tedpottel@gmail.com wrote:
Quote:
Hi,
I have the following code
<?php
//DatabaseConnect();
if (!($dblink = mysql_connect("drt-
sport.com","drtspo_tedted","oreo8157")))
die(" could not connect to mysal");
>
if (!$dbconn = mysql_select_db("drtspo_zc1",$dblink))
die(" Could not connect to databse ");
>
$sql="INSERT INTO `orders` (`fname`) VALUES ('ted')";
if (!$results=mysql_query($sql,$dblink))
die("<brcould not query database");
>
print("new item inserted");
?>
>
The output is always
could not query database.
I'm assuming something is wrong with the sql string?
Is there a way to get PHP to output debug informtion????
>
-Ted
My approach is this (usually for more complex queries than that):
1 - Have a side window open and running phpMyAdmin on that database
2 - Put a print statement to print out $sql
3 - Try running that $sql in the sql tab of phpMyAdmin.
That tells me right away what any error is and playing around with the
query in phpMyAdmin to get it to work is usually much faster than first
modifying the php code.
BTW, make sure the "die"s are removed when you go live. Instead, use
ifs and set messages but keep the app moving.
My guess is that either you don't have field in table orders call fname
or you do not have privilege to write to the database. Just for kicks,
try this:
if (!($results=mysql_query($sql,$dblink)))
Finally, you don't really need those back-ticks.