Jump to content

parse error


webdogjcn

Recommended Posts

I use a registration form that looks something like this:
[code]
<form name='register' method ='post' action='register.php'>
<input type='text' name='first' value='first' size='20'>
<input type='text' name='last' value='last' size='20'>
<input type='text' name='username' value='username' size='20'>
<input type='password' name='password' value='password' size='20'>
<input type='text' name='email' value='email' size='20'>
<input type='submit' name='Submit' value='Submit'>
<input type='reset' name='Reset' value='Reset'>
</form>[/code]


and register.php looks like this:
[code]
<?
/* variables to use */
$username="";
$password="";
$database="";

/* variables from form data*/
$first=$_POST['first'];
$last=$_POST['last'];
$username=$_POST['username'];
$pass=$_POST['password'];
$email=$_POST['email'];

/* connecting */

@mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "SELECT user_id FROM user_info";
$result = mysql_query($query);
$num=mysql_numrows($result);
$num++;

$sql="INSERT INTO user_info (user_name, user_pass, user_first, user_last, user_email) VALUES ('$username','$pass','$first','$last','$email')”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}

mysql_close();

?>[/code]

I get the following error:
Parse error: parse error, unexpected $ in /home/www/altgames.awardspace.com/register.php on line 34

Now I don't even see anything on line 34. I really need this pretty quick so if anyone has any thoughts please fill me in.
Link to comment
https://forums.phpfreaks.com/topic/9621-parse-error/
Share on other sites

[!--quoteo(post=373583:date=May 13 2006, 08:24 PM:name=AndyB)--][div class=\'quotetop\']QUOTE(AndyB @ May 13 2006, 08:24 PM) [snapback]373583[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]$sql="INSERT INTO user_info (user_name, user_pass, user_first, user_last, user_email) VALUES ('$username','$pass','$first','$last','$email')”;[/code]
Looks like a 'smart quote' at the end of that statement. Change it to " and see what happens.
[/quote]

[code]
$query = "SELECT user_id FROM user_info";
$result = mysql_query($query);
$num=mysql_numrows($result);
$num++;
[/code]

to

[code]
$query = "SELECT user_id FROM user_info";
$result = mysql_query($query);
$num=mysql_num_rows($result);
$num++;
[/code]
Link to comment
https://forums.phpfreaks.com/topic/9621-parse-error/#findComment-35555
Share on other sites

[!--quoteo(post=373617:date=May 13 2006, 07:40 PM:name=webdogjcn)--][div class=\'quotetop\']QUOTE(webdogjcn @ May 13 2006, 07:40 PM) [snapback]373617[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Andy B: I made the page in Notepad and didn't think that notepad supported 'Smart Quotes'
Redarrow: what change did you make in the code I can't see any difference

I don't know what you did but I copied it in there and now I get: Unable to select database
[/quote]


Did you spell your database name correct in $database? also does that user have access to that DB? Also had some variences with scripts on diffrent hosts

mysql_select_db($database) would work on host A but host B had to be mysql_select_db("$database");

Also if you have some extra $$ I would HIGHLY recommend Zend Developer.
Link to comment
https://forums.phpfreaks.com/topic/9621-parse-error/#findComment-35589
Share on other sites

Thanks, those solutions didnt seem to solve anything, but it strangely worked when I removed my comment lines. I now have a new problem involving the script I use to login. I get an unexpected T_STRING error in login.php.
[code]<?php
$name="";
$lock="";
$database="";

$user=$_POST['username'];
$pass=$_POST['password'];

mysql_connect('',$name,$lock); //im not posting my hostname here so dont comment about it being wrong
@mysql_select_db($database) or die( "Unable to select database");
$sql="SELECT user_name FROM user_info WHERE user_name='$user' and password=’$pass’”;
$r = mysql_query($sql);
if(!$r) {
$err=mysql_error();
print $err;
exit();
}
if(mysql_affected_rows()==0){
print "no such login in the system. please try again.";
exit();
}
else{
print "successfully logged into system.";
header("location:http://...");
exit;
}
?>[/code]

returns the error:
Parse error: parse error, unexpected T_STRING in .../login.php on line 19


Also, how would I add the value of variables into the url that the page should be redirected to? So that I could redirect the URL to a page that would look like [a href=\"http://mypage.com/userarea/index.htm?name=blah&pass=true\" target=\"_blank\"]http://mypage.com/userarea/index.htm?name=blah&pass=true[/a]
Link to comment
https://forums.phpfreaks.com/topic/9621-parse-error/#findComment-35753
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.