Solved

Insert Query with odbc_execute not working

Posted on 2002-04-26
7
273 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

786 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