Need help with php script --***********Caution Newbie***********

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Baldaris

    Need help with php script --***********Caution Newbie***********

    Hi
    I am using Xampp , Php 5.2.6 and phpedit for wiriting code.

    i am trying to add the content's from user form and then add then
    into the data base.

    It check's if submit is clicked or not , Then if any of the field's
    are empty -- It should show an error , it shold check if user name is
    there in the data base or not...if yes show error message otherwise
    insert into database.
    I am getting error if any can help me figure what i am doing wrong

    if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
    "register" ); {
    if ( $_POST['username'] != "" && $_POST['password'] != "" &&
    $_POST['first_name'] != "" && $_POST['last_name'] != "" &&
    $_POST['email'] != "" ) {
    $query = "SELECT username from user_info WHERE username = " .
    $_POST['username'] . " ;";
    $result = mysql_query( $query ) or die( mysql_error() );

    if ( mysql_num_rows != 0 ) {
    echo $_POST['username'] . "already in use";

    ?>
    <form action="registe r.php" method="POST">
    <?php
    form_display(); -- a function to display text box for
    username , password m first name,last name , city ,state

    ?>
    <?php
    } else {
    $query = "INSERT INTO user_info
    (username,passw ord,email,first _name,last_name ,city,state) " . "VALUES
    ('" . $_POST['username'] . "' ,' " . $_POST['password'] . "','" .
    $_POST['email'] . "' , ' " . $_POST['first_name'] . "',' " .
    $_POST['last_name'] . "
    ' , ' " . $_POST['city'] . "',' " . $_POST['state'] . "' );";
    $result = mysql_query( $query ) or die( mysql_error() );
    $_SESSION['user_logged'] = $_POST['username'];
    $_SESSION['user_password'] = $_POST['user_password'];
    ?>
    <p>
    Thank you, <?php echo $_POST['first_name'];
    ?for Registering<br>
    </p>
    <?php
    header( "refresh:0 ;URL=index.php" );
    die();
    }
    } else {

    ?>
    <b>The username , Password , Email ,First Name , Last name are
    required</b>
    <form action="registe r.php" method="POST">
    <?php
    form_display();
    }

    ?>
    <?php } else { -- i am getting an error in this line.

    ?>
    <p>Welcome to the Registration Page
    <form action="registe r.php" method="POST">
    <?php
    form_display();--a function to display text box for username ,
    password m first name,last name , city ,state

    ?>
    </p>
    <?php
    }

    ?>
    </body>
    </html>

    i have been trying to get it work , if anyone can tell me what i am
    doing wrong i would really appreciate it.
    Thank's in advance
    Baldaris

  • Floortje

    #2
    Re: Need help with php script --***********Caut ion Newbie********* **

    Baldaris wrote:
    Hi
    if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
    "register" ); {
    Should be
    if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) == "register" ){
    Without the ';'
    i have been trying to get it work , if anyone can tell me what i am
    doing wrong i would really appreciate it.
    Thank's in advance
    You could also try to clean up your code. Seperate the logic from the
    layout for example or create a few funtions. A verry simple one would be:

    function CheckEmptyPostF ields(array('us ername','pass', 'etc'));
    $aEmptyFields = array;

    foreach($aArray as $sField){

    if(empty($_POST[$sField])){
    array_push($aEm ptyFields,$sFie ld);
    }

    }
    return $aEmptyField;
    }


    $aEmptyFields = CheckEmptyPostF ields(array('us ername','pass', 'etc'));

    Floortje


    Comment

    • Jerry Stuckle

      #3
      Re: Need help with php script --***********Caut ion Newbie********* **

      Baldaris wrote:
      Hi
      I am using Xampp , Php 5.2.6 and phpedit for wiriting code.
      >
      i am trying to add the content's from user form and then add then
      into the data base.
      >
      It check's if submit is clicked or not , Then if any of the field's
      are empty -- It should show an error , it shold check if user name is
      there in the data base or not...if yes show error message otherwise
      insert into database.
      I am getting error if any can help me figure what i am doing wrong
      >
      if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) ==
      "register" ); {
      if ( $_POST['username'] != "" && $_POST['password'] != "" &&
      $_POST['first_name'] != "" && $_POST['last_name'] != "" &&
      $_POST['email'] != "" ) {
      $query = "SELECT username from user_info WHERE username = " .
      $_POST['username'] . " ;";
      $result = mysql_query( $query ) or die( mysql_error() );
      >
      if ( mysql_num_rows != 0 ) {
      echo $_POST['username'] . "already in use";
      >
      ?>
      <form action="registe r.php" method="POST">
      <?php
      form_display(); -- a function to display text box for
      username , password m first name,last name , city ,state
      >
      ?>
      <?php
      } else {
      $query = "INSERT INTO user_info
      (username,passw ord,email,first _name,last_name ,city,state) " . "VALUES
      ('" . $_POST['username'] . "' ,' " . $_POST['password'] . "','" .
      $_POST['email'] . "' , ' " . $_POST['first_name'] . "',' " .
      $_POST['last_name'] . "
      ' , ' " . $_POST['city'] . "',' " . $_POST['state'] . "' );";
      $result = mysql_query( $query ) or die( mysql_error() );
      $_SESSION['user_logged'] = $_POST['username'];
      $_SESSION['user_password'] = $_POST['user_password'];
      ?>
      <p>
      Thank you, <?php echo $_POST['first_name'];
      ?for Registering<br>
      </p>
      <?php
      header( "refresh:0 ;URL=index.php" );
      die();
      }
      } else {
      >
      ?>
      <b>The username , Password , Email ,First Name , Last name are
      required</b>
      <form action="registe r.php" method="POST">
      <?php
      form_display();
      }
      >
      ?>
      <?php } else { -- i am getting an error in this line.
      >
      ?>
      <p>Welcome to the Registration Page
      <form action="registe r.php" method="POST">
      <?php
      form_display();--a function to display text box for username ,
      password m first name,last name , city ,state
      >
      ?>
      </p>
      <?php
      }
      >
      ?>
      </body>
      </html>
      >
      i have been trying to get it work , if anyone can tell me what i am
      doing wrong i would really appreciate it.
      Thank's in advance
      Baldaris
      >
      >
      "I am getting error if any can help me figure what i am doing wrong" is
      not very descriptive. What error are you getting?

      One thing I do see right off hand -

      if ( ( isset( $_POST['submit'] ) && $_POST['submit'] ) == "register" ); {

      There should NOT be a semicolon at the end of this.

      --
      =============== ===
      Remove the "x" from my email address
      Jerry Stuckle
      JDS Computer Training Corp.
      jstucklex@attgl obal.net
      =============== ===

      Comment

      Working...