PHP删除用户脚本

时间:2013-05-12 01:22:25

标签: php web delete-row

我创建了这个名为urmusers.php的脚本,但是我收到了意外的文件结束错误。我是PHP的小说,刚开始学习它。有谁可以看看我的代码并告诉我它有什么问题?我将不胜感激。我也明白mysql_ *是折旧的,但出于我的小项目的目的,它并不重要,因为它不会在实时环境中使用,而只是用于测试目的。

脚本如下:

<?php

$mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "newman13";
$mysql_database = "ninjaz_gaming";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Could not connect database");
mysql_select_db($mysql_database, $bd) or die("Could not select database");

$id = get_post('id');
$name = get_post('name');
$email = get_post('email');
$ircts3 = get_post('ircts3');
$game = get_post('game');

if (isset($_POST['delete']) && $id != "")
{
$query = "DELETE FROM Users WHERE id='$id'";

if (!mysql_query($query, $bd))
{
echo "DELETE failed: $query<br />" .
mysql_error() . "<br /><br />";
}
else
{
for ($j = 0 ; $j < $rows ; ++$j)
$row = mysql_fetch_row($result);
echo <<<_END
<pre>
Id $row[0]
Name $row[9]
Email $row[3]
IRCTS3 $row[6]
Fav Game $row[7]
</pre> 
}
<form action="urmuser.php" method="post">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="id" value="$row[0]" />
<input type="submit" value="DELETE USER" /></form>
_END;

}
mysql_close($bd);
function get_post($var)
{
return mysql_real_escape_string($_POST[$var]);
}
?>

2 个答案:

答案 0 :(得分:1)

您需要缩进代码!

第21行的if语句缺少左大括号{

您还需要关闭PHP标记(?>)以将HTML放在那里,否则PHP会尝试解析它。 例如:

<pre>
    <?php
      $blah = "a";
      echo($blah);
    ?>
</pre>
    <?php
      ...

答案 1 :(得分:0)

由于结束的大括号位于Heredoc syntax for ($j = 0 ; $j < $rows ; ++$j)内,因此未正确解析,因此您未关闭echo <<<_END <pre> .... _END;

for ($j = 0 ; $j < $rows ; ++$j)
{
$row = mysql_fetch_row($result);
echo <<<_END
<pre>
Id $row[0]
Name $row[9]
Email $row[3]
IRCTS3 $row[6]
Fav Game $row[7]
</pre> 
}   // This one here is not being parsed as a php end curly-bracket, move it to below
<form action="urmuser.php" method="post">
<input type="hidden" name="delete" value="yes" />
<input type="hidden" name="id" value="$row[0]" />
<input type="submit" value="DELETE USER" /></form>
_END;
// move it to here

需要在_END;

之后移动它