Hey everyone-
I am trying to insert a name, email and comment into a database in MQL. The tablename is guestbook.
I have a connection to the database but cannot get the entries to be successfully added. I think it is a problem with my IF conditional for when the form is submitted. I have tried both the $REQUEST and $POST actions but with no luck.
and ideas? I am using XAMPP.
Thanks a lot for taking a quick look. The names are all correct.
<?php
//create variable as a string that we will append entires too
$gb_str = "";
$pgeTitle="View and Sign Guestbook";
//if form is submitted than insert into the database
if (!empty ($_REQUEST["submit"])) {
$name = $_REQUEST["frmName"];
$email =$_REQUEST["frmEmail"];
$comment =$_REQUEST["frmComment"];
$date = Date ("Y-m-d h:i:s");
$gb_query = "INSERT INTO guestbook VALUES (0, '$name', '$email',
'$comment', '$date')";
mysql_query($gb_query);
$res = mysql_affected_rows();
//test to see if the insert was successful
if ($res >0) {
$ret_str="Your guestbook entry was successfully added.";
}else {
$ret_str="Your guestbook entry was NOT successfully added.";
}
//append succss/failure message
$gb_str .= "<span class=\"ret\">$ret_str</span><BR>";
}
?>
<?php
//the querystring
$get_query = "SELECT gbName, gbEmail, gbComment, DATE_FORMAT(gbDateAdded,
'%m-%d-%y %H:%i')gbDateAdded FROM guestbook";
$get_rs = mysql_query($get_query);
//While there are still results
while ($get_row = mysql_fetch_array($get_rs)) {
$name = $get_row["gbName"];
$email= $get_row["gbEmail"];
$comment=$get_row["gbComment"];
$date= $get_row["gbDateAdded"];
if (!empty($name)) {
//if the name exists and email exists, link name to the email
if (!empty($email)) {
$name="by to:$email\">$name";
}
//if the name does not eist and the email exists than link email to email
} else if (!empty($email)) {
$name= "by to:$email\">$email";
//or else make the name blank
}else {
$name ="";
}
//append to string and will print later on
$gb_str .= "<br>$comment<p class=\"small\"><posted on $date $name>";
}
//Free the result Memory
mysql_free_result($get_rs);
?>