我想從html表單插入som數據到我的mySql數據庫服務器。簡單的html php插入mysql問題
這裏是我的html代碼:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add events</title>
</head>
<body>
<form action="addevents.php" method="post">
id: <input type="text" name="eventID" />
<br></br>
larmkod: <input type="text" name="larmkod" />
<br></br>
idArduinoT: <input type="text" name="idArduinoT" />
<br></br>
handelse: <input type="text" name="handelse" />
<br></br>
tid: <input type="text" name="tid" />
<br></br>
rumNr: <input type="text" name="rumNr" />
<br></br>
inneboendeNamn: <input type="text" name="inneboendeNamn" />
<br></br>
overvakare: <input type="text" name="overvakare" />
<input type="submit" />
</form>
</body>
</html>
這裏是我的PHP代碼:
<?php
$con = mysql_connect("localhost","humhum","humhum");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("arduino_db",$con;
$sql="INSERT INTO events (eventID, larmkod, idArduinoT, handelse, tid, rumNr, inneboendeNamn, overvakare)
VALUES
('$_POST[eventID]', '$_POST[larmkod]', '$_POST[idArduinoT]', '$_POST[handelse]', '$_POST[tid]', '$_POST[rumNr]',
'$_POST[inneboendeNamn]', '$_POST[overvakare]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
我不看這個問題是嗎? .. eventID是主鍵。
不,我沒有看到這個問題。你沒有告訴我們。 – MJB 2011-05-11 20:14:31
問題 - 你的sql注入攻擊是開放的,你必須在把數據放入db之前對數據進行清理 – 2011-05-11 20:16:07
是的,我知道,但是我只是用它作爲out學校項目的臨時... – SHUMAcupcake 2011-05-11 20:17:26