Jump to content

Archived

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

webdogjcn

parse error

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.

Share this post


Link to post
Share on other sites
[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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
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.

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
You would redirect the user like so:

[code]
header("Location: http://www.yousite.com/the_page_you_want_redirected_to.php?name=$user&pass=true");
[/code]

Put this bit where you have:

header("location:http://...");

Share this post


Link to post
Share on other sites
Humour me. Copy the line below and use it to replace the similar line you have (which contains weird characters!) and try again:
[code]$sql="SELECT user_name FROM user_info WHERE user_name='$user' and password='$pass'";[/code]

Share this post


Link to post
Share on other sites
well it worked but for some reason it wont redirect:

successfully logged into system.
Warning: Cannot modify header information - headers already sent by (output started at /home/www/altgames.awardspace.com/login.php:23) in /home/www/altgames.awardspace.com/login.php on line 24

Share this post


Link to post
Share on other sites
The header error is because you have sent ouput to the browser already (successfully logged into system). Remove that message line since it's really redundant as the redirection will make if evident to your visitor that they are now logged in.

Share this post


Link to post
Share on other sites

×

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.