我似乎无法从此脚本获得任何响应。没有错误消息,没有......正如你所看到的,我想要做的是插入表“yum”,回显最后一个条目,然后使用最后一个条目插入一个单独的表。我做错了什么,为什么没有错误消息?
<?php
$b= $_GET["sto"];
$pb= $_GET["usto"];
$sql = "INSERT INTO yum(vara, varb)
VALUES('" . $b . "', '" . $pb . "')";
$hostname_Database = "blocked";
$database_Database = "blocked";
$username_Database = "blocked";
$password_Database = "blocked";
$mysqli = new mysqli($hostname_Database, $username_Database, $password_Database, $database_Database);
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = $mysqli->query($sql);
if ($result) {
echo "ha";
$sql = $mysqli->query("SELECT vara FROM yum ORDER BY vara DESC LIMIT 1");
if($sql === FALSE) {
echo "ahahahahah";
die(mysql_error()); // TODO: better error handling
}
while($row = mysql_fetch_array($sql))
{
echo $row['vara'];
}
//$row = $result->fetch_assoc();
$sql = "INSERT INTO disco(varb, vara)
VALUES( '" . $item . "', {$row['vara']})";
$result = $mysqli->query($sql);
if ($result) {
etc...
}
}
?>
答案 0 :(得分:1)
您正在使用
while($row = mysql_fetch_array($sql))
{
echo $row['vara'];
}
这里当$ row对于最后一个条目变为null时所以使用foreach但是因为你只得到一行而不是所有的while循环只需使用
$row = mysql_fetch_array($sql);
也可以只使用mysql_ *或mysqli _ *
这是完整的代码
$mysqli = mysqli_connect($hostname_Database, $username_Database, $password_Database, $database_Database);
if (mysqli_connect_errno($mysqli)) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$result = $mysqli_query($con,$sql);
if ($result) {
echo "ha";
$sql = $mysqli_query("SELECT vara FROM yum ORDER BY vara DESC LIMIT 1");