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

keyMySQLの予約キーワードです。フィールド名として使用する場合は、バッククォートで引用する必要があります。

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