<?php
Implement the operation of increasing, deleting and changing the commodity information
I. Importing configuration files and function library files
Require ("dbconfig.php");
Require ("functions.php");
Second, connect MySQL, select database
$link = mysql_connect (Host,user,pass) or Die ("Database failed! ");
mysql_select_db (DBNAME, $link);
Third, get the value of the action parameter, and do the corresponding operation
Switch ($_get["action"]) {
Case "Add"://Add
1. Get add information
$name = $_post["name"];
$typeid = $_post["typeID"];
$price = $_post["Price"];
$total = $_post["Total"];
$note = $_post["Note"];
$addtime = time ();
2. Verify () Omit
if (empty ($name)) {
Die ("Commodity name must have value");
}
3. Perform a picture upload
$upinfo = UploadFile ("Pic", "./uploads/");
if ($upinfo ["Error"]===false) {
Die ("Picture information upload failed:". $upinfo ["info"]);
}else{
Upload successful
$pic = $upinfo [info];//Gets the picture name of the upload success
}
4. Perform picture scaling
Imageupdatesize ('./uploads/'. $pic, 50,50);
5. Assemble the SQL statement and execute the Add
$sql = "INSERT into goods values (null, ' {$name} ', ' {$typeid} ', {$price},{$total}, ' {$pic} ', ' {$note} ', {$addtime})";
Echo $sql;
mysql_query ($sql, $link);
6. Judging and outputting results
if (mysql_insert_id ($link) >0) {
echo "Product launch success! ";
}else{
echo "Product launch failed! ". Mysql_error ();
}
echo "<br/> <a href= ' index.php ' > View product Information <a>";
Break
Case "Del"://delete
Get the ID number to delete and assemble the delete SQL to execute
$sql = "Delete from goods where id={$_get[' id '}";
mysql_query ($sql, $link);
Perform picture deletion
if (Mysql_affected_rows ($link) >0) {
@unlink ("./uploads/". $_get[' Picname '));
@unlink ("./uploads/s_". $_get[' Picname '));
}
Jump to the browsing interface
Header ("Location:index.php");
Break
Case "Update"://Modify
1. Get the information you want to modify
$name = $_post["name"];
$typeid = $_post["typeID"];
$price = $_post["Price"];
$total = $_post["Total"];
$note = $_post["Note"];
$id = $_post[' id '];
$pic = $_post[' oldpic ');
2. Data validation
if (empty ($name)) {
Die ("Commodity name must have value");
}
3. Determine if there is any image upload
if ($_files[' pic ' [' ERROR ']!=4) {
Performing uploads
$upinfo = UploadFile ("Pic", "./uploads/");
if ($upinfo ["Error"]===false) {
Die ("Picture information upload failed:". $upinfo ["info"]);
}else{
Upload successful
$pic = $upinfo [info];//Gets the picture name of the upload success
4. Have picture upload, perform zoom
Imageupdatesize ('./uploads/'. $pic, 50,50);
}
}
5. Perform modifications
$sql = "Update goods set name= ' {$name} ', typeid={$typeid},price={$price},total={$total},note= ' {$note} ', pic= ' {$pic} ' where id={$id} ";
Echo $sql;
mysql_query ($sql, $link);
6. Determine if the modification was successful
if (Mysql_affected_rows ($link) >0) {
If there is a picture upload, delete the old picture
if ($_files[' pic ' [' ERROR ']!=4) {
@unlink ("./uploads/". $_post[' Oldpic '));
@unlink ("./uploads/s_". $_post[' Oldpic '));
}
echo "modified successfully";
}else{
echo "modification failed". Mysql_error ();
}
echo "<br/> <a href= ' index.php ' > View product Information <a>";
Break
}
Iv. Closing the database
Mysql_close ($link);
Steps for Database Setup