Welcome! Log In Create A New Profile

Advanced

) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21

Posted by Imtiyaaz 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 26, 2011 11:51PM
Hi

I started with the registration page and followed the guide in the tutorial letter,however Im getting the above error when submitting the form. Below is my code so far, please assist...

<?php
include ('connect.php'winking smiley;


$Submit = $_POST['Submit'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$username = $_POST['username'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];

if($Submit=='Yes'winking smiley
$result = mysql_query("SELECT * FROM user WHERE username='$username'"winking smiley;
$num_rows = mysql_num_rows($result);
if($num_rows > 0){
echo "The user $username already exists!";
}
?>
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 28, 2011 06:13PM
Please use the formatted code button when posting code.

Notices are not errors but a guide by PHP that your code could be written better. You can turn notices off in several ways - just google for "turn notices off php"

"Although PHP does not require variable declaration, it does recommend it in order to avoid some security vulnerabilities or bugs where one would forget to give a value to a variable that he will use later in the script" So just use the isset function before using the variable - in this case
Language: PHP
if(isset($Submit==';Yes';)) { //check if is set $result = mysql.....
.And use brackets for ifs.... just good programming.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 28, 2011 09:23PM
Thanks. Where do you put the php code in the HTML document? At the top or in the form section or do I need a separate page just for the php code?
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 28, 2011 09:57PM
This is my code so far for the register.php

Everything seems fine to me but the form is not doing anything. I have and existing username in my database but if I put in that same username in the form it does not display the message user already exists. Also if I insert a a different user it just clears the form and nothing gets inserted into the database. Please assist....

Language: PHP
<?php include (';connect.php';); error_reporting(0);   Edited: You cannot post ALL your code here....
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 29, 2011 06:45AM
Imtiyaaz Wrote:
-------------------------------------------------------
> Thanks. Where do you put the php code in the HTML
> document? At the top or in the form section or do
> I need a separate page just for the php code?

Read the tut letter.
The form data is submitted to the same page, using an if/else statement that "divides the page into two sections – one presenting the login form and the other handling the form input.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 29, 2011 03:25PM
Hi Mac, did you have a look at my code?Can you tell me why my form is not doing anything? My php looks right to me but it does not insert a new user and also it does not check the database for existing users....please help
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 29, 2011 03:36PM
I have read the tut letter many times over but Im still a bit confused about this "using an if/else statement that "divides the page into two sections – one presenting the login form and the other handling the form input."

Is my php in the right place or should certain pats of it be in the form, or must the whole document be in between the php tags, im really confused and your assistance will be appreciated...

I've gone through many tutorials online but I still seem to be stuckconfused smiley
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 29, 2011 05:39PM
I deleted your code but the logic is - an you may have had it correctly

Language: PHP
if(isset($Submit=="yes';)) { // handle the form input i.e. insert into database - bit check is the user does not already exist - which requires another if/else statement here } else { //show the registration form }

So it seems you are on the right track when I look at your initial code top of the thread.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 29, 2011 07:05PM
Is my php in the right place? Also I changed my if($Submit=='Yes'winking smiley to if(isset($Submit=='Yes'winking smiley) then I get the following error "( ! ) Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or 'winking smiley' in C:\wamp\www\register.php on line 12"

It seems when I submit my form then nothing happens, I've even tried taking out most of the code and just leave the section that checks if the user is in the database but the form still appears to be doing nothing, when I click the submit button, the text I entered just disappears and thats it....Do I need to position the if statement that checks for a user by the username section in the form or is the code suppose to be at the beginning of the HTML document like I have it now?
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 29, 2011 08:49PM
ok managed to get most of it sorted...I at least get some activity now when I submit the formsmileys with beer

However, how do align the text in the echo statements so that it prints to the center of the HTML document?
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
August 30, 2011 06:57AM
That is an html issue - not a PHP issue. You should know this by now from last year smiling smiley
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
September 12, 2011 07:58PM
I am getting the exact same error as you did. How did you resolve the error?
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
September 13, 2011 06:43AM
42097207 Wrote:
-------------------------------------------------------
> I am getting the exact same error as you did. How
> did you resolve the error?

The undefined error? The solution is further up.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
September 19, 2011 03:08PM
HOW DOU GET THE PARSE_ERROR SORTED AM EXPERIENCING THE SAME PROBLEMconfused smiley?
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
September 19, 2011 03:29PM
HTML you should know from last year. That is what the question was on. For the engineering students that did not do HTML there is a link to quick fix tutorials. Peruse the posts and all will become clearer.
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
September 20, 2011 02:35PM
The above holds true for "undefined index notices" as well
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 01:51AM
i have write the script required in the tut 102 but after some time i try to check my work, that is were i get a problem. when i run any page on the local server, i get this error message:
"error in registrationYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'd41d8cd98f00b204e9800998ecf8427e'winking smiley' at line 1". i have check for the manual but can find anything helpful. please can some one help me?smile
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 06:19AM
You have an error in your sql statement, on the line that is shows. In addition, you should have created a new topic with this error (like "error in sql syntax - check the manaul..."winking smiley since it does not fit under here.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 12:14PM
thanks Mr Mac but the more more i try to correct it the more confuse i become. the next difficulties am facing now is when i try to register a user i get the error message "HTTP 404 not found...". am really frustrated
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 12:32PM
You need to WORK through the home and learn tutorials, and the corresponding chapters, becasue that shows you how to write sql queries correctly.
I cannot give you tips and support for every problem you have... then I can just about write your app for you.
HTTP 404 not found means the page can not be found so you probably spelled it incorrectly or the path to it is incorrect. This is not a PHP problem.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 12:59PM
thanks Mr mac, i am checking on the path now
smilesmile
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 01:45PM
hi Mr Mac, i got another problem with my list, when i try to list my table i get this error message "Deprecated: Function mysql_list_tables() is deprecated in C:\wamp\www\list.php on line 10". i don't know any thing about this error
avatar
Mac
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 05, 2011 02:28PM
PLEASE start a new thread because this error is unrelated to this topic.....

It will help you to Google for such errors. deprecated means you cannot use mysql_list_tables any more.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 11, 2011 03:10PM
Language: PHP
//########################################################################### //GET THE USER REGISTRATION INFO AND CHECK FOR SQL DANGEROUS CHARACTERS //###########################################################################   $user_full_names = $_POST[';fullname';]; $user_surname = $_POST[';surname';]; $use_names = $_POST[';username';]; $user_password = $_POST[';password';]; $confirm_password = $_POST[';confirmpassword';];   $use_name= htmlspecialchars($use_name); $user_password = htmlspecialchars($user_password);   //########################################################################### // CHECK THE CORRECT LENGTH OF USER INPUT TO UNABLE MALICIOUS USERS TO // GET errorMessages THAT WILL GIVE THEM ACCESS TO SEND DATA TO THE DATABASE //###########################################################################   //########################################################################## // Write to the database IF $errorMessage IS BLANK ELSE DISPLAY ERROR //##########################################################################   if ($errorMessage == "") {   //###################################################################### //###############Connection to the database#############################   $user_name = "root"; $pass_word = ""; $database = "belan"; $server = "127.0.0.1";   $db_handle = mysql_connect($server, $user_name, $pass_word); $db_found = mysql_select_db($database, $db_handle);     if ($db_found) {   $user__names = quote_smart($user_names, $db_handle); $user_password = quote_smart($user_password, $db_handle);     //==================================================================== // CHECK THAT THE USERNAME IS NOT TAKEN //====================================================================   $SQL = "SELECT * FROM user WHERE username = $user_names"; $result = mysql_query($SQL); $num_rows = mysql_num_rows($result);   if ($num_rows > 0) { $errorMessage = "Username already taken"; }   else {   $SQL = "INSERT INTO user (name,surname,username,password) VALUES ($user_full_name,$user_surname,$user_names, md5($user_password))";   $result = mysql_query($SQL);   mysql_close($db_handle);

Hi, Mac sleepless sleepless nite are not getting these scripts inserted into user database and submiting the form takes me to the login page the same problem with my second table form they appear ok but I can't seem to write into the database. Please assist I have tried revising repeatedly, no break through.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 11, 2011 06:32PM
try changing this $SQL = "INSERT INTO user (name,surname,username,password) VALUES ($user_full_name,$user_surname,$user_names, md5($user_password))";


to

$SQL = "INSERT INTO user VALUES (' ', '$user_full_name', '$user_surname', '$user_names', '$user_password'winking smiley ";

*on top you typed $use_names=$_POST['username']; * at the insert statement you typed $user_names


Also remember that MD5 requires that your database password column be more than 6 characters long. (read php.net)

TIP1: your other mistake is at variables $use_names and $user_names //note the " r " is missing on $use_names

Tip 2: first try a simple statement to insert into database before using numrows and so forth.

Tip3: follow instructions from Tut 102: line 1 = session_start();, line 2 = include('connect.php'winking smiley;

Question: Are you going to type the mysql_connect(); function in all the 7 pages?.
Re: ) Notice: Undefined variable: result in C:\wamp\www\php.php on line 21
October 13, 2011 10:41AM
Thanks buddy you hv been a genius on your advise I make some changes following your INSERT TIP and both my tables are accepting data from my forms, thou I posted on the unrelated topic still you replied, thanks once more.
Sorry, only registered users may post in this forum.

Click here to login