1
 <?php

include ("apps/controller/database.php"); include ("header.php");
//Connect to the DB $database->connect(); //Check the url has been set
if ($_SERVER['REQUEST_METHOD'] == 'POST') {


$url = isset($_POST['url']) ? $database->escape($_POST['url']) : false;
//$url = isset($_POST['url']) ? $database->escape($_POST['url']) : '';
//This is optional ;)
$password = isset($_POST['password']) ? $database->escape($_POST['password']) : '';
//Okay, now we've figured out if they've set the url, let's add it to the DB
if (isset($url)) {
    $id = md5(uniqid());
    $res = $database->query("INSERT INTO urls (url,pass,key) VALUES('".$url."','".$password."','".$id."')");
    echo '<br /><br /><div id="both" class="types both"><a href="http://localhost/view.php?id=' .
        $id . '">http://localhost/view.php?id=' . $id . '</a></div>';
}
//Close the DB
$database->close();
}else
{
    echo '<br /><br /><div id="err" class="notification error"><a class="close" href="#" alt="close" title="Close this notification"> </a> You cannot view this URL directly. Please create a url.</div>';
}


$database->close(); 

我的MYSQL结构是:id、url、views、keys

4

1 回答 1

4

key是一个MySQL 保留关键字,如果你想使用它作为字段名,你需要用反引号将它引用。

INSERT INTO urls (url,pass,`key`)...
于 2012-08-30T12:46:57.813 回答