Home >Backend Development >PHP Tutorial >The sixth day of learning PHP in ten days_PHP tutorial
Learning purpose: Learn to add, delete and modify data
mysql_query($exec);
This statement alone can perform all operations, the difference is the $exec sql statement
Add: $exec="insert into tablename (item1,item2) values ('".$_POST['item1']."',".$_POST['item1'].")";
Delete: $exec="delete from tablename where...";
Modify: $exec="update tablename set item1='".$_POST['item1']."' where ... ";
At this point we have to talk about form and php variable transfer. If an
form in the form If it is submitted by POST, then you can use $_POST['item1'] to get the variable value when processing the form file. Similarly, if it is submitted by GET, it is $_GET['item1']
Isn't it very simple? But usually $exec will have problems, because your SQL statement may be very long, and you will miss the .connection character, or ' to surround the character field.
We can comment out the mysql_query($exec); statement and use echo $exec; instead to output $exec to check the correctness. If you still can't detect any errors in $exec, you can copy this sql statement and execute it in phpmyadmin to see its error message. It should also be noted that we should not use some sensitive strings as field names, otherwise problems may occur, such as date. Sometimes it is good for you to follow some rules when naming variables and fields. Beginners should not ignore its importance.
That’s it for today. You can DOWN a reference manual for SQL statements and study it further. Let’s continue talking about SESSION tomorrow.