Jump to content

Parse error - unexpected $end


Onions

Recommended Posts

Hello all!

I have been playing about with PHP, trying to make a simple registration form. The code below should connect to a MySQL database. If no information has been passed to it (via POST) then it will present a form to register. All the details put into it are then sent to a table in a database. Otherwise, it will say "Thank you for registering". The problem is, when I upload the .php file to my server, I get the error

Parse error: syntax error, unexpected $end in harryrabbit.co.uk/electronics/misc/mysql-connect.php on line 36

This makes no sense as line 36 is the "?> to close the PHP script. I thought the heredoc used for echoing the form HTML might be the cause of the problem, however the same error occurs when the whole load of HTML is condensed into one line and echoed by echo "[the HTML]";

 

What is going wrong and how can I fix it?

Onions.

 

<?php
require_once 'credentials.php';
$server = mysql_connect($db_hostname, $db_username, $db_password);
if(!$server) die("Unable to connect to the database: " . mysql_error());
mysql_select_db($db_database) or die("Unable to select database: " . mysql_error());
echo 'Connected!';
if(isset($_POST['username']) &&
   isset($_POST['password']) &&
   isset($_POST['pplink'])){

   $username = get_post('username');
   $password = get_post('password');
   $pplink   = get_post('pplink'  );
   
   $query = "INSERT INTO users VALUES" . "('$username', '$password', '$pplink')";

   if(!mysql_query($query, $db_server))
      echo "Registration failed: " . mysql_error();
   else{
     echo "Thankyou for registering";
   }

echo <<<END
<form action='mysql-connect.php' method='post'> 
  Username <input type='text' name='username' /><br /> 
  Password <input type='password' name='password' /><br /> 
  Picture  <input type='text' name='pplink' /><br /> 

   <input type='submit' value='Sign up!' /><br /><br /> 

  Please enter your desired username and password. <br /> 
  'Picture' is the link to your desired profile picture. We reccomend uploading the picture to imgur. Pictures must be no larger than 100 X 100.<br />
</form>
END;

?>

Link to comment
Share on other sites

Try this:

<?php
require_once 'credentials.php';
$server = mysql_connect($db_hostname, $db_username, $db_password);
if(!$server) die("Unable to connect to the database: " . mysql_error());
mysql_select_db($db_database) or die("Unable to select database: " . mysql_error());
echo 'Connected!';
if(isset($_POST['username']) &&
   isset($_POST['password']) &&
   isset($_POST['pplink'])){

   $username = get_post('username');
   $password = get_post('password');
   $pplink   = get_post('pplink'  );
   
   $query = "INSERT INTO users VALUES" . "('$username', '$password', '$pplink')";

   if(!mysql_query($query, $db_server))
      echo "Registration failed: " . mysql_error();
   else{
     echo "Thankyou for registering";
   }
   }

echo <<<END
<form action='mysql-connect.php' method='post'> 
  Username <input type='text' name='username' /><br /> 
  Password <input type='password' name='password' /><br /> 
  Picture  <input type='text' name='pplink' /><br /> 

   <input type='submit' value='Sign up!' /><br /><br /> 

  Please enter your desired username and password. <br /> 
  'Picture' is the link to your desired profile picture. We reccomend uploading the picture to imgur. Pictures must be no larger than 100 X 100.<br />
</form>
END;

?>

 

You forgot a curly bracket to close the first if()

Link to comment
Share on other sites

Click Solved if your issue has been sorted. ::)

I was looking for it, but I couldn't find the button to click. As it happens, I have another problem  :)

 

Once a set of data is put into the form, it should add the data to a MySQL database. However, I get this error: supplied argument is not a valid MySQL-Link resource

 

It is referring to these lines of code, which should extract the sent data, create a query then put the data into a table. Instead, it gives the error message above.

   $username = $_POST['username'];
   $password = $_POST['password'];
   $pplink   = $_POST['pplink'];
   
   $query = "INSERT INTO users VALUES " . "('$username', '$password', '$pplink')";

   if(!mysql_query($query, $db_server))
      echo "Registration failed: " . mysql_error();
   else{
     echo "Thankyou for registering";
   }

 

My assumption is that the query being put together doesn't make sense to MySQL, however I haven't had enough experience of the language to know what I've done wrong this time  :-[

Any hints?  ;)

 

Thanks again,

Onions.

Link to comment
Share on other sites

Click Solved if your issue has been sorted. ::)

I was looking for it, but I couldn't find the button to click. As it happens, I have another problem  :)

 

Once a set of data is put into the form, it should add the data to a MySQL database. However, I get this error: supplied argument is not a valid MySQL-Link resource

 

It is referring to these lines of code, which should extract the sent data, create a query then put the data into a table. Instead, it gives the error message above.

   $username = $_POST['username'];
   $password = $_POST['password'];
   $pplink   = $_POST['pplink'];
   
   $query = "INSERT INTO users VALUES " . "('$username', '$password', '$pplink')";

   if(!mysql_query($query, $db_server))
      echo "Registration failed: " . mysql_error();
   else{
     echo "Thankyou for registering";
   }

 

My assumption is that the query being put together doesn't make sense to MySQL, however I haven't had enough experience of the language to know what I've done wrong this time  :-[

Any hints?  ;)

 

Thanks again,

Onions.

What I can see is that you haven't executed a query.

Try using:

$query = "INSERT INTO users VALUES ('{$username}', '{$password}', '{$pplink}')";

Then changing this line:

 if(!mysql_query($query, $db_server))

To:

if(!$query)

 

Let us see if you get any joy. 8)

 

Also, echo out this line to see if everything is parsing correctly:

$query = "INSERT INTO users VALUES ('{$username}', '{$password}', '{$pplink}')";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.