Php 在mysql中得到错误的结果?
您好,我有一个html表单在php端一切都很好,我刚刚被演示了如何从这个网站隐藏字段 我在每个结果上都有一个提交按钮,让用户选择他们想要的。当他们按下提交按钮时,我希望信息被提交并添加到数据库中。但由于某些原因,当用户单击项目1上的提交时,它会将最后一个项目添加到数据库中,例如项目6??所以有6个结果,每个结果有一个提交按钮,所以有6个按钮。当用户在第1项上按submit时,它会在第6项上提交一些请求Php 在mysql中得到错误的结果?,php,mysql,sql,Php,Mysql,Sql,您好,我有一个html表单在php端一切都很好,我刚刚被演示了如何从这个网站隐藏字段 我在每个结果上都有一个提交按钮,让用户选择他们想要的。当他们按下提交按钮时,我希望信息被提交并添加到数据库中。但由于某些原因,当用户单击项目1上的提交时,它会将最后一个项目添加到数据库中,例如项目6??所以有6个结果,每个结果有一个提交按钮,所以有6个按钮。当用户在第1项上按submit时,它会在第6项上提交一些请求 <form method="post" action="buydo.php">
<form method="post" action="buydo.php">
<label><br />
<br />
</label>
<p>
<?php
$sql = "SELECT * FROM sell
ORDER BY Pokemon_level ASC";
$res = mysql_query($sql) or die(mysql_error());
while ($v = mysql_fetch_array($res)) {
echo '
<div class="auction_box">
<img src="http://myrpg.net/new_rpg/'.$v['Pokemon_pic'].'" width="100" height="100"><br/>
£'.$v['price'].'<br/>
<label id="pokemonName'.$v['id'].'">'.$v['pokemon_name'].'</label><br/>
<label>Level '.$v['Pokemon_level'].'</level><br/>
<label>Exp '.$v['exp'].'</level><br/>
<label>Time Left:';
echo '</label>
<br/>
<input type="hidden" name="Name" value="'.$v['pokemon_name'].'">
<input type="hidden" name="level" value="'.$v['Pokemon_level'].'">
<input type="hidden" name="vid" value="'.$v['id'].'">
<input type="hidden" name="price" value="'.$v['price'].'">
<input type="hidden" name="exp" value="'.$v['exp'].'">
<input type="submit" id="'.$v['id'].'" class="buy_submit" value="Buy Now" /> </div>';
}
?>
</p>
<p> </p>
</form>
就像我说的,插入只插入第6项,无论你按第1-5项,它都会插入第6项的级别、exp、名称,因为你以一种形式显示它,所以最新的值会覆盖以前的值。通过移动while循环中的
和
标记,尝试使每个项目成为自己的表单,或者尝试使用jquery单击按钮id进行跟踪,并用单击的id填充隐藏字段,这是因为html错误。这些值会被覆盖
基本上,您必须选择:
- 为每个项目呈现一个表单
- 使用下拉菜单或单选按钮进行操作
您的标签
你所有的钱都是属于我们的…谢谢你做了这项工作将标志着这是正确的,当它让我:)再次感谢汉克斯:)很高兴有像你这样的人在这里帮助。
include 'config.php';
session_start() ;
$name = mysql_real_escape_string($_POST['Name']);
$Pokemon_level = mysql_real_escape_string($_POST['level']);
$idofpokemonsell = mysql_real_escape_string($_POST['vid']);
$price = mysql_real_escape_string($_POST['price']);
$exp = mysql_real_escape_string($_POST['exp']);
$sql = "SELECT * FROM `users` WHERE `username` = '" . $_SESSION['username'] . "'";
$result = mysql_query($sql) or die(mysql_error());
$values = mysql_fetch_array($result);
echo $values['money'] ;
if ( $values['money'] == $price ) {
echo "Give them the pokemon yay";
}
if ( $values['money'] > $price ) {
mysql_query("INSERT INTO `user_pokemon` (`pokemon`, `belongsto`, `exp`, `slot`, `level`) VALUES ('$name','" . $_SESSION['username'] . "','$exp','0','$Pokemon_level')") or die(mysql_error());
echo "Your money is over";
}