Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,689 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,306 people online right now. Registration is fast and FREE... Join Now!




Another form question

 
Reply to this topicStart new topic

Another form question, Parse error: syntax error, unexpected $end

rjolitz
post 24 May, 2008 - 10:44 PM
Post #1


D.I.C Head

Group Icon
Joined: 17 May, 2008
Posts: 86



Thanked 1 times

Dream Kudos: 75
My Contributions


Here is the code I'm using:

CODE

<?php

include ('db_var.php');

if ($_POST) {

  $user=$_POST['user_name'];
  $password=$_POST['password'];
  $confirm=$_POST['confirmpw'];
  $affiliation=$_POST['affiliation'];
  $admin='N';
  $subscription='N';
  $beta_test='N';
  $email=$_POST['email'];
  $points=0;
  $wins=0;
  $losses=0;
  $rank='Ensign';

  if ($password != $confirmpw) {  
      
print("      <span style='color:red'>ERROR: Passwords do not match! </span>");

}

else

{

   $mysqli = new mysqli($host, $user, $pw, $db);


if ( $mysqli->errno)
   {
      printf("Unable to connect to the database: <br />  %s", $mysqli->error);
      exit();
    }
  
$query = "SELECT COUNT(id) FROM users WHERE user_name = $user";

$result= $mysqli->query($query, MYSQLI_STORE_RESULT);

list($count) =$result->fetch_row();

if ($count >= 1) {  

print(" <span style='color:red'>ERROR: Username is not available! </span>");



}
else

{

$query = "INSERT INTO users (`user_name` ,`password` ,`affiliation` ,`admin` ,`subscription` ,`beta_test` ,
`email` ,`points` ,`wins` ,`losses` ,`rank`) VALUES (
'$user','$password', '$confirm', '$affiliation', '$admin', '$subscription', '$beta_test','$email','$points','$wins','$losses', '$rank')";

$result=$mysqli->query($query, MYSQLI_STORE_RESULT);

$result->free();
}

?>

<html>
<body>
<form method='post' action='register.php'>

Username: <input type='text' name='user_name' /><br />
Password: <input type='password' name='password' /><br />
Confirm Password: <input type='password' name='confirmpw' /><br />
affiliation: <input type='text' name='affiliation' /><br />
Email: <input type='text' name='email' /> <br />
<br />
<input type='submit' value='Register!' />
</form>

</body>
</html>


I'm getting:

Parse error: syntax error, unexpected $end in /home/rich/public_html/register.php on line 81


I've gone through this several times to see if I'm missing a single or double quote or a missing ; somewhere. And I'm not seeing anything. I'm sure I'm missing something ultra-obvious here.

anyone see something I'm missing?


User is offlineProfile CardPM

Go to the top of the page

PsychoCoder
post 24 May, 2008 - 11:01 PM
Post #2


using DIC.Core;

Group Icon
Joined: 26 Jul, 2007
Posts: 8,933



Thanked 118 times

Dream Kudos: 8525

Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions


I'm not 100% positive but I think you error is originating from here


php

else

{

$mysqli = new mysqli($host, $user, $pw, $db);


Notice you're missing the closing } for your else statement


php

else
{
$mysqli = new mysqli($host, $user, $pw, $db);
}
User is offlineProfile CardPM

Go to the top of the page

rjolitz
post 24 May, 2008 - 11:41 PM
Post #3


D.I.C Head

Group Icon
Joined: 17 May, 2008
Posts: 86



Thanked 1 times

Dream Kudos: 75
My Contributions


That wasn't the } I was missing but it put me on the right track!

Now the page comes up - the form submits... not on to figuring out why it won't write to the DB now smile.gif

thanks!!

Rich
User is offlineProfile CardPM

Go to the top of the page

no2pencil
post 24 May, 2008 - 11:58 PM
Post #4


My fridge be runnin OH NOEZ!

Group Icon
Joined: 10 May, 2007
Posts: 6,354



Thanked 58 times

Dream Kudos: 2375

Expert In: Goofing Off

My Contributions


QUOTE

CODE

$query = "INSERT INTO users (`user_name` ,`password` ,`affiliation` ,`admin` ,`subscription` ,`beta_test` ,
`email` ,`points` ,`wins` ,`losses` ,`rank`) VALUES (
'$user','$password', '$confirm', '$affiliation', '$admin', '$subscription', '$beta_test','$email','$points','$wins','$losses', '$rank')";

$result=$mysqli->query($query, MYSQLI_STORE_RESULT);

$result->free();

... you don't do any testing. Check for $result to make sure that it obtained a value.

CODE

if (!$result) {
    die('Invalid query: ' . mysql_error());
}
User is offlineProfile CardPM

Go to the top of the page

rjolitz
post 25 May, 2008 - 12:17 AM
Post #5


D.I.C Head

Group Icon
Joined: 17 May, 2008
Posts: 86



Thanked 1 times

Dream Kudos: 75
My Contributions


Yep!

Going in to put in testing and echo values to see what is going on.

It appears to be a syntax error which I suspected. smile.gif
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 07:33AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month