0

我无法让我的代码正常工作。如果我将它输入 phpMyAdmin 它可以工作,但是当我在代码中尝试它时,它不会更新数据库。

<?php
$con = mysql_connect("SERVER","USER","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE", $con);

$sp=mysql_real_escape_string($_GET['file']);

$query = "UPDATE TDB SET WEIGHT=100000 WHERE PATH='$sp'"; 

mysql_close($con);

?>
4

3 回答 3

1

试试这个代码片段,看看你是怎么做的。

<?php
$con = mysql_connect("SERVER","USER","PASSWORD");
if (!$con) {
  die('Could not connect: ' . mysql_error());
} else {
    mysql_select_db("DATABASE", $con);
    $sp=mysql_real_escape_string($_GET['file']);
    $query = "UPDATE TDB SET WEIGHT=100000 WHERE PATH='$sp'"; 
    $result = mysql_query($query);
    mysql_close($con);
}
?>

我建议这样做,因为 PHP 不再支持 mysql。

<?php
$mysqli = new mysqli("localhost", "user", "password", "database");

if (!$mysqli) {
  die('Could not connect: ' . $mysqli->connect_error);
} else {
    $sp = $mysqli->real_escape_string($_GET['file']);
    $query = "UPDATE TDB SET WEIGHT=100000 WHERE PATH='$sp'"; 
    $mysqli->query(query);
    $mysqli->close();
}
?>
于 2013-03-25T16:22:24.097 回答
0
<?php
$con = mysql_connect("SERVER","USER","PASSWORD");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("DATABASE", $con);

$sp=mysql_real_escape_string($_GET['file']);

$sql = "UPDATE TRACKDB SET WEIGHT=100000 WHERE PATH='$sp'"; 

$result = mysql_query($sql) or die(mysql_error());

mysql_close($con);

?>
于 2013-03-25T16:12:35.547 回答
0

您没有执行您的查询。您只是在定义一个恰好包含一些 SQL 的字符串,例如

$sql = "blah blah blah";
$result = mysql_query($sql) or die(mysql_error()); <--forgot this
于 2013-03-25T16:09:03.877 回答