freddyw Posted July 16, 2009 Share Posted July 16, 2009 Hello fellow freaks. Im still getting to grips with php so please go easy on me. No throwing rotton vegetables at me for silly mistakes, i beg you. Im creating a registration form with php. The information added on the form is to be added into the psql database (in the users table - consisting of first name, last name, username, and password) heres my code so far NB: im behind the times and having to work with PHP 5, not 6 unfortunately <html> <head><title> Register </title></head> <body> <? $self = $server ['PHP_SELF']; $first_name = $_post ['first_name']; $last_name = $_post ['last_name']; $username = $_post ['username']; $password = $_post ['password']; if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ) { $form.="Please enter your details below to register with Sporticket"; $form.="<form action=\"$self\""; $form.=" method=\"post\"> First Name: "; $form.="<input type=\"text\" name=\"first_name\""; $form.=" value=\"$first_name\"><br>Last Name: "; $form.="<input type=\"text\" name=\"last_name\""; $form.=" value=\"$last_name\"><br>Username: "; $form.=" <input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>Password: "; $form.=" input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.=" <input type=\"submit\" value=\"Submit\">"; $form.=">/form>"; } else { $conn = @pg_connect(~connection details hidden~); $psql = "insert into users (first_name,last_name,username,password) values (\"$first_name\",\"$last_name\",\"$username\", password(\"$password\") )"; $result = pg_query($conn) or die ("Could not execute query"); if ( $result ) { echo ( "Congratulations, You can now log into Sporticket with the username and password you supplied" ) ; } } ?> </body </html> and im recieving these errors: Notice: Undefined variable: server in /home2/webusers/07/344740/public_html/sporticket/register.php on line 5 Notice: Undefined variable: _post in /home2/webusers/07/344740/public_html/sporticket/register.php on line 6 Notice: Undefined variable: _post in /home2/webusers/07/344740/public_html/sporticket/register.php on line 7 Notice: Undefined variable: _post in /home2/webusers/07/344740/public_html/sporticket/register.php on line 8 Notice: Undefined variable: _post in /home2/webusers/07/344740/public_html/sporticket/register.php on line 9 Notice: Undefined variable: form in /home2/webusers/07/344740/public_html/sporticket/register.php on line 15 any help is appreciated Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/ Share on other sites More sharing options...
Maq Posted July 16, 2009 Share Posted July 16, 2009 You have spaces between your array and the associative key. Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876714 Share on other sites More sharing options...
Adam Posted July 16, 2009 Share Posted July 16, 2009 I think the problem is that $_post does not equal $_POST. Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876718 Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 should be: $self = $_SERVER['PHP_SELF']; $first_name = $_POST['first_name']; $last_name = $_POST['last_name']; $username = $_POST['username']; $password = $_POST['password']; Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876719 Share on other sites More sharing options...
freddyw Posted July 16, 2009 Author Share Posted July 16, 2009 wow, quick responses, thankyou. undefined variables are no longer a problem. however i now have undefined index's. Notice: Undefined index: first_name in /home2/webusers/07/344740/public_html/sporticket/register.php on line 6 Notice: Undefined index: last_name in /home2/webusers/07/344740/public_html/sporticket/register.php on line 7 Notice: Undefined index: username in /home2/webusers/07/344740/public_html/sporticket/register.php on line 8 Notice: Undefined index: password in /home2/webusers/07/344740/public_html/sporticket/register.php on line 9 Notice: Undefined variable: form in /home2/webusers/07/344740/public_html/sporticket/register.php on line 15 Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876724 Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 <html> <head><title> Register </title></head> <body> <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $first_name = mysql_real_escape_string($_POST['first_name']); $last_name = mysql_real_escape_string($_POST['last_name']); $username = mysql_real_escape_string($_POST['username']); $password = mysql_real_escape_string($_POST['password']); if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ){ die("Missing some values"); } $conn = @pg_connect(~connection details hidden~); $psql = "INSERT INTO users (first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username',password('$password'))"; $result = pg_query($conn) or die ("Could not execute query"); if ( $result ) { echo "Congratulations, You can now log into Sporticket with the username and password you supplied"; } else { echo "Failed to add user"; } }else{ $form.="Please enter your details below to register with Sporticket"; $form.="<form action=\"\""; $form.=" method=\"post\"> First Name: "; $form.="<input type=\"text\" name=\"first_name\""; $form.=" value=\"$first_name\"><br>Last Name: "; $form.="<input type=\"text\" name=\"last_name\""; $form.=" value=\"$last_name\"><br>Username: "; $form.=" <input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>Password: "; $form.=" input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.=" <input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo $form; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876732 Share on other sites More sharing options...
freddyw Posted July 16, 2009 Author Share Posted July 16, 2009 Thnaks rhodesa, but im not using mysql to build my database. Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876743 Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 sorry, switch those to pg_escape_string() Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876755 Share on other sites More sharing options...
freddyw Posted July 16, 2009 Author Share Posted July 16, 2009 okay thanks. I'll give that a go and let you know the results Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876757 Share on other sites More sharing options...
freddyw Posted July 16, 2009 Author Share Posted July 16, 2009 thanks. that has cleared the errors. my code is now [<html> <head><title> Register </title></head> <body> <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $first_name = pg_escape_string($_POST['first_name']); $last_name = pg_escape_string($_POST['last_name']); $username = pg_escape_string($_POST['username']); $password = pg_escape_string($_POST['password']); if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ){ die("Missing some values"); } $conn = @pg_connect("-----------------------------------------------------"); $psql = "INSERT INTO users (first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username',password('$password'))"; $result = pg_query($conn) or die ("Could not execute query"); if ( $result ) { echo "Congratulations, You can now log into Sporticket with the username and password you supplied"; } else { echo "Failed to add user"; } }else{ $form.="Please enter your details below to register with Sporticket"; $form.="<form action=\"\""; $form.=" method=\"post\"> First Name: "; $form.="<input type=\"text\" name=\"first_name\""; $form.=" value=\"$first_name\"><br>Last Name: "; $form.="<input type=\"text\" name=\"last_name\""; $form.=" value=\"$last_name\"><br>Username: "; $form.=" <input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>Password: "; $form.=" input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.=" <input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo $form; ?> </body> </html>] im now recieving parse error: syntax error, unexpected $end on line 40 which is just the close html tag. sorry if im sounding really stupid. Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876761 Share on other sites More sharing options...
rhodesa Posted July 16, 2009 Share Posted July 16, 2009 oops: [<html> <head><title> Register </title></head> <body> <?php if($_SERVER['REQUEST_METHOD'] == 'POST'){ $first_name = pg_escape_string($_POST['first_name']); $last_name = pg_escape_string($_POST['last_name']); $username = pg_escape_string($_POST['username']); $password = pg_escape_string($_POST['password']); if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ){ die("Missing some values"); } $conn = @pg_connect("-----------------------------------------------------"); $psql = "INSERT INTO users (first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username',password('$password'))"; $result = pg_query($conn) or die ("Could not execute query"); if ( $result ) { echo "Congratulations, You can now log into Sporticket with the username and password you supplied"; } else { echo "Failed to add user"; } }else{ $form.="Please enter your details below to register with Sporticket"; $form.="<form action=\"\""; $form.=" method=\"post\"> First Name: "; $form.="<input type=\"text\" name=\"first_name\""; $form.=" value=\"$first_name\"><br>Last Name: "; $form.="<input type=\"text\" name=\"last_name\""; $form.=" value=\"$last_name\"><br>Username: "; $form.=" <input type=\"text\" name=\"username\""; $form.=" value=\"$username\"><br>Password: "; $form.=" input type=\"text\" name=\"password\""; $form.=" value=\"$password\"><br>"; $form.=" <input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo $form; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876762 Share on other sites More sharing options...
freddyw Posted July 16, 2009 Author Share Posted July 16, 2009 Thanks alot rhodesa. I kinda feel like im letting you do all the work for me. Atleast i had the basic framework to begin with, as im guessing you sometimes have post that say "i want this, how do i do it" and wait for a prgrammer to come along and code the whole thing. I am 16 and this is all new to me. I've made a few more changes and the form appears with no errors. when submitted i get this.... Warning: pg_query() [function.pg-query]: Query failed: ERROR: syntax error at or near "Resource" at character 1 in /home2/webusers/07/344740/public_html/sporticket/register2.php on line 17 Could not execute query this is now my current code <html> <head><title> Register </title></head> <body> <?php if(isset($_POST['first_name'])){ $first_name = pg_escape_string($_POST['first_name']); $last_name = pg_escape_string($_POST['last_name']); $username = pg_escape_string($_POST['username']); $password = pg_escape_string($_POST['password']); if ( ( !$first_name ) or (!$last_name) or (!$username) or (!$password) ){ die("Missing some values"); } $conn = @pg_connect(===========================================); $psql = "INSERT INTO users (first_name,last_name,username,password) VALUES ('$first_name','$last_name','$username',password('$password'))"; $result = pg_query($conn) or die ("Could not execute query"); if ( $result ) { echo "Congratulations, You can now log into Sporticket with the username and password you supplied"; } else { echo "Failed to add user"; } }else{ $form ="Please enter your details below to register with Sporticket"; $form.="<form action=\"\""; $form.=" method=\"post\"> First Name: "; $form.="<input type=\"text\" name=\"first_name\""; $form.=" <br>Last Name: "; $form.="<input type=\"text\" name=\"last_name\""; $form.=" <br>Username: "; $form.=" <input type=\"text\" name=\"username\""; $form.=" <br>Password: "; $form.=" <input type=\"text\" name=\"password\""; $form.=" <br>"; $form.=" <input type=\"submit\" value=\"Submit\">"; $form.="</form>"; echo $form; } ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876768 Share on other sites More sharing options...
rhodesa Posted July 17, 2009 Share Posted July 17, 2009 you have the wrong variable in there: $result = pg_query($psql) or die ("Could not execute query"); Quote Link to comment https://forums.phpfreaks.com/topic/166251-solved-undefined-variables-in-registration-from/#findComment-876978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.