<?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,網址,觀點,鍵您的SQL語法有錯誤;檢查對應於你的MySQL服務器版本正確的語法
我強烈建議分開演示文稿和數據庫連接之間的功能。 – taz
迴應您的查詢 –
您最好使用自動增量主鍵。它避免了每次插入行時必須創建ID的開銷。 –