10 days Learn PHP Day 6

web front end five thousand four hundred and twenty-five 13 years ago (2011-04-08)

Learning purpose: learn to add, delete and modify data

    mysql_query($exec);

This statement alone can perform all operations. The difference is the SQL statement $exec

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 will talk about the form and php variable transmission. If a<input name="item1" type="text" id="item1">

If the form is submitted in POST, the variable value can be obtained by using $_POST ['item1 '] to process the form file. Similarly, if the form is submitted in GET, it is $_GET ['item1']

Is it simple? But $exec usually has problems, because your SQL statement may be very long, and you may miss the. connector, or 'to surround character fields.

We can comment mysql_query ($exec); The statement uses echo $exec; Instead, output $exec to check the correctness. If you are not aware of any error in $exec, you can copy the sql statement to phpmyadmin to see its error information. It should also be noted that we should not use some sensitive strings as field names, otherwise problems may occur, such as date. The naming of variables and fields follows a little rule. Sometimes it is good for you, and beginners can't ignore its importance.

That's all for today. You can do further research on a reference manual for SQL statements in DOWN. Continue to talk about SESSION tomorrow.