/    Sign up×
Community /Pin to ProfileBookmark

No Errors just no results! form populated by a query for editing

OK, Lemme try to explain this. I have been looking at this ol’ PHP book I have had for some time. One of my teachers gave it to me. Now I am not blaming it on the book but I just can’t seem to figure out what the heck is going on with this form.

This form displays a user record with the fields populated with the current data being in each text box for display and editing. Would be a useful little bugger if I could get the fields to populate. I am not getting an php error. nor a mysql error either. I asume that it gets the query but I am trying to display it wrong or I messed up somewhere.

If you can help that would be nice. By the way I know that the previous form is posting the right information because when you look at the source of the parsed page the number $id is there in the hidden form field. The problem lies in this page somewhere.

Thanks in advance!

[code=php]
<?php
if (!$_POST[id]) {
header( “Location:http://www.eriescene.com/xml/turbodbadmin_0.1.2/users.php”);
exit;

} else {
session_start();
}

if ($_SESSION[valid] != “yes”) {
header( “Location:http://www.eriescene.com/xml/turbodbadmin_0.1.2/users.php”);
exit;
}

//Connect To Database

$db_name = “markbad_markbadsql”;
$table_name = “user_data”;
$connection = mysql_connect(“localhost”, “markbad_drpl1”, “**SECURITY**”)
or die(mysql_error());
$db = mysql_select_db($db_name, $connection)
or die (‘I cannot connect to the database because: ‘ . mysql_error());
$sql = “SELECT f_name, l_name, password, adddress1, address2, city_state, postcode, country, prim_tel, sec_tel, email, company, birthday FROM $table_name WHERE id = ‘$_POST[$id]’ “;
//create result variable
$result = mysql_query($sql,$connection) or die(mysql_error());
//while loop to gather variables from result.
while ($row = mysql_fetch_array($result)) {
$f_name = $row[‘f_name’];
$l_name = $row[‘l_name’];
$password = $row[‘password’];
$adddress1 = $row[‘adddress1’];
$address2 = $row[‘address2’];
$city_state = $row[‘city_state’];
$postcode = $row[‘postcode’];
$country = $row[‘country’];
$prim_tel = $row[‘prim_tel’];
$sec_tel = $row[‘sec_tel’];
$email = $row[’email’];
$company = $row[‘company’];
$birthday = $row[‘ birthday’];
}
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<title>Erie Scene Contact Managment System : Add Contact</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />
<link href=”http://www.eriescene.com/layout.css” rel=”stylesheet” type=”text/css” />
</head>

<body>

<table class=”align” width=”85%” cellspacing=”3″ cellpadding=”5″>
<form method=”post” action=”do_modcontact.php”>
<tr>
<th>Name &amp; Address Information</th>
<th>Other contact / Personal Information</th>
</tr>
<tr>
<td valign=”top”>
<form method=”post” action=”do_modcontact.php”>
<label>First Name<br />
</label>
<input type=”hidden” name=”id” value=”<? echo “$_POST[id]”; ?>” />
<input type=”text” name=”f_name” size=”20″ value=”<? echo “$f_name”; ?>” /><br />
<label>Last Name<br />
</label>
<input type=”text” name=”l_name” size=”20″ value=”<? echo “$l_name”; ?>” /><br />
<label>password<br />
</label>
<input type=”password” name=”password” size=”20″ value=”<? echo “$password”; ?>” /><br />
<label>Address Line 1</label>
<br />
<input type=”text” name=”adddress1″ size=”20″ value=”<? echo “$adddress1″; ?>” /><br />
<label>Address Line 2</label>
<br />
<input type=”text” name=”address2″ size=”20″ value=”<? echo “$address2″; ?>” /><br />
<label>City and State</label>
<br />
<input type=”text” name=”city_state” size=”20″ value=”<? echo “$city_state”; ?>” /><br />
<label>Postal Code<br />
</label>
<input type=”text” name=”postcode” size=”20″ value=”<? echo “$postcode”; ?>” /><br />
<label>Country<br />
</label>
<input type=”text” name=”country” size=”20″ value=”<? echo “$country”; ?>” /><br /> </td>
<td valign=”top”>
<label>Primary Telephone Number</label>
<br />
<input type=”text” name=”prim_tel” size=”20″ value=”<? echo “$prim_tel”; ?>” /><br />
<label>Secondary Telephone Number<br />
</label>
<input type=”text” name=”sec_tel” size=”20″ value=”<? echo “$sec_tel”; ?>” /><br />
<label>E-Mail Address<br />
</label>
<input type=”text” name=”email” size=”20″ value=”<? echo “$email”; ?>” /><br />
<label>Birth date (YYYY-MM-DD)<br />
</label>
<input type=”text” name=”birthday” size=”20″ value=”<? echo “$birthday”; ?>” /><br />
<label>Company<br />
</label>
<input type=”text” name=”company” size=”20″ value=”<? echo “$company”; ?>” /><br />
</td>
</tr>
<tr>
<td colspan=”2″>
<br />
<div align=”center”>
<input type=”submit” name=”submit” value=”Update Contact!” />
</form>
<a href=”users.php”>Back To User Menu</a>
</div>
</td>
</tr>
</table>

</body>
</html>

[/code]

Did I mention that the values=”” in the html of the form are empty? so it is right here in my syntax. but I can’t figure it out everything is paralel to my book

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@chazzyJan 11.2006 — first errors i see are with your post and session variables.

$_SESSION[valid] != "yes"

needs to use single quotes around valid and

and if your field on the form page is called "id" then you reference it in the post array as

$_
POST['id'] not $_POST[$id]
Copy linkTweet thisAlerts:
@Markbad311authorJan 11.2006 — $_POST['id'] not $_POST[$id][/QUOTE]

You were right the syntax in the array was wrong and that is definetly why it wasn't working. Yet, the syntax you suggested is not right either. at least not for my version of mysql. I had to enter it as "$_POST[id]". Other wya gave me an error like this

Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/markbad/public_html/xml/turbodbadmin_0.1.2/show_modcontact.php on line 23[/QUOTE]


Thank you you did point the way! The session valid thing works thats what it says in the book. In the book the code is like I typed it too.
Copy linkTweet thisAlerts:
@chazzyJan 11.2006 — post just your query if you're having issues with it. $_POST[id] should not work. ideally you want something like this:

[code=php]
$id = $_POST['id']; //assuming your field is named id on your form
$query = "SELECT (whatever columns) FROM (your table) WHERE id=".$id;
//note that since id is presumably an int, you don't need the single quotes.
[/code]
Copy linkTweet thisAlerts:
@NogDogJan 12.2006 — If you are embedding an array element within a double-quoted string, you can use the "complex" notation with curly braces to make sure the PHP parser knows where your array element variable begins and ends:
[code=php]
echo "This is a string with an {$array['element']} in 'complex' notation using curly braces.";
[/code]
Copy linkTweet thisAlerts:
@chickenlandJan 12.2006 — [code=php]$sql = "SELECT f_name, l_name, password, adddress1, address2, city_state, postcode, country, prim_tel, sec_tel, email, company, birthday FROM ".$table_name." WHERE id = '".$_POST['$id']."'"; [/code]

should work fine...
×

Success!

Help @Markbad311 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...