/    Sign up×
Community /Pin to ProfileBookmark

how to fetch data from database in php and display in fields

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

[code=php]
<?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>[/code]

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmSep 14.2016 — Those error messages are probably telling you the line number too, aren't they? That would be a nice thing to pass along to those who would like to help you.

Is there any structure to this code? It appears to be a long straight line set of html and php horribly intermixed with no thought given to how it will operated. Your errors are probably in the second query statement. I'll leave it to you to figure out why that is, simply because you need to learn to visualize how a program works and how you need to set it up so that things happen in the sequence that they need to be in.

1 - stop using the MySQL_* functions. Read the manual for the warnings in Red!

2 - learn how and practice keeping the html and php code separate. Place the bulk of your html at the end and only use html in the 'php' portion when building some dynamic structure with data embedded in it. Then place a php var in the separated html code where it needs to be.

3 - read up on the heredocs feature to make it easier to code your html - it will save you from a lot of switching from html to php mode

4 - IIRC you must use and AND or OR in the where clause of your query. If the commas that you are using are acceptable, then I have learned something for today.
Copy linkTweet thisAlerts:
@NogDogSep 14.2016 — I took the liberty of formatting your code and embedding it in this forum's "php" tags.

I suspect those warnings are showing up in the code at the end that displays the form, as the variables used there won't be defined if the form has not been submitted, and thus the initial if() block will not be entered.
×

Success!

Help @Dawn1 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...