Page 1 of 1

Echo Values Into Fields for Editing Problem?

Posted: Fri Jan 21, 2005 9:54 am
by mmc01ms
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&#1111;'customer_id'];
	
	$link_id = db_Connect();
	
	$query = mysql_query("SELECT * FROM customers WHERE customer_id='".$_SESSION&#1111;'customer_id']."'",$link_id); 
	$c = mysql_fetch_array($query);
	
		
	
	echo $_SESSION&#1111;'customer_id'];
	echo $c&#1111;'postcode'];
	echo $c&#1111;'first_name'];
	
	function display_checkout_form()&#123;
?>

		<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&#1111;'first_name']: '' ; ?>"></td>
				</tr>
				<tr>
					<td align="right">Last Name: </td>
					<td><input name="lastName" type="text" maxlength="20" value="<?php print $c&#1111;'surname']; ?>"></td>
				</tr>
				<tr>
					<td align="right"Title: </td>
						<td><input name="initial" type="text" maxlength="4" value="<?php echo $c&#1111;'initial']; ?>"></td>
					</tr>
					<tr>
						<td align="right">Address Line One: </td>
						<td><input name="addressLineOne" type="text" maxlength="25" value="<?php echo $c&#1111;'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&#1111;'address_line_two']; ?>"></td>
					</tr>
					<tr>
						<td align="right">City:  </td>
						<td><input name="city" type="text" maxlength="30" value="<?php echo $c&#1111;'city']; ?>"></td>
					</tr>
					<tr>
						<td align="right">County:  </td>
						<td><input name="county" type="text" maxlength="30" value="<?php echo $c&#1111;'county']; ?>"></td>
					</tr>
					<tr>
						<td align="right">Postcode:  </td>
						<td><input name="postcode" type="text" maxlength="8" value="<?php echo $c&#1111;'postcode']; ?>"></td>
					</tr>
				</form>
			</table>

	<?
	&#125;
	
	display_checkout_form();
	?>

Posted: Fri Jan 21, 2005 10:07 am
by feyd
variable scope issue: you need "global $c" or better yet, pass $c into the function.

Posted: Fri Jan 21, 2005 1:40 pm
by PrObLeM

Code: Select all

display_checkout_form($c);

Posted: Fri Jan 21, 2005 3:57 pm
by mmc01ms
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&#1111;'customer_id']."'",$link_id); 
	$c = mysql_fetch_array($query);
	
		
	function display_checkout_form($c)&#123;	
		
		
		
?>

<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&#1111;'first_name']; ?>"></td>
		</tr>
		<tr>
			<td align="right">Last Name: </td>
			<td><input name="lastName" type="text" maxlength="20" value="<?php print $c&#1111;'surname']; ?>"></td>
		</tr>
		<tr>
			<td align="right"Title: </td>
				<td><input name="initial" type="text" maxlength="4" value="<?php echo $c&#1111;'initial']; ?>"></td>
			</tr>
			<tr>
				<td align="right">Address Line One: </td>
				<td><input name="addressLineOne" type="text" maxlength="25" value="<?php echo $c&#1111;'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&#1111;'address_line_two']; ?>"></td>
			</tr>
			<tr>
				<td align="right">City:  </td>
				<td><input name="city" type="text" maxlength="30" value="<?php echo $c&#1111;'city']; ?>"></td>
			</tr>
			<tr>
				<td align="right">County:  </td>
				<td><input name="county" type="text" maxlength="30" value="<?php echo $c&#1111;'county']; ?>"></td>
			</tr>
			<tr>
				<td align="right">Postcode:  </td>
				<td><input name="postcode" type="text" maxlength="8" value="<?php echo $c&#1111;'postcode']; ?>"></td>
			</tr>
		</form>
	</table>
	
	<?
	&#125;
	
	if ($c = mysql_fetch_array($query))
	&#123;
		display_checkout_form($c);
	&#125;
	else
		echo 'Could not retrieve customer details.<br />';
	
	
	
	?>

Posted: Fri Jan 21, 2005 4:35 pm
by feyd
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.