我对 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";
}
?>