Katman wrote:[text]
Notice: Undefined variable: first_name in C:\wamp\www\Allinone\welcome.php on line 4
Notice: Undefined variable: username in C:\wamp\www\Allinone\welcome.php on line 8
Notice: Undefined variable: first_name in C:\wamp\www\Allinone\welcome.php on line 8
Notice: Undefined variable: last_name in C:\wamp\www\Allinone\welcome.php on line 8
Notice: Undefined variable: retype_email in C:\wamp\www\Allinone\welcome.php on line 11
Notice: Undefined variable: email in C:\wamp\www\Allinone\welcome.php on line 11
Notice: Undefined variable: password in C:\wamp\www\Allinone\welcome.php on line 14
Notice: Undefined variable: retype_password in C:\wamp\www\Allinone\welcome.php on line 17
Notice: Undefined variable: password in C:\wamp\www\Allinone\welcome.php on line 17
Notice: Undefined variable: username in C:\wamp\www\Allinone\welcome.php on line 20
Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Allinone\welcome.php on line 21
[/text]
Those are the new errors coming up. Using this code...
And those are all very easy to understand and solve. For the most part, they are pretty self explanitory. Lets dissect one:
"Notice: Undefined variable: first_name in C:\wamp\www\Allinone\welcome.php on line 4"
This means that you are referencing a variable ($first_name) in your code, but it has not been defined.
Back to the basics, to define a variable you need to set it or assign it to something.
ex: $first_name = 'Katman';
As we look over your code, we see that you are checking if $first_name is empty:
"if(!empty($first_name) && !empty($last_name) && !empty($email) && !empty($retype_email) && !empty($password) && !empty($retype_password)) {"
$first_name is not set, so you cant check to see if it is empty. If there is confusion on what the empty() function does, you should pull up the php documentation
here
if you want to check to see if a variable has been defined, you can use the isset() function, and you can read about it
here
There we go, the order in which you
must do things:
1. Declare the variable.
2. Set it to something.
3. Use it in your code.
Ok, that should address all but the last warning.
"Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\Allinone\welcome.php on line 21"
first, we need to know what parameter 1 of mysql_num_rows is. We can do that by checking the reference
here
Ok, this means, that mysql_num_rows() is expecting a resource (i.e. a sucessfull query to the database). If the mysql_query fails, it will return FALSE, which is a boolean data type. To read more about the return values of mysql_query, you should reference it
here
Perfect! Now, rather than telling you the answer, I've taught you to solve it. This will make you a much better developer!
Go back through the code that I posted and think very carefully about the comments I made to your code. Try to understand why I wrote portions of the code the way that I did, especially this part:
Code: Select all
<?php
/*
* Always check variable existence before referencing it.
* Assign default values if the reference does not exist.
*/
# Fetch $_POST Vars
$submit = isset($_POST['submit']) ? $_POST['submit'] : 0;
$first_name = isset($_POST['first_name']) ? strip_tags($_POST['first_name']) : '';
$last_name = isset($_POST['last_name']) ? strip_tags($_POST['last_name']) : '';
$email = isset($_POST['email']) ? strip_tags($_POST['email']) : '';
$retype_email = isset($_POST['retype_email']) ? strip_tags($_POST['retype_email']) : '';
$password = isset($_POST['password']) ? strip_tags($_POST['password']) : '';
$retype_password = isset($_POST['retype_password']) ? strip_tags($_POST['retype_password']) : '';
?>
Hint: $_POST['first_name'] will not be set if you access the page through a GET request. If I punch into my browser:
http://www.example.org/welcome.php and click enter... that's a GET request. All of your reference's to $_POST variable will fail, because there is no $_POST data, until you click submit on your form (which has a method of "post"). So you see, before you reference $_POST data, you should first check to make sure that it exists. Otherwise you will always be plagued by these type of Notice's and Warnings. PHP is trying to tell you what the problem is.
Good luck with your code!