I'm currently building a web form which has several drop down menus and I want to submit these into a SQL database through PHP.
I have little PHP knowledge but no better way to learn than doing it! I'm following this guide to post data back to my db - Link
My code is:
$CLI = $_POST['CLI'];
$Environment = $_POST['Environment'];
$Type = $_POST['Type'];
$Fault = $_POST['Fault'];
$query="INSERT INTO testtable (cli, env, type, fault)VALUES ('$CLI', '$Environment', '$Type', '$Fault')"
mysql_query($query) or die (mysql_error());
echo "Database Updated With: ".$CLI";
When I'm editting this code I'm getting a syntax error on the mysql_query line and the echo line. I've uploaded this to my server however it goes to the php update page then doesnt post the data back to the db.
Can someone help please? I can't find any simple answers to fix it!
Thanks
echo $query;before executing it.mysql_queryin new applications. This interface is being phased out because of serious problems with SQL injection bugs as you've demonstrated in your simple example. If any of these values contain'then your query will not work. You should be usingmysqlior PDO and placeholders to do this correctly under all circumstances.