Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

i have undefined index error .

Codes here !

Moderators: macek, egami, gesf

i have undefined index error .

Postby sharmadeepu » Thu Jul 25, 2013 10:26 pm

here i am posting my code ...
i would like to know the solution please.....
Index.php
<?
//login script
if(isset($_POST["user_login"]) && isset($_POST["password_login"]))
{
$user_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST['user_login']);//filter the numbers and letters
$password_login = preg_replace('#[^A-Za-z0-9]#i', '', $_POST['password_login']); //filter everything numbers and letters
$sql = mysql_query("select id FROM users WHERE username='$user_login' AND password='$password_login' LIMIT 1");//query the person
//check for their existence
$userCount = mysql_num_rows($sql);//count the number of rows returned
if($userCount == 1)
{
while($row = mysql_fetch_array($sql))
{
$id = $row['id'];
}
$_SESSION['id'] = $id;
$_SESSION['user_login']=$user_login;
$_SESSION['password_login']=$password_login;
header("location: index1.php");
exit();
}
else
{
echo 'your entered information is incorrect, please try again';
exit();
}
}
?>

Header.inc.php
//start the session
session_start();
//checks whether the user is logged in or not
$user = $_SESSION['Username'];
if (!isset($_SESSION['user_login']))
{
header("location: index1.php");
exit();
}
else
{
header("location: Home.php");
}

Home.php
<?php
session_start();
$user = $_SESSION['user_login'];
//if the user is not logging in
if (!isset($_SESSION['user_login']))
{
header("location: index1.php");
exit();
}
else{
//if the user is logged in
echo "Hi, $user, your logged in..<br/> welcome to what is soon to be, your newsfeed";
}
?>


Database connection code:mysql.connect.php
<?php function db_connect($whitebook)
{
$host_name = "localhost:3306";
$user_name = "root"; $password = "jaquor";
$db_link = mysql_connect($host_name,
$user_name, $password)
or die("Could not connect to $host_name");
mysql_select_db($whitebook)
or die("Could not select database $db_name");
return $db_link;
} ?>
sharmadeepu
New php-forum User
New php-forum User
 
Posts: 1
Joined: Thu Jul 25, 2013 10:20 pm

Re: i have undefined index error .

Postby johnj » Fri Jul 26, 2013 8:35 am

undefined index has been answered a hundred times in this forum.
johnj
php-forum Super User
php-forum Super User
 
Posts: 1805
Joined: Thu Mar 10, 2011 5:07 pm


Return to mySQL & php coding

Who is online

Users browsing this forum: No registered users and 2 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron