Solved

Insert Query with odbc_execute not working

Posted on 2002-04-26
7
271 Views
Last Modified: 2012-05-04
Hello I m trying followin  script to insert values into MS Access database using odbc functions in PHP.i m using ISS on WIN2000 plateform.I have already set System DSN and there is no problem with connection because no error message is sent to clien about odbc connection<html>

<head>
       <title>Contact Us</title>
</head>
<body>
    <center>
      <?php
            if(isset($name)&&$name && isset($email)&&$email && isset($comment)&&$comment)
            {
                  $db = odbc_connect("data","","");
                  $res = odbc_prepare($db, "Insert into contact values('$name', '$email', '$comment')");
                  if(odbc_execute($res))
                  {
                        echo "We have recieved your comments, we will contact you soon at your email address";
                  }
                  else
                  {
                        echo "Could not insert the values in database";
                  }
            }
            else
            {
                  echo "Please fill all the fields";
            }
      ?>

</body>
</html>

The out put to browser is "Could not insert the values"(as in case of failiure of to odbc_execute it should do)
please tell me what should i do . a piece of code will be great help
          thanks
0
Comment
Question by:ksj786
  • 4
7 Comments
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Do any of your fields contain a single quote -> ' <- ?

If so, try ...

$res = odbc_prepare($db, "Insert into contact values('" . addslashes($name) . "', '" . addslashes($email) . "', '" . addslashes($comment) . "')");

Regards,

Richard Quadling.
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
Do you get any other errors?

An ODBC error/warning maybe?

Try temporarily adding error_reporting(E_ALL) to the top of your script.

DON'T FORGET TO TAKE IT OUT WHEN YOU HAVE FINISHED!!!!!
0
 
LVL 40

Expert Comment

by:RQuadling
Comment Utility
<?php

error_reporting(E_ALL);

if ...

...

?>


Example of error_reporting.
0
 

Author Comment

by:ksj786
Comment Utility
The parameters that i am passing donot contain any single Quote charaters . The odbc error doesnot occure . The connection is successful but Query does not execute.
0
 
LVL 40

Accepted Solution

by:
RQuadling earned 100 total points
Comment Utility
I've not used prepare/execute as I have yet to need parameter based queries.

Can you try using odbc_exec($db, "Insert into contact values('$name', '$email', '$comment')");

Richard.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now