SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    php database error

    hello friends i am new in php ,want to add form with database ,but a error appeared ,


    ( ! ) Notice: Undefined variable: name in C:\wamp\www\your_mail\register.php on line 26 Call Stack # Time Memory Function Location 1 0.0521 142664 {main}( ) ..\register.php:0
    ( ! ) Notice: Undefined variable: email in C:\wamp\www\your_mail\register.php on line 26 Call Stack # Time Memory Function Location 1 0.0521 142664 {main}( ) ..\register.php:0

    this is my code can anyone help me.


    PHP Code:
    if(isset($_POST['name'])){
    $name $_POST['name'];
    $email $_POST['email'];
    $password $_POST['password'];
    }
    $query "INSERT INTO users
      (id,name,email,password,added_date,modified_date,status)
    VALUES
      ('','
    $name','$email','$password','NOW()','','0') "
    Last edited by cpradio; Nov 11, 2013 at 11:02.

  2. #2
    SitePoint Addict bronze trophy
    Join Date
    Sep 2005
    Posts
    323
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Your SQL query isn't inside your if statement, so if those $name and $email variables aren't set, PHP outputs a notice error saying that it can't find them. If you put the SQL statement inside the if statement, it should solve your problem.

  3. #3
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanx Patche , i got it,but can you tell me why and where we use isset[ ] , i am confused with it.

  4. #4
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    111
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by udaikr View Post
    Thanx Patche , i got it,but can you tell me why and where we use isset[ ] , i am confused with it.
    isset() is a predicate language construct; it returns TRUE if the variable exists in memory, or FALSE if it does not. For a variable to exist, it must not have a NULL value. This means that anything but a NULL value (including empty values, '') will result in isset() returning TRUE, causing the conditions within your IF statement to parse.

    In your scenario above, you were checking that the element key, name, in the $_POST super global variable was set (i.e. PHP had loaded the contents of the HTTP POST data into $_POST for you to manipulate). It is important that you perform checks to ensure variables are set before trying to manipulate them (using isset()) to prevent notices and bugs from cropping up within your application.

  5. #5
    SitePoint Member
    Join Date
    Nov 2013
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks alot for this information.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •