Solved

Insert Query with odbc_execute not working

Posted on 2002-04-26
7
277 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:Richard Quadling
ID: 6986519
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:Richard Quadling
ID: 6986527
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:Richard Quadling
ID: 6986531
<?php

error_reporting(E_ALL);

if ...

...

?>


Example of error_reporting.
0
 

Author Comment

by:ksj786
ID: 6987885
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:
Richard Quadling earned 100 total points
ID: 6988153
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Foreword (July, 2015) Since I first wrote this article, years ago, a great many more people have begun using the internet.  They are coming online from every part of the globe, learning, reading, shopping and spending money at an ever-increasing ra…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

861 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