TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-01-2005, 11:53 PM   #1 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default Trying to create a "sign up form"....help please

I am trying to create a sign up form and this is the error I keep getting:

Parse error: parse error, unexpected $ in /XXXX/XXXXX/public_html/signup/signup.php on line 37

I have been doing some searching and found that it seems to be a sytax error of some sort but I can't find the problem. Maybe a second or third set of eyes can help. Here's the source code:

<?php
$FirstName = $_GET["FirstName"];
$LastName = $_GET["LastName"];
$Email = $_GET["Email"];
$Phone = $_GET["Phone"];
$Address = $_GET["Address"];
$City = $_GET["City"];
$State = $_GET["State"];
$Zip = $_GET["Zip"];
$Username = $_GET["Username"];
$Password = $_GET["Password"];
$LastLogin = date("Y-m-d");
print "FirstName is $FirstName<br>\n";
print "Email is $Email<br>\n";

mysql_connect("localhost", "dbname", "dbpassword");

$result = mysql_query(
"insert into dbname.dbtable
(FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin) values
('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')"
);
if ($result) {
echo <<<EOT
Thank You
Your signup is appreciated.
EOT;
} else {
echo "Something went awry with the awful SQL";
}
mysql_close();
?>

If someone could look over this and tell me what I'm doing wrong I'd appreciate it....
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 12:01 AM   #2 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

Hi,
not sure exactly. i have changed the code(just to correct something which you should think about (not necessary, bu tgood to have)
try this code and see if error is again there
PHP Code:
<?php
    $FirstName 
mysql_escape_string($_GET["FirstName"]);//use this function on all the input before storing it in database
    
$LastName $_GET["LastName"];
    
$Email $_GET["Email"];
    
$Phone $_GET["Phone"];
    
$Address $_GET["Address"];
    
$City $_GET["City"];
    
$State $_GET["State"];
    
$Zip $_GET["Zip"];
    
$Username $_GET["Username"];
    
$Password $_GET["Password"];
    
$LastLogin date("Y-m-d");
    print 
"FirstName is $FirstName<br>\n";
    print 
"Email is $Email<br>\n";

    
$con = @mysql_connect("localhost""dbname""dbpassword");
    if(
$con)
    {
        
$query "insert into dbname.dbtable (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)".
             
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')"
        
$result mysql_query($query);
        if (
$result)
        {
            echo <<<EOT
            Thank You
            Your signup is appreciated.
    EOT;
        }
        else
        {
            echo "Something went awry with the awful SQL";
        }
        mysql_close(
$con);
    }
    else
    {
        echo 'Could not connect to database<br>';
    }
?>
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:07 AM   #3 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

Parse error: parse error, unexpected T_VARIABLE

Nope didn't seem to work, different error but still not working.

One note * On your comment, was I suppose to add that info that you added to each one of those inputs?
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 12:12 AM   #4 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

YES, you should use that function to ALL inputs made by user, which you are going to store in database.

in new version the new function is
mysql_real_escape_string() which is recommended to use, but, you have to make sure if it exists in your version or not
or you can do this

$var = (function_exists('mysql_real_escape_string'))?mysq l_real_escape_string($user_info):mysql_escape_stri ng($user_info);

its jsut saying if that function exists then use that else use other one

ABOUT THE ERROR
please specify the line number where error occured
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:33 AM   #5 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

WOW...ok I'm a serious newb when it comes to all this so if I ask many questions or repeat myself please excuse my ignorance. I'll try and digest what you just explained to me but to answer your question the error line number is the very last line number in the script. So if ?> is line 37 the error will be on line 37, that is for the original problem. The 2nd problem ( your fixed version ) Says the error is on line 24. Hope this helps


*** Just a side note I'm taking a lesson from the Apache, MySQL, & PHP WebDevelopment for Dummies book and modifying it *** So the first set of code I posted it the modified version of their "example" in the book. I can post that here if you like????
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 12:37 AM   #6 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

ooops ws a syntax, try again
also i was newbie once too. so, don't worry, maybe you'll get it in less time thatn me :)
PHP Code:
<?php
    $FirstName 
mysql_escape_string($_GET["FirstName"]);//use this function on all the input before storing it in database
    
$LastName $_GET["LastName"];
    
$Email $_GET["Email"];
    
$Phone $_GET["Phone"];
    
$Address $_GET["Address"];
    
$City $_GET["City"];
    
$State $_GET["State"];
    
$Zip $_GET["Zip"];
    
$Username $_GET["Username"];
    
$Password $_GET["Password"];
    
$LastLogin date("Y-m-d");
    print 
"FirstName is $FirstName<br>\n";
    print 
