2013-11-23 284 views
-1

這是我添加的管理面板和刪除成員表的用戶在我的數據庫,但是當我按OK它不工作:管理面板不工作

我不知道問題出在哪裏。 我不擅長PHP,所以請提供易於理解的答案。

<?php 

if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    $user="admin"; 
    $pass="whatever"; 
    $host="localhost"; 
    $db_name="login"; 

    $con=mysqli_connect($host, $user, $pass, $db_name); 

    if (mysqli_connect_errno($con)) { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

    $id  = ($_POST['id']); 
    $password = md5($_POST['pass']); 
    $fieldset = ($_POST['fieldset']); 
    $id  = mysqli_real_escape_string($con,$password); 
    $password = mysqli_real_escape_string($con,$password); 
    $fieldset = mysqli_real_escape_string($con,$fieldset); 

    if ($fieldset == "add") { 
     $sqlcommand="INSERT INTO members (student_id,student_pass) VALUES ('$id','$password')"; 
    } elseif (fieldset == "delete") { 
     $sqlcommand="DELETE FROM members WHERE student_id LIKE '$id'";   
    } else { 
     echo "Your information is incorrect"; 
    } 
} 
?> 
+0

'當我按下確定它does not操作'當你按下ok時會發生什麼?它是否被提交?任何錯誤? –

回答

0

我猜想,錯誤會在這裏

$id = mysqli_real_escape_string($con,$password); // <<<<<< 
$password = mysqli_real_escape_string($con,$password); 
$fieldset = mysqli_real_escape_string($con,$fieldset); 

我想這應該是

$id = mysqli_real_escape_string($con,$id); 

,你也沒有遇到任何問題,因爲另一個人說: ,你只需設置SQL。基本上你的腳本應該看起來像

if ($_SERVER["REQUEST_METHOD"] == "POST") { 
    $user="admin"; 
    $pass="whatever"; 
    $host="localhost"; 
    $db_name="login"; 

    $con=mysqli_connect($host, $user, $pass, $db_name); 

    if (mysqli_connect_errno($con)) { 
     echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
    } 

    $id  = ($_POST['id']); 
    $password = md5($_POST['pass']); 
    $fieldset = ($_POST['fieldset']); 
    $id  = mysqli_real_escape_string($con,$id); 
    $password = mysqli_real_escape_string($con,$password); 
    $fieldset = mysqli_real_escape_string($con,$fieldset); 

    if ($fieldset == "add") { 
     $sqlcommand="INSERT INTO members (student_id,student_pass) VALUES ('$id','$password')"; 
    } elseif (fieldset == "delete") { 
     $sqlcommand="DELETE FROM members WHERE student_id LIKE '$id'";   
    } else { 
     $sqlcomand=''; 
     echo "Your information is incorrect"; 
    } 

    mysqli_query($con,$sqlcommand); 
} 
+0

@Shane熱辣女孩的電子郵件是'man.in.black'的尷尬時刻:D –

+0

@Shane這種說法就是讓女性(而不是女孩)在科技世界常常感到不舒服的一種說法。瘸。 – ceejayoz

+0

是的,但它的真相dude – Shane

0

你實際上並沒有在任何地方執行SQL查詢。您需要在某處運行mysqli_query($con,$sqlcommand);

0

您沒有執行查詢;使用mysql_query($sql); 希望它會幫助你:)

+0

謝謝是的,你是對的 – Shane