Hi all,
I'm pretty new to PHP+MySQL and I am having trouble connecting to my host's MySQL database and inserting a record. Here's the code:
START CODE
$name = $REQUEST['name'];
$nation = $REQUEST['nation'];
$quote = $_REQUEST['quote'];
$Error = "";
If ($name == ""){
$Error = "You left your name out, please go back and fill it in properly.";
}
If ($nation == ""){
$Error = "You left your nation out, please go back and fill it in properly.";
}
If ($quote == ""){
$Error = "You left your quote out, please go back and fill it in properly.";
}
$username = "thedavies";
$password = "REMOVED-FROM-CODE";
$hostname = "orf-mysql1.brinkster.com";
$dbh = mysql_connect($hostname, $username, $password)
or die("Could not connect to the database");
$selected = mysql_select_db("thedavies",$dbh)
or die("Could not select thedavies");
MYSQL_QUERY("INSERT INTO quote(ID_NO, Quote, Nation, Name) VALUES('','$quote','$nation','$name')");
If ($Error == "")
{
?>
Your Quote was recieved. Thanks!
<?
}
Else
{
Echo($Error);
}
mysql_close($dbh);
?>
END CODE
Obviously I removed my password so thats not a problem. The funny thing is, the exact code above works in a different page (except a different INSERT statement) and I'm not recieving the errors generated by:
$dbh = mysql_connect($hostname, $username, $password)
or die("Could not connect to the database");
$selected = mysql_select_db("thedavies",$dbh)
or die("Could not select thedavies");
So I think it's my INSERT statement. Not for sure though,
thanks in advance!
EDIT I just remembered, when I run that script, it says "Your quote was recieved. Thanks!" but when I go into my Database manager in my host's control panel then do a SELECT * FROM quote on my database I see the record was not added.