"Email is $Email<br>\n";

    
$con = @mysql_connect("localhost""dbname""dbpassword");
    if(
$con)
    {
        
$query "insert into dbname.dbtable (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)".
             
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')";
        
$result mysql_query($query);
        if (
$result)
        {
            echo <<<EOT
            Thank You
            Your signup is appreciated.
EOT;
        }
        else
        {
            echo 
mysql_error();
        }
        
mysql_close($con);
    }
    else
    {
        echo 
'Could not connect to database<br>';
    }
?>
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:40 AM   #7 (permalink)
The Wanderer
 
Join Date: Jun 2005
Location: London
Posts: 7
Thanks: 0
SoftCloud is on a distinguished road
Default

Nothing owuld be the problem with a missing ; at the end of this code:
PHP Code:
        $query "insert into dbname.dbtable (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)"
             
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')" 
???

Fixed:
PHP Code:
        $query "insert into dbname.dbtable (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)"
             
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')"
SoftCloud is offline  
Reply With Quote
Old 06-02-2005, 12:42 AM   #8 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

Parse error: parse error, unexpected T_SL, expecting ',' or ';' in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 28


LOL getting frustrated like me yet? I really really appreciate your help on this. I've been working on it for almost 8 hours now and I'm about 2 lines of code away from ripping out my eye balls...hehe NOT really but you understand what I mean.

Here's the revised up to date code:

<?php
$FirstName = mysql_escape_string($_GET["FirstName"]);//use this function on all the input before storing it in database
$LastName = mysql_escape_string($_GET["LastName"]);
$Email = mysql_escape_string($_GET["Email"]);
$Phone = mysql_escape_string($_GET["Phone"]);
$Address = mysql_escape_string($_GET["Address"]);
$City = mysql_escape_string($_GET["City"]);
$State = mysql_escape_string($_GET["State"]);
$Zip = mysql_escape_string($_GET["Zip"]);
$Username = mysql_escape_string($_GET["Username"]);
$Password = mysql_escape_string($_GET["Password"]);
$LastLogin = date("Y-m-d");
print "FirstName is $FirstName<br>\n";
print "Email is $Email<br>\n";

$con = @mysql_connect("localhost", "dbuser", "dbpassword");
if($con)
{
$query = "insert into dbname.table (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)".
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')";
$result = mysql_query($query);
if ($result)
{
echo <<<EOT
Thank You
Your signup is appreciated.
EOT; }
else
{
echo mysql_error();
}
mysql_close($con);
}
else
{
echo 'Could not connect to database<br>';
}
?>
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 12:42 AM   #9 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

Quote:
Originally Posted by SoftCloud
Nothing owuld be the problem with a missing ; at the end of this code:
sorry, din't get you meant
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:48 AM   #10 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

Quote:
Originally Posted by RogueDogg
Parse error: parse error, unexpected T_SL, expecting ',' or ';' in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 28


LOL getting frustrated like me yet? I really really appreciate your help on this. I've been working on it for almost 8 hours now and I'm about 2 lines of code away from ripping out my eye balls...hehe NOT really but you understand what I mean.
ok, i tried your code and din't get any error
did you try the code i posted second time??

and also try putting this
error_reporting(E_ALL);
as the very first line of your script

SIDE NOTE: programming is time consuming specially errors, so start living with this. and as you can see my signatures, Errors = Better programming.
because next time you'll try not to do the same error and even if you do get the error, you'll know what it was. makes you a better programmer.
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:51 AM   #11 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

Think maybe it's the signup.html form I'm using then? That is calling this signup.php script?
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 12:52 AM   #12 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

No, its the script. post the code WHICH YOU ARE USING NOW
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:53 AM   #13 (permalink)
The Wanderer
 
Join Date: Jun 2005
Location: London
Posts: 7
Thanks: 0
SoftCloud is on a distinguished road
Default

Quote:
Originally Posted by jaswinder_rana
sorry, din't get you meant
At the end of that database query it was missing a ; (Semi Colon) - I just thought that it might be needed.
SoftCloud is offline  
Reply With Quote
Old 06-02-2005, 12:53 AM   #14 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

oh ok, sorry couldn't get the meaning
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 12:54 AM   #15 (permalink)
The Wanderer
 
Join Date: Jun 2005
Location: London
Posts: 7
Thanks: 0
SoftCloud is on a distinguished road
Default

Quote:
Originally Posted by jaswinder_rana
No, its the script. post the code WHICH YOU ARE USING NOW
And don't forget [code][/code] or [php][/php] tags!
SoftCloud is offline  
Reply With Quote
Old 06-02-2005, 12:55 AM   #16 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

PHP Code:
<?php
error_reporting
(E_ALL); 
    
$FirstName mysql_escape_string($_GET["FirstName"]);//use this function on all the input before storing it in database 
    
$LastName mysql_escape_string($_GET["LastName"]); 
    
$Email mysql_escape_string($_GET["Email"]); 
    
$Phone mysql_escape_string($_GET["Phone"]); 
    
$Address mysql_escape_string($_GET["Address"]); 
    
$City mysql_escape_string($_GET["City"]); 
    
