gpt4 book ai didi

php - sql查询结果为空。

转载 作者:行者123 更新时间:2023-11-29 06:48:12 24 4
gpt4 key购买 nike

我是 php 的新手,真的不知道我做错了什么。

我的变量 $largeid 在结果中似乎是空的:

$newfile=$_POST['largeName'].$largeid.".php";

即使在执行这段代码之后:

while($largeidrow = mysql_fetch_array(largeidresult))
{
$largeid = $largeidrow['large_id'];
}

这是完整的代码:

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

mysql_select_db("test", $con);

$sql="INSERT INTO larges(name,largecontent)VALUES('$_POST[largeName]','$_POST[content]')";

if (!mysql_query($sql,$con))
{
echo "failed";
die('Error: ' . mysql_error());
}
echo "1 record added";

$largeidresult = ("SELECT large_id FROM larges WHERE name='$_POST[largeName]'");

if (!mysql_query($largeidresult,$con))
{
echo "failed";
die('Error: ' . mysql_error());
}

while($largeidrow = mysql_fetch_array(largeidresult))
{
$largeid = $largeidrow['large_id'];
}

if ($_POST['largeName']) {
error_reporting(0);
$i=1;
while($file = fopen("untitled$i.php", "r")) { fclose($file); $i++; }
if($file = fopen("untitled$i.php", "w")) {
$php = "<html> \n <head> \n </head> \n <body> \n test \n <?php \n echo 'hallo'; \n ?> \n </body> \n <html>";
$file_ext = strip_tags($_POST['$php']);
if(fwrite($file, $php) === false) { echo "Could not write"; exit; }
fclose($file);
$newfile=$_POST['largeName'].$largeid.".php";
system("mv untitled$i.php $newfile");
header("Location: $newfile");
}
}
else {
echo "<form method=post action='".$_SERVER["SCRIPT_NAME"]."'>\n";
echo "New File Name: <input name='filename'>\n</form>\n";
}
?>

最佳答案

首先我会说不要使用 mysql 函数。使用 mysqliPDO

From PHP documentation :

Warning This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include..

在您的代码中,您调用 mysql_fetch_array(#link) 的方式是错误的。

$sql = ("SELECT large_id FROM larges WHERE name='$_POST[largeName]'");

$result = mysql_query($sql);
if($result)
{
while($row= mysql_fetch_array($result))
{
$largeid = $row['large_id'];
}
}

关于php - sql查询结果为空。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17361670/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com