Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Insert Query with odbc_execute not working

Posted on 2002-04-26
7
Medium Priority
?
282 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 count occurrences of each item in an array.

705 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