$State mysql_escape_string($_GET["State"]); 
    
$Zip mysql_escape_string($_GET["Zip"]); 
    
$Username mysql_escape_string($_GET["Username"]); 
    
$Password mysql_escape_string($_GET["Password"]); 
    
$LastLogin date("Y-m-d"); 
    print 
"FirstName is $FirstName<br>\n"
    print 
"Email is $Email<br>\n"

    
$con = @mysql_connect("localhost""dbuser""dbpassword"); 
    if(
$con
    { 
        
$query "insert into dbname.dbtable (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)"
             
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')"
        
$result mysql_query($query); 
        if (
$result
        { 
            echo <<<
EOT 
            Thank You 
            Your signup is appreciated

EOT;        } 
        else 
        { 
            echo 
mysql_error(); 
        } 
        
mysql_close($con); 
    } 
    else 
    { 
        echo 
'Could not connect to database<br>'
    } 
?>
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 01:03 AM   #17 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

ok change this
PHP Code:
            echo <<<EOT
            Thank You
            Your signup is appreciated.
EOT;        } 
to
Quote:
echo <<<EOT
Thank You
Your signup is appreciated.
EOT;
}
only difference is } is on second line and make sure there's nothing after the
EOT;(not even space)

give it a try

EDIT: had to use [quote] because i don't know why but [php] tags din't show it properly
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 01:10 AM   #18 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

Ok we've made some progress:

It looks like I'm not filling out my dbuser, dbpass, db, and dbtable info correctly, tell me what you think.

Quote:

Notice: Undefined index: FirstName in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 3

Notice: Undefined index: LastName in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 4

Notice: Undefined index: Email in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 5

Notice: Undefined index: Phone in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 6

Notice: Undefined index: Address in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 7

Notice: Undefined index: City in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 8

Notice: Undefined index: State in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 9

Notice: Undefined index: Zip in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 10

Notice: Undefined index: Username in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 11

Notice: Undefined index: Password in /XXXX/XXXXXXXX/public_html/signup/signup.php on line 12
FirstName is
Email is
Table 'cashflow_members.client' doesn't exist
PHP Code:
 $con = @mysql_connect("localhost""database_johndoe""password"); 
    if(
$con
    { 
        
$query "insert into database_members.client (FirstName, LastName, Email, Phone, Address, City, State, Zip, Username, Password, LastLogin)"
             
"values('$FirstName', '$LastName', '$Email', '$Phone', '$Address', '$City', '$State', '$Zip', '$Username', '$Password', '$LastLogin')"
        
$result mysql_query($query); 
This is the part of the db connection I think I'm messing up, I changed the actual info for fake info but kept the same formatting so you know how mine looks.
RogueDogg is offline  
Reply With Quote
Old 06-02-2005, 01:13 AM   #19 (permalink)
The Acquainted
 
Join Date: May 2005
Posts: 106
Thanks: 0
jaswinder_rana is on a distinguished road
Default

About database i can't say becasue you should know what is the name of the table you are using

errors
it seems that the names you are using in $_GET[] are not proper and the ydon't exist.

also try doing this to avoid these kinda errors
$LastName = (isset($_GET["LastName"]))?mysql_escape_string($_GET["LastName"]):'';

it'll check if the variable is set, if not then it'll make it equal to space

EDIT: just noticed you din't use mysql_select_db('database_name') to select the dataabse you want to work on
__________________
---------------------------
Errors = Improved Programming.
Portfolio
Send a message via MSN to jaswinder_rana
jaswinder_rana is offline  
Reply With Quote
Old 06-02-2005, 01:27 AM   #20 (permalink)
The Wanderer
 
Join Date: Jun 2005
Posts: 13
Thanks: 0
RogueDogg is on a distinguished road
Default

Code:
<html>
<head>
<title>Sign Up Form</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
Welcome new customer! Please fill out the form below to begin.<br>
<br>
<form name="signup" method="GET"
action="signup.php">
FirstName: <input type="text" FirstName="FirstName"><br>
LastName: <input type="text" LastName="LastName"><br>
Email: <input type="text" Email="Email"><br>
Phone#: <input type="text" Phone="Phone"><br>
Address: <input type="text" Address="Address"><br>
City: <input type="text" City="City"><br>
State: <input type="text" State="State"><br>
Zip: <input type="text" Zip="Zip"><br>
Username: <input type="text" Username="Username"><br>
Password: <input type="password" Password="Password"><br>
<input type="submit" name="Submit" value="Sign Up">
</form>
</body>
</html>
K there is the "signup.html" form that should be correct. As far as selecting the db that I want to work on isn't that what the
PHP Code:
 "insert into cashflow_members.client 
line is for?

Now in the members database and the clients table there is "FirstName, LastName, Email, etc...." And I made sure to use caps where they were and no spaces so that should'nt be the problem either right?
RogueDogg is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 09:47 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design