Hi i am new to php, can any of u help me,
I am storing details such as name , address, email id, phone no, fax no and all. and i am creating edit form to edit those details , i am returns almost all values except address and select location value, can any one tell me how to get those values,
Below is my code

$qry = "select * from tbl_customer where comp_id='$id'";
				$rst = mysql_query($qry,$con);
				if($rst){
					$row = mysql_fetch_array($rst);
					$customername = $row['comp_name'];
					$customeradd  = $row['comp_add'];
					$customerpnum  = $row['comp_pnum'];
					$customeremail = $row['comp_email'];
					$customerfnum  = $row['comp_fnum'];
					$customerloc  = $row['select_loc'];	

<td width="80">Username&nbsp;*&nbsp;</td><td><input type="text" name="comp_name" class="textbox"  size="30" maxlength="50" title="Enter your name" value="<?php echo $customername; ?>"/></td>  
 
 <td width="80">Address&nbsp;*&nbsp;</td><td><TEXTAREA ROWS="6" COLS="23" name="comp_add"  title="Enter Your Address" value="<?php echo $customeradd; ?>"></textarea></td>  

 <td width="80">Phone No&nbsp;*&nbsp;</td><td><input type="text" name="comp_pnum" class="textbox"  size="30" maxlength="20" title="Enter Valid Phone No" value="<?php echo $customerpnum ; ?>" /></td>  
 <tr>  
 <td>Location&nbsp;*&nbsp;</td>  
 <td><?php
/*$link = mysql_connect('localhost', 'root', ''); 
if (!$link) {
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("b2bassociates");*/
include 'dbcon.php';

$qry = "select * from tbl_location order by loc_name";
$result = mysql_query($qry,$con);

?>
<select name="sel_loc" title="Select Location"  value="<?php echo $customerloc; ?>" >
<option value="">----Select Location----</option>
<?php 
while($row=mysql_fetch_array($result))
{ 
?>
   <option value="<?php echo $row['loc_code']; ?>" 
   >
   <?php echo $row['loc_name']; ?>
   </option>
<?php 
} 
?>
</select>
 </td>  
 </tr>

HERE I RETURN ALL THE DETAILS FROM DATABASE EXCEPT THE ADDRESS AND SELECT LOCATION, CAN ANY ONE TELL ME , hOW IT IS SOLVED

Dani AI

Generated

The form values were not appearing because two HTML/PHP fundamentals were mixed up. As pointed out, a textarea does not use a value attribute — its contents must go between the opening and closing tags — and each <option> must use a concrete scalar for value and be marked selected when it matches the stored value. The fix that worked for was to echo the address inside the textarea and to build options from the location rows using the location code as the option value and the name as the visible text.

Practical checklist:

  • Put the address between <textarea>...</textarea> and escape it with htmlspecialchars to avoid breaking the markup when the address contains quotes or </&. See the textarea spec for details: textarea on MDN.
  • When rendering the location <select>, use the location code as value and the location name as the option text. Compare the stored location code to that value and output selected="selected" when they match. Avoid echoing an entire array — echo $row will not print the fields you expect. See the select element docs: select on MDN.
  • Don’t reuse the same $row variable for both the customer fetch and the locations loop; use distinct names like $cust and $loc to avoid confusion.

Debug tips:

  • Turn on full error reporting during development: error_reporting(E_ALL); ini_set('display_errors',1); and var_dump() the fetched arrays to confirm column names and values.
  • Verify the stored location value exactly matches the option value (string vs integer differences can matter).

Security/maintenance note: mysql_* is deprecated. Migrate to mysqli or PDO and use prepared statements for inserts/updates. See PHP’s PDO and mysqli guides: PDO prepared statements and mysqli quickstart.

Recommended Answers

All 6 Replies

Hi..
i didnt get u...whats the problem here...have u got any error?
plz note it...

No ahmksssv,
no error throws, say i have some details in name column, address column, email column , fax no column, phone no column and i stored the code no of locations, suppose i want to edit any data regarding to name column i use value="<?php echo $customername; ?>"
here
<td width="80">Username&nbsp;*&nbsp;</td><td><input type="text" name="comp_name" class="textbox" size="30" maxlength="50" title="Enter your name" value="<?php echo $customername; ?>"/></td>

and the same for all the phone no, email fax no. and what i s problem i have is , i got all the results except the address column and select location. and i need ur help in how the get the post value of address and location where i stored in database

No ahmksssv,
no error throws, say i have some details in name column, address column, email column , fax no column, phone no column and i stored the code no of locations, suppose i want to edit any data regarding to name column i use value="<?php echo $customername; ?>"
here
<td width="80">Username&nbsp;*&nbsp;</td><td><input type="text" name="comp_name" class="textbox" size="30" maxlength="50" title="Enter your name" value="<?php echo $customername; ?>"/></td>

and the same for all the phone no, email fax no. and what i s problem i have is , i got all the results except the address column and select location. and i need ur help in how the get the post value of address and location where i stored in database

Hi.. the above code is correct.....
i think the address field is empty ,due to some reasons....

when u inserting address into database you use this way...

$address=mysql_real_escape_string($_POST['address']);

just try this one....

Hi ahmksssv,
My database's address field is not empty . though why <select> didnt echos their post value why ? i use <td>Location&nbsp;*&nbsp;</td>
<td><?php
/*$link = mysql_connect('localhost', 'root', '');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db("b2bassociates");*/
include 'dbcon.php';

$qry = "select * from tbl_location order by loc_name";
$result = mysql_query($qry,$con);

?>
<select name="sel_loc" title="Select Location" >
<option value="">----Select Location----</option>
<?php
while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row; ?>"
>
<?php echo $row; ?>
</option>
<?php
}
?>
</select>
</td>

I s this the correct way to echo the value
<?php echo $row; ?>

prawin@123,

Try the following,
Address text area should be :
<TEXTAREA ROWS="6" COLS="23" name="comp_add" title="Enter Your Address"><?php echo $customeradd; ?></textarea>


Select Box Should Be:
<select name="sel_loc" title="Select Location">
<option value="">----Select Location----</option>
<?php
while($row=mysql_fetch_array($result))
{
?>
<option value="<?php echo $row; ?>" <?php if($customerloc == $row)echo 'selected';?>>
<?php echo $row; ?>
</option>
<?php
}
?>
</select>

Hi Thanks , U solved My problem, Thank u very much for the solution , Keep doing this job

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.