I have this PHP code , it gets data from an HTML file , when i click on submit it goes through with no problem but nothing is adding to the database! I never had this problem before. please help
<?php
$SNHUID=$_POST['SNHUID'];
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$department=$_POST['department'];
@mysql_connect("localhost","root","");
mysql_select_db("db");
$select ="insert into t_users (SNHUID,FirstName,LastName,Department) values ('.$SNHUID.','".$fname."','".$lname."','".$department."')";
$sql=mysql_query($select);
print'<script type="text/javascript">';
print'alert("The data is inserted")';
print'</script>';
mysql_close();
?>
Please replace this line.
I have added double quote before and after $SNHUID
$select ="insert into t_users (SNHUID,FirstName,LastName,Department)
values ('".$SNHUID."','".$fname."','".$lname."','".$department."')";
First of all, you have your double/single-quotes wrong around $SNHUID
variable in query. It probably leads to an error as MySQL does not understand literal $SNHUID
string inside a query. You can always check the error from your query using mysql_error()
after query.
As a side note, you should not directly pass arguments from user to a query as this may result in SQL-injection vulnerability. Use prepared statement instead.