Jump to content

Insert function not working on add_user()


alvin567

Recommended Posts

<?php

    //javascript-coder.com

    if(!empty($_REQUEST['adduser'])){

    if($_POST["email"] && $_POST["password"] && $_POST["cpassword"]){

if($_POST["password"] == $_POST["cpassword"]){

$email = $_POST['email'];

$password = $_POST['password'];

if(validate_user($email,$password) == 1){

echo 'User Already Exist in the system';

}else{

add_user($email,$password);

echo 'User successfully added into the system';

}

}else{

echo 'Password doesn\'t match try again';

}

}

else{

echo 'Please ensure all values are filled up';

}

    }

    //w3schools,refer

//airline system from netbeans

//betterphp help

function validate_user($email,$password){

//if the password is correct the move on todo others

$result = mysql_query("Select * FROM user WHERE email = '$email'");//learn from betterphp

$row = mysql_fetch_array($result);

if ($row['email'] <> "") {//check if email already existed in the database

return true;//email exist in the database

}else{

return false;//email doesn't exist in the database

} }

function add_user($email,$password){

//password to be hashed in the database because the database it,

$sql = "Insert into user ('email','password') VALUES ('aaaa', 'aaaa')";

mysql_query($sql);

$user_id = mysql_insert_id();//return the user id by the previously generated columns

return $user_id;

    }

?>

 

Link to comment
Share on other sites

With 130+ posts, you should really know by now to do the following things:

 

1)  Wrap your code in [ php ] and [/ php ] tags so it is properly displayed.  We even have a button for it now.  Highlight your code and click the "PHP" button in the toolbar.

 

2)  Use error reporting and error handling, as well as the mysql_error() function to figure out errors on your own.  Experts like thorpe don't just stare at non-functional code hoping they notice the error.  The fact that thorpe was able to do so in this case doesn't mean that's how we normally debug something.  Echo your own error, figure out what it means.

 

3)  Form better questions.  Or, in the case of this thread, form a sentence.  You did nothing but paste a large block of unformatted code to a group of strangers.

 

4)  Google the answers you receive.  Thorpe's answer was perfect.  If you don't know what a mysql identifier is, find out.  If you had written a question, perhaps the answer you received would have been more complete.

Link to comment
Share on other sites

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.