大家好,
我有一个 mysql 数据库和一个 php 页面。当我或某人调用我的 php 页面时,它正在顺利更新我的表格。
但是当它被多个用户同时调用时,它并没有正确更新表。它只更新一个用户的进程。我正在使用标准的 mysql 连接。我试过 ADO DB 连接,但问题没有解决。问题是什么 ?
这是我的 php 页面;
<?php
$host ="******.com";
$uname = "*****";
$pwd = "*******";
$db = "*****_db";
$con = mysql_connect($host,$uname,$pwd) or die("connection failed");
mysql_select_db($db,$con) or die("db selection failed");
$id = $_REQUEST['id'];
$int_id = intval($id);
$value = 0;
if (isset($_REQUEST['vote1']))
{
$vote1 = $_REQUEST['vote1'];
$value = 1;
$vote = intval($vote1);
}
if (isset($_REQUEST['vote2']))
{
$vote2 = $_REQUEST['vote2'];
$vote = intval($vote2);
$value = 2;
}
//Get Detail
mysql_query("SET NAMES 'utf8'");
mysql_query ("SET CHARACTER SET utf8");
mysql_query ("SET COLLATION_CONNECTION = 'utf8_general_ci'");
// get all products from products table
$res_detail = mysql_query("SELECT *FROM v_list WHERE id='$int_id'") or die(mysql_error());
if (mysql_num_rows($res_detail) > 0) {
while ($row = mysql_fetch_assoc($res_detail)) {
if($value ==1 )
{
$fark = $vote1 - $row["vs1_vote"];
if($fark == 1)
{
$sum_vote = $vote1 + $row["vs2_vote"] ;
$v1_percent = round( ($vote1 *100 / $sum_vote), 2);
$v2_percent = 100 - $v1_percent;
}
else
{
echo "An error occoured";
}
}//value1
if($value ==2 )
{
$fark = $vote2 - $row["vs2_vote"];
if($fark == 1)
{
$sum_vote = $row["vs1_vote"] + $vote2 ;
$v2_percent = round(($vote2 *100 / $sum_vote),2);
$v1_percent = 100 - $v2_percent;
}
else
{
echo "An error occoured";
}
}//value2
}//while
}//if
$date = date('Y-m-d H:i:s');
$flag['code']=0;
if($value ==1 )
{
if($r=mysql_query("UPDATE v_list SET vs1_vote='$vote',vs1_percent='$v1_percent',vs2_percent='$v2_percent',allvotes='$sum_vote' WHERE id='$int_id'",$con))
{
$flag['code']=1;
echo"hi";
}
}
if($value ==2 )
{
if($r=mysql_query("UPDATE v_list SET vs2_vote='$vote',vs1_percent='$v1_percent',vs2_percent='$v2_percent',allvotes='$sum_vote' WHERE id='$int_id'",$con))
{
$flag['code']=1;
echo"hi";
}
}
print(json_encode($flag));
mysql_close($con);
?>