这章学习如何插入图像。
MySQL插入新列的语句:
ALTER TABLE 表名 {ADD COLUMN(增加一个新列)
DROP COLUMN(删除一列)
CHANGE COLUMN(修改一列的列名和数据类型)
MODIFY COLUMN(修改一列的数据类型或位置)
}
MySQL中的NOW()函数用于插入当前日期/时间。
$_FILES['变量名']{ ['name'] (上传文件的文件名)
['type'] (上传文件的类型)
['size'] (上传文件的大小)
['tmp_name'] (文件在服务器上的临时储存位置)
['error'] (文件上传的错误码:0表示成功)
}
move_uploaded_file()函数接受一个文件的源位置和目标位置,然后负责移动。
MySQL中ORDER BY 可以给数据库排序, ASC代表升序, DESC代表降序。
PHP函数前加@可以抑制函数错误报告。
标记279页详述POST 和GET。
MySQL中LIMIT可以限制删除的行数。
第287页练习:
require_once ('appvars.php');
require_once ('connectvars.php');
if (isset($_GET['id']) && isset($_GET['date']) && isset($_GET['name']) $$ isset($_GET['score']) && isset($_GET['screenshot'])){
$id = $_GET['id'];
$date = $_GET['date'];
$name = $_GET['name'];
$score = $_GET['score'];
$screenshot = $GET['screenshot'];
}else if (isset($_POST['id']) && isset($_POST['name']) && isset($_POST['score'])){
$id = $_POST['id'];
$name = $_POST['name'];
$score = $_POST['score'];
}else{
echo '<p class = "error">Sorry, no high score was specified for removal. </p>';
}
if (isset($_POST['submit']))
if ($_POST['confirm'] == 'YES'){
@unlink (GW_UPLOADPATH . $screenshot);
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
$query = "DELETE FROM guitarwars WHERE id = $id LIMIT 1";
mysqli_query($dbc, $query);
mysqli_close($dbc);
echo '<p>The high score of ' . $score . 'for' . $name . ' was successfully removed.';
}else{
echo '<p class = "error">The high score was not removed.</p>';
}
}else if (isset($id) && isset($name) && isset($date) && isset($score) $$ isset($screenshot)){
echo '<p> Are you sure you want to delete the following high score?</p>';
echo '<p><strong>Name: </strong>' . $name . '<br /><strong>Date: </strong>' . $date . '<br /><strong>Score: </strong>' . $score . '</p>';
echo '<form method = "post" action = "removescore.php">';
echo '<input type = "radio" name = "confirm" value = "Yes" /> Yes ';
echo '<input type = "radio" name = "confirm" value = "NO" checked = "checked" />No <br />';
echo '<input type = "submit" value = "Submit" name = "submit" />';
echo '<input type = "hidden" name = "id" value = "' . $id . '" />';
echo '<input type = "hidden" name = "name" value = "' . $name . '" />';
echo '<input type = "hidden" name = "score" value = "' . $score . '" />';
}
echo '<p><a href = admin.php>< < Back to admin page</a></p>';