I’m fairly new to mysql and I was wondering if the following code should be working. I’ve been checking with my database after submission of this form and nothing is getting inputted into the database. Please let me know what I’m doing wrong, Thank you!
<?php
$username = $_SESSION['username'];
$email = $_POST['email'];
$desc = $_POST['desc'];
$url = $_POST['url'];
$priority = $_POST['priority'];
if( strlen($username) > 0 && strlen($email) > 0 && strlen($desc) > 0)
{
$sql = "INSERT INTO feature_request_table (username, desc, email, url, priority, status)
VALUES( '$username' , '$desc' , '$email' , '$url' , '$priority' , '0' )";
echo "The sql statement is: " . $sql . "</br>";
mysql_query($sql);
//echo "The result is: " . $results . "</br>";
echo "Your request have been sent. Please allow a brief period of time for your webmaster implement your request. Thank you!";
}
mysql_close($con);
?>
Use the return value of
mysql_query()and check if it isNULLto find out if the query was successful:Also, we don’t see in the posted code that
mysql_connect()was called. Also check that the connection was successfully made: