Jump to content

Recommended Posts

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  :D

should be:

                $self =         $_SERVER['PHP_SELF'];
                $first_name =   $_POST['first_name'];
                $last_name =    $_POST['last_name'];
                $username =   $_POST['username'];
                $password =    $_POST['password'];

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

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

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.

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>

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>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.