我一直在試圖更新我的數據庫,但它更新,它顯示了這樣的MySQL的PHP查詢不更新
通知的ID錯誤是成功的:用C player_id:未定義的變量\ WAMP \ WWW \ Potifolio \ update_ac.php第4行
成功:波紋管是我的代碼請幫助:
me.php
<?php
include_once("connect.php");
$query = "SELECT * FROM players";
$result = mysql_query($query,$db);
?>
<table><tr>
<td>Name</td>
<td>Surname</td>
<td>Positon</td>
<td>Email</td>
<td>Passowrd</td>
<td>Email</td>
<td>Action</td>
</tr>
<?php
while($row = mysql_fetch_assoc($result)){
?>
<tr>
<td><?php echo $row['name'];?></td>
<td><?php echo $row['surname'];?></td>
<td><?php echo $row['position'];?></td>
<td><?php echo $row['password'];?></td>
<td><?php echo $row['username'];?></td>
<td><?php echo $row['name'];?></td>
<td ><a href= "update1.php?player_id=<?php echo $row['player_id'];?>">Update</a></td>
</tr>
<?php
}
?>
update1.php
<?php
include_once("connect.php");
$player_id = $_GET['player_id'];
$query = "SELECT * FROM players where player_id ='$player_id'";
$result = mysql_query($query,$db);
$row = mysql_fetch_assoc($result);
?>
<form name = "form1"action="update_ac.php" method ="post">
<input type = "text" name="name" value="<?php echo $row['name'];?>">
<input type = "hidden" name = "player_id" ID = "player_id" value="<?php echo $row['player_id'];?>" >
<input type = "submit" name="submit" value="submit">
</form>
update_ac.php
<?php
include_once('connect.php');
$name= $_POST['name'];
$sql="UPDATE players SET name='$name' WHERE player_id = '$player_id'";
$result = mysql_query($sql);
if($result){
echo "Success";
}else {
echo "Error";
}
?>
您正在使用[**的**過時的數據庫API(http://stackoverflow.com/q/12859942/19068),並應使用[現代替代品](http://php.net/manual/en/mysqlinfo.api.choosing.php)。你也**易受[SQL注入攻擊](http://bobby-tables.com/)**,現代的API會使[防禦]更容易(http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php)自己從。 – Quentin 2013-04-28 08:41:53
您需要幫助才能瞭解錯誤消息嗎?在文件'update_ac.php'的#4行,你正在使用一個名爲'$ player_id'的變量,它從無處跳出。這就是你應該首先解決的問題。 – 2013-04-28 08:46:59
重複的http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index – 2013-04-28 08:48:40