TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Absolute Beginners (http://www.talkphp.com/absolute-beginners/)
-   -   Trying to create a "sign up form"....help please (http://www.talkphp.com/absolute-beginners/63-trying-create-sign-up-form-help-please.html)

RogueDogg 06-01-2005 11:53 PM

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

jaswinder_rana 06-02-2005 12:01 AM

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


RogueDogg 06-02-2005 12:07 AM

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?

jaswinder_rana 06-02-2005 12:12 AM

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

RogueDogg 06-02-2005 12:33 AM

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????

jaswinder_rana 06-02-2005 12:37 AM

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


SoftCloud 06-02-2005 12:40 AM

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')"


RogueDogg 06-02-2005 12:42 AM

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

jaswinder_rana 06-02-2005 12:42 AM

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

jaswinder_rana 06-02-2005 12:48 AM

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.

RogueDogg 06-02-2005 12:51 AM

Think maybe it's the signup.html form I'm using then? That is calling this signup.php script?

jaswinder_rana 06-02-2005 12:52 AM

No, its the script. post the code WHICH YOU ARE USING NOW

SoftCloud 06-02-2005 12:53 AM

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.

jaswinder_rana 06-02-2005 12:53 AM

oh ok, sorry couldn't get the meaning

SoftCloud 06-02-2005 12:54 AM

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!

RogueDogg 06-02-2005 12:55 AM

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>'
    } 
?>


jaswinder_rana 06-02-2005 01:03 AM

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

RogueDogg 06-02-2005 01:10 AM

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.

jaswinder_rana 06-02-2005 01:13 AM

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

RogueDogg 06-02-2005 01:27 AM

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?


All times are GMT. The time now is 08:38 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0