我很新的PHP,真的不知道我做錯了什麼。sql查詢結果爲null。
我的變量$ 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";
}
?>
謝謝你好,先生! – Johannes
開始使用'mysqli'或'PDO'擴展名編寫代碼。 – adatapost