0

I have created this script called urmusers.php, however I get an unexpected end of file error. I am a noobie to PHP and just started learning it recently. Could anyone please look at my code and tell me what is wrong with it? I would greatly appreciate it. I also understand that mysql_* is depreciated but for the purpose of my little project it does not matter as this will not be used in a live environment but for testing purposes only.

The scrip is as follows:

<?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
  • Deleting from the database is bad practice, you should append a number to a column name which wont be indexed when searching Commented May 12, 2013 at 1:25
  • As I have said this is a small project, and am not so much worried about little stuff like that. Commented May 12, 2013 at 1:26

2 Answers 2

1

You need to indent your code!

You are missing the opening curly-brace { for the if statement on line 21.

You also need to close your PHP tags (?>) to put HTML there, otherwise PHP will try to parse it. For example:

<pre>
    <?php
      $blah = "a";
      echo($blah);
    ?>
</pre>
    <?php
      ...
Sign up to request clarification or add additional context in comments.

4 Comments

or: echo '<pre>$blah</pre>';
He is using Heredoc syntax echo <<<_END <pre> .... _END; -php.net/manual/en/…
Didn't help so I switched it back. Edited my code a bit but still getting the same error.
Don't switch it back. The thing with PHP is, having one problem stops you from seeing many others. You have many problems. Another one being that your for loop closing bracket is inside your echo Heredoc block.
0

You are not closing your for ($j = 0 ; $j < $rows ; ++$j) as your closing curly-bracket is inside your Heredoc syntax echo <<<_END <pre> .... _END; so it is not being parsed correctly

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

Need to move it to after _END;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.