PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Fri Jan 21, 2005 9:54 am
Just messing around with PHP and i wanted a contact form which would get the values out of the database and display them in the relevent fields so if a user wants to edit the details they can while looking at their current details. Everything seems ok except it wont echo the details into the fields. Any ideas?
Code: Select all
<?php
session_start();
require('page.inc'); //page class
require_once('shopping_basket_fns.php');
$customer = $_SESSIONї'customer_id'];
$link_id = db_Connect();
$query = mysql_query("SELECT * FROM customers WHERE customer_id='".$_SESSIONї'customer_id']."'",$link_id);
$c = mysql_fetch_array($query);
echo $_SESSIONї'customer_id'];
echo $cї'postcode'];
echo $cї'first_name'];
function display_checkout_form(){
?>
<br />
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<form method="post" action="purchase.php" enctype="multipart/form-data">
<tr><th colspan="2" bgcolor="#cccccc">Details</th></tr>
<tr>
<td align="right">First Name: </td>
<td><input name="firstName" type="text" maxlength="20" value="<?php echo $cї'first_name']: '' ; ?>"></td>
</tr>
<tr>
<td align="right">Last Name: </td>
<td><input name="lastName" type="text" maxlength="20" value="<?php print $cї'surname']; ?>"></td>
</tr>
<tr>
<td align="right"Title: </td>
<td><input name="initial" type="text" maxlength="4" value="<?php echo $cї'initial']; ?>"></td>
</tr>
<tr>
<td align="right">Address Line One: </td>
<td><input name="addressLineOne" type="text" maxlength="25" value="<?php echo $cї'address_line_one']; ?>"></td>
</tr>
<tr>
<td align="right">Address Line Two: </td>
<td><input name="addressLineTwo" type="text" maxlength="25" value="<?php echo $cї'address_line_two']; ?>"></td>
</tr>
<tr>
<td align="right">City: </td>
<td><input name="city" type="text" maxlength="30" value="<?php echo $cї'city']; ?>"></td>
</tr>
<tr>
<td align="right">County: </td>
<td><input name="county" type="text" maxlength="30" value="<?php echo $cї'county']; ?>"></td>
</tr>
<tr>
<td align="right">Postcode: </td>
<td><input name="postcode" type="text" maxlength="8" value="<?php echo $cї'postcode']; ?>"></td>
</tr>
</form>
</table>
<?
}
display_checkout_form();
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 21, 2005 10:07 am
variable scope issue: you need "global $c" or better yet, pass $c into the function.
PrObLeM
Forum Contributor
Posts: 418 Joined: Sun Mar 07, 2004 2:30 pm
Location: Mesa, AZ
Contact:
Post
by PrObLeM » Fri Jan 21, 2005 1:40 pm
mmc01ms
Forum Commoner
Posts: 97 Joined: Wed Dec 01, 2004 3:33 am
Location: Nottingham, UK
Post
by mmc01ms » Fri Jan 21, 2005 3:57 pm
cheer guys doesn't work still not displaying anything except that no customers could be displayed. It is echoing the customer_id so the session values are there however don't think it is still not picking up $c
Code: Select all
<?php
session_start();
require('page.inc'); //page class
require_once('shopping_basket_fns.php');
$link_id = db_Connect();
$query = mysql_query("SELECT * FROM customers WHERE customer_id='".$_SESSIONї'customer_id']."'",$link_id);
$c = mysql_fetch_array($query);
function display_checkout_form($c){
?>
<br />
<table border="0" width="100%" cellspacing="0" cellpadding="0">
<form method="post" action="purchase.php" enctype="multipart/form-data">
<tr><th colspan="2" bgcolor="#cccccc">Details</th></tr>
<tr>
<td align="right">First Name: </td>
<td><input name="firstName" type="text" maxlength="20" value="<?php echo $cї'first_name']; ?>"></td>
</tr>
<tr>
<td align="right">Last Name: </td>
<td><input name="lastName" type="text" maxlength="20" value="<?php print $cї'surname']; ?>"></td>
</tr>
<tr>
<td align="right"Title: </td>
<td><input name="initial" type="text" maxlength="4" value="<?php echo $cї'initial']; ?>"></td>
</tr>
<tr>
<td align="right">Address Line One: </td>
<td><input name="addressLineOne" type="text" maxlength="25" value="<?php echo $cї'address_line_one']; ?>"></td>
</tr>
<tr>
<td align="right">Address Line Two: </td>
<td><input name="addressLineTwo" type="text" maxlength="25" value="<?php echo $cї'address_line_two']; ?>"></td>
</tr>
<tr>
<td align="right">City: </td>
<td><input name="city" type="text" maxlength="30" value="<?php echo $cї'city']; ?>"></td>
</tr>
<tr>
<td align="right">County: </td>
<td><input name="county" type="text" maxlength="30" value="<?php echo $cї'county']; ?>"></td>
</tr>
<tr>
<td align="right">Postcode: </td>
<td><input name="postcode" type="text" maxlength="8" value="<?php echo $cї'postcode']; ?>"></td>
</tr>
</form>
</table>
<?
}
if ($c = mysql_fetch_array($query))
{
display_checkout_form($c);
}
else
echo 'Could not retrieve customer details.<br />';
?>
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Fri Jan 21, 2005 4:35 pm
you've called fetch twice.. the first one will get the result you are looking for, the second will throw it away, as there was only 1 record returned.