ksj786
asked on
Insert Query with odbc_execute not working
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
<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
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!!!!!
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!!!!!
<?php
error_reporting(E_ALL);
if ...
...
?>
Example of error_reporting.
error_reporting(E_ALL);
if ...
...
?>
Example of error_reporting.
ASKER
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
If so, try ...
$res = odbc_prepare($db, "Insert into contact values('" . addslashes($name) . "', '" . addslashes($email) . "', '" . addslashes($comment) . "')");
Regards,
Richard Quadling.