how to fetch data from database in...

User 2850066 Photo


Guest
1 post

Can anyone please tell me what am i doing wrong in this code , i am trying to fill in the textboxes from the mysql database before updating it but it is giving me error : Notice: Undefined variable: password , Notice: Undefined variable: email , Notice: Undefined variable: phone

<?php

include "sessioncheck.php";
?>


<?php
if(isset($_POST["update"])){
//echo'<pre>';print_r($_POST);exit();

//$user_name =$_POST["name"];
$email = $_POST["email"];
$password = $_POST["password"];
$phone = $_POST["tel"];
$id =$_POST["id"];

//***** DB Connection *****//
$hostname = 'localhost';
$dbname = 'shopping';
$username = 'root';

mysql_connect('localhost', 'root', '') or DIE('Connection Not FOUND..!');
mysql_select_db('shopping') or DIE('Database name is not available!');
//***** DB Connection END*****//

$query = "SELECT id, email , password, status FROM users WHERE id='$id' , email='$email' , password='$password' , status='$phone'";
//echo $query;exit();
$result = mysql_query($query);

$rows = mysql_num_rows($result);
// //echo'USER EXIST';
if ($rows==1){
while($rs = mysql_fetch_array($result)){
$id = $rs["id"];
$email = $rs["email"];
$phone =$rs["status"];
$password=$rs["password"];
//echo $id.' Email: '.$uemail;exit();

}
}


$query = "UPDATE users SET id = '$id' , email='$email' , password = '$password' , status= '$phone'";
//echo $query;exit();

$result = mysql_query($query);
if($result==false){
die(mysql_error());
}
header("Location: Grid.php");
return mysql_affected_rows();

exit();

}
?>

<!DOCTYPE html>
<html>
<head>
<title>Edit Data</title>
</head>
<body>
<div class="form">
<h2>Edit Data</h2>
<form method="post" action="update1.php">
<input type="hidden" value="<?php echo $id;?>" name="id">
<!-- <input type="text" name="name" placeholder="Username"/> -->
<input type="password" name="password" value="<?php echo $password;?>" placeholder="Password"/>
<input type="email" name="email" value="<?php echo $email;?>" placeholder="Email Address"/>
<input type="tel" name="tel" value="<?php echo $phone;?>" placeholder="Phone Number"/>
<input type="submit" name = "update" value="Update">
</form>
</div>
</body>
</html>
User 187934 Photo


Senior Advisor
20,181 posts

Your probably not referencing your sessioncheck.php correctly. Check it's location.
I can't hear what I'm looking at.
It's easy to overlook something you're not looking for.

This is a site I built for my work.(RSD)
http://esmansgreenhouse.com
This is a site I built for use in my job.(HTML Editor)
https://pestlogbook.com
This is my personal site used for testing and as an easy way to share photos.(RLM imported to RSD)
https://ericrohloff.com

Have something to add? We’d love to hear it!
You must have an account to participate. Please Sign In Here, then join the conversation.