Jump to content


Photo

parse error


  • Please log in to reply
9 replies to this topic

#1 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 13 May 2006 - 08:17 PM

I use a registration form that looks something like this:
<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>


and register.php looks like this:
<?
/* 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();

?>

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.

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 13 May 2006 - 08:24 PM

$sql="INSERT INTO user_info (user_name, user_pass, user_first, user_last, user_email) VALUES ('$username','$pass','$first','$last','$email')”;
Looks like a 'smart quote' at the end of that statement. Change it to " and see what happens.
Legend has it that reading the manual never killed anyone.
My site

#3 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 13 May 2006 - 08:27 PM

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

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

to

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

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#4 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 14 May 2006 - 12:40 AM

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

#5 kickassamd

kickassamd
  • Members
  • PipPipPip
  • Advanced Member
  • 102 posts
  • LocationDallas Tx

Posted 14 May 2006 - 12:50 AM

[!--quoteo(post=373617:date=May 13 2006, 07:40 PM:name=webdogjcn)--][div class=\'quotetop\']QUOTE(webdogjcn @ May 13 2006, 07:40 PM) View Post[/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.

#6 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 14 May 2006 - 05:33 PM

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.
<?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;
}
?>

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]

#7 haydndup

haydndup
  • Members
  • PipPipPip
  • Advanced Member
  • 42 posts
  • LocationJohannesburg, South Africa

Posted 14 May 2006 - 06:58 PM

You would redirect the user like so:

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

Put this bit where you have:

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

[!--coloro:#660000--][span style="color:#660000"][!--/coloro--]The Gene Pool Could Use A Little Chlorine[!--colorc--][/span][!--/colorc--]

#8 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 May 2006 - 07:22 PM

Humour me. Copy the line below and use it to replace the similar line you have (which contains weird characters!) and try again:
$sql="SELECT user_name FROM user_info WHERE user_name='$user' and password='$pass'";

Legend has it that reading the manual never killed anyone.
My site

#9 webdogjcn

webdogjcn
  • Members
  • PipPipPip
  • Advanced Member
  • 40 posts

Posted 14 May 2006 - 09:02 PM

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

#10 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 14 May 2006 - 09:11 PM

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.
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users