WeLoveCSS Logo
Home Profile Members Search Rules Help New Posts



WeLoveCSS > PROGRAMMING LANGUAGES > Scripting and Server Side > Undefined variable error

Reply
  Thread Tools Display Modes
Old 12th October 15, 07:36 PM   #1
software_ss
WLC Member
 
Join Date: May 2015
Posts: 6
Default Undefined variable error

Dear,
I am trying to study code and learn. Problem is login system showing error

Notice: Undefined variable: username in C:\wamp\www\sumon\login.php on line 63

but it allows login.

code for index.php is given bellow:

<form action="login.php" method="post">
<Center>
<table border=0 CellPadding=5 border="black" background="AquaLoop Wallpaper Bk.jpg" WIDTH=10% text="blue" ><center>
<tr><td>
<table border=0 CellPadding=5 border="black" background="3438593196_e91fcc6316.jpg" WIDTH=10% text="blue" >

<tr font face ="Britannic Bold" border="0" color="Red" size="500" ALIGN="CENTER"> <TH COLSPAN=4> <fieldset> <p font size=0>LogIn Form</fieldset></TH>
<th bgcolor="" colspan=2 align="right"><img src="indicator.GIF" width="100" height="100" border="0"></th></TR>


<div align="center" style="color:#000000">
<tr>
<td> Username : <input type="text" name="username" size="30"></td></tr>
<tr>
<td>
Password :<input type="password" name="password" size="30"></td></tr>
<tr><td colspan="2">
<input name="submit" type="submit" value="Log In"> <a href="register.html"><b>Sign Up? </a></td> </tr> </div>
<!--<td&nbsp;&nbsp&nbsp;<a href="logInForm.php">Click here to Log-Out</a>&nbsp;&nbsp;&bull;&nbsp;&nbsp; </td>-->
</td></tr>

</form>

now code for login.php is given bellow:

<?php
ob_start();

include("config.php");

// connect to the mysql server
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Could not connect to mysql because ".mysql_error());

// select the database
mysql_select_db($database)
or die ("Could not select database because ".mysql_error());

$match = "select id from $table where username = '".$_POST['username']."'
and password = '".$_POST['password']."';";

$qry = mysql_query($match)
or die ("Could not match data because ".mysql_error());
$num_rows = mysql_num_rows($qry);

if ($num_rows <= 0) {


echo '<span style="color:#000000;text-align:center;"><b>Sorry, there is no username with the specified password.<br></span>';
echo "<a href=index.html><b>Try again</a>";
exit;
} else {
$username;
setcookie("loggedin", "TRUE", time()+(3600 * 24));
setcookie("mysite_username", "$username");


echo '<span style="color:#000000;text-align:center;"><b>You are now logged in!<br></span>';
echo '<p style="color: red; text-align: center">
<a href=home.php><b>continue...</a>
</p>';




}
ob_end_flush();
?>


Where is the problem? I found on google that variable should be declared, how to solve? where to declare in this case?
software_ss is offline   Reply With Quote
Old 12th October 15, 08:00 PM   #2
software_ss
WLC Member
 
Join Date: May 2015
Posts: 6
Default Re: Undefined variable error

Adding $username = $_POST['username']; just before line 63 -setcookie("mysite_username", "$username");
solved the error, but is this ok?
software_ss is offline   Reply With Quote
Reply


Thread Tools
Display Modes
Linear Mode Linear Mode

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:04 PM.



Home | Advertise | Contact Us | Top
Home | Advertise | Contact Us | Top

Copyrightę 2006 WeLoveCSS.com. All Rights Reserved.
Powered by vBulletin Version 3.8.4 Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.