Oahgneg
05-21-2008, 09:15 PM
I have a page which uses a session_user_id from
if(!isset($_SESSION['SESS_MEMBER_ID']) || (trim($_SESSION['SESS_MEMBER_ID'])=='')) {
header("location: login.php");
to get a row of record from a table to populate textboxes on a page
I understand the query to fish out the row is
mysql_query("SELECT CName, CAddress, CEmail,... FROM customer WHERE CuserID = '$_SESSION['SESS_MEMBER_ID']'")
But how do I fill the textboxes? Do I really need a different query for every textbox, or can I use $_GET/POST?
peteyb383
05-21-2008, 09:20 PM
<?php
//connection
$result = mysql_query("SELECT CName, CAddress, CEmail,... FROM customer WHERE CuserID = '$_SESSION['SESS_MEMBER_ID']'");
while($row=mysql_fetch_array($result))
{
?>
Name: <input type='text' name='cname' value='<?php echo $row['CName']; ?>'>";
Address: <input type='text' name='caddress' value='<?php echo $row['CAddress']; ?>'>";
// same for all text boxes...
<?php
}
?>
If it's only one row of data, then the while loop isn't even necessary. Just set $row=mysql_fetch_array($result) and print the rows out like I did and remove the brackets.
Oahgneg
05-21-2008, 10:07 PM
I apologise, but it seems like I made a boo-boo:o
1 of them isnt a textbox, but a dropdown list
<select name="country" id="country">
<option value="Australia">Australia</option>
<option value="Canada">Canada</option>
<option value="United States">United States</option>
so how do I fetch the Country from the $row=mysql_fetch_array($result) & make it the selected value in the dropdown list?:confused:
peteyb383
05-21-2008, 11:21 PM
You can do this:
$country = $row['country'];
<select name="country" id="country">
<option value="Australia" <?php echo ($country == 'Australia'? "selected" : "");?>>Australia</option>
<option value="Canada" <?php echo ($country == 'Canada'? "selected" : "");?>>Canada</option>
<option value="United States" <?php echo ($country == 'United States'? "selected" : "");?>>United States</option>
</select>
Might be an easier way, but it is slipping my mind
I am not a php guru but I think you may be able to do it in either the while loop or (if there is such a thing in php), a 'for' loop.
Someone else should be along soon to show the correct syntax but try something along the lines of
<select name="country" id="country">
<?php
//connection
$result = mysql_query("SELECT CName, CAddress, CEmail,... FROM customer WHERE CuserID = '$_SESSION['SESS_MEMBER_ID']'");
while($row=mysql_fetch_array($result))
{
?>
<option value="$row">$row</option>
<?php
}
?>
</select>
hth
bazz
peteyb383
05-22-2008, 12:26 AM
I am not a php guru but I think you may be able to do it in either the while loop or (if there is such a thing in php), a 'for' loop.
Someone else should be along soon to show the correct syntax but try something along the lines of
I think his/her table only has one country per member, and he/she wants it selected within a select group.
So the whole list of countries would be there, and their specific one would be selected with my code. Yours would simply set it as an option.
1 of them isnt a textbox, but a dropdown list
<select name="country" id="country">
<option value="Australia">Australia</option>
<option value="Canada">Canada</option>
<option value="United States">United States</option>
OK, I just read this and thought my response might be of help.:eek:
bazz
syosoft
05-22-2008, 09:54 AM
For much cleaner forms, you might want to rip out the write_form_variables() function here http://www.codingforums.com/showthread.php?t=36142&page=2#post689694