Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Insert Query with odbc_execute not working

Posted on 2002-04-26
7
Medium Priority
?
284 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
5 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 400 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

824 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