查看完整版本: 關於php碼的問題[已解決]
頁: [1]

dicayoyoyo 發表於 2015-10-17 06:37 PM

關於php碼的問題[已解決]

本帖最後由 dicayoyoyo 於 2015-10-28 08:08 PM 編輯

各位前輩好
小弟剛入門不久想做一個PHP網頁編輯MYSQL資料庫

打入id案提交,就可以把那一個資料刪掉

可試了幾次都無法把資料刪除
求大大們幫忙吧{:54:}
--------------------------------------------------
程式碼1
<html>
<head>
<title>motherfucker</title>
</head>
<body>
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'raspberry';
$dbname = 'pi';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) ;//連接資料庫
mysql_query("SET NAMES 'utf8'");//設定語系
mysql_select_db($dbname);
$sql = "select * from readings";//查詢整個表單
$result = mysql_query($sql) ;
echo "<table border='1'>
<tr>
<th>id</th>
<th>tagId</th>
<th>time</th>
<th>action</th>
</tr>";

while($row = mysql_fetch_array($result)){//印出資料
        echo "<tr>";
        echo "<td>" .  $row['id']."</td>";
        echo "<td>" .  $row['tagId']."</td>";
        echo "<td>" .  $row['time']."</td>";
        echo "<td>" .  $row['action']."</td>";
        echo "</tr>";
}
?>
<form action="fw.php" method="Post">
id:<input type="Text" name="id">
<input type="Submit">
</form>
</body>
</html>
----------------------------------------------------
程式碼2
<html><head>
<title></title>
</head><body>
<?
$id=$_REQUEST["id"];
?>

</body></html>

<?php
    $dbhost = 'localhost';
    $dbuser = 'root';
    $dbpass = 'raspberry';
    $dbname = 'pi';



    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');

    mysql_query("SET NAMES 'utf8'");
    mysql_select_db($dbname);

    $sql_delete = "DELETE FROM readings WHERE id = '$id'";

    $result = mysql_query($sql_delete) or die('MySQL insert error');

    $sql_query = "select * from readings";
    $result = mysql_query($sql_query) or die('MySQL query error');
    while($row = mysql_fetch_array($result))
    {
    echo $row['id']."<br>";

     }
?>
...<div class='locked'><em>瀏覽完整內容,請先 <a href='member.php?mod=register'>註冊</a> 或 <a href='javascript:;' onclick="lsSubmit()">登入會員</a></em></div><div></div>

arthurxyz 發表於 2015-10-18 02:07 PM

有出現什麼錯誤訊息嗎?

dicayoyoyo 發表於 2015-10-18 10:22 PM

arthurxyz 發表於 2015-10-18 02:07 PM static/image/common/back.gif
有出現什麼錯誤訊息嗎?

案提交就出現MySQL insert error   

theloserbm 發表於 2015-10-19 11:16 AM

你先在你的error message後面加上mysql_error(), 要不然不知道是甚麼錯誤

jehovahcloud 發表於 2015-10-19 09:14 PM

另外,建議用 php-pdo 來處理這東西喔!
雖然說沒辦法完全擋掉 XSS,起碼他會做最基本的 type protection!

http://php.net/manual/en/book.pdo.php<br><br><br><br><br><div></div>

dicayoyoyo 發表於 2015-10-20 04:49 PM

jehovahcloud 發表於 2015-10-19 09:14 PM static/image/common/back.gif
另外,建議用 php-pdo 來處理這東西喔!
雖然說沒辦法完全擋掉 XSS,起碼他會做最基本的 type protection! ...

好 謝謝大大><{:31:}{:31:}

bpflsll234 發表於 2015-10-22 12:21 AM

刪除檔 基本上只需要做刪除的動作 (不需用HTML和echo)
刪除完 redirect 到原本的頁面就可以了
頁: [1]