PDA

View Full Version : Textarea form problem


PRodgers4284
02-08-2008, 11:27 AM
Im looking to post the content of a textarea back to a form from my database but i cant same to get it to work, its fine for the rest of the fields in the form, my code is:

<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$update = mysql_query("UPDATE users SET username='" . $_POST["username"] . "',forename='" . $_POST["forename"] . "',surname='" . $_POST["surname"] . "',email='" . $_POST["email"] . "',mobile='" . $_POST["mobile"] . "',dob='" . $_POST["dob"] . "',location='" . $_POST["location"] . "',about='" . $_POST["about"] . "' WHERE username='" . $_SESSION["username"] . "'");
?>

<br />
<a href=\"index.php\">Back to main page</a>
<br />
<br />
<br />
You have successfully updated your account .
<?php
}
else
{
$account = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE username='" . $_SESSION["username"] . "'"));
?>
<form method="post" class="registerform" action="">
<fieldset>
<label for="username">Your Account details</label><p><label for="username">Username:</label>
<input name="username" type="text" id="username" value="<?php echo $account["username"]; ?>" /><br />
</p>
</fieldset>

<fieldset>
<label for="forename">Forename:</label>
<input name="forename" type="text" id="forename" value="<?php echo $account["forename"]; ?>" /><br />
</fieldset>

<fieldset>
<label for="surname">Surname:</label>
<input name="surname" type="text" id="surname" value="<?php echo $account["surname"]; ?>" /><br />
</fieldset>


<fieldset>
<label for="email">Email:</label>
<input name="email" type="text" id="email" value="<?php echo $account["email"]; ?>" /><br />
</fieldset>


<fieldset>
<label for="mobile">Mobile:</label>
<input name="mobile" type="text" id="mobile" value="<?php echo $account["mobile"]; ?>" /><br />
</fieldset>

<fieldset>
<label for="dob">DOB:</label>
<input name="dob" type="text" id="dob" value="<?php echo $account["dob"]; ?>" /><br />
</fieldset>

<fieldset>
<label for="location">Location:</label>
<p></p>
<select name="location">
<option value="Please Select">Please Select</option>
<?php
$location_opts = array(
"Co.Antrim",
"Co.Armagh",
"Co.Down",
"Co.Fermanagh",
"Co.Londonderry",
"Co.Tyrone",
);
foreach($location_opts as $opt){
$selected = ($account["location"]) == $opt ? " selected=true":"";
echo "<option value=\"" . $opt . "\"" . $selected . ">" . $opt . "</option>";
}
?>
</select>
</fieldset>
<hr class="hr_blue"/>

<fieldset>
Additional Information<br />
<p></p>
<fieldset>
<label for="about">About you</label>
<textarea rows="2" name="about" cols="20" value="<?php echo $account["about"]; ?>" /></textarea><br />
<p></p>
<fieldset>

<br />

<p class="submit">
<input type="submit" name="submit" value="Submit" />
</p>
</fieldset>

</form>
<?php
}
?>

abduraooft
02-08-2008, 11:55 AM
<textarea rows="2" name="about" cols="20" value="<?php echo $account["about"]; ?>" /></textarea> textarea has no value atribute. Use it like <textarea rows="2" name="about" cols="20" /><?php echo $account["about"]; ?></textarea>

PRodgers4284
02-08-2008, 11:59 AM
textarea has no value atribute. Use it like <textarea rows="2" name="about" cols="20" /><?php echo $account["about"]; ?></textarea>


Thanks

Inigoesdr
02-08-2008, 12:03 PM
textarea has no value atribute. Use it like <textarea rows="2" name="about" cols="20" /><?php echo $account["about"]; ?></textarea>
I'm sure it was a typo, but for clarification, that should be:
<textarea rows="2" name="about" cols="20"><?php echo $account["about"]; ?></textarea>

PRodgers4284
02-08-2008, 02:14 PM
How can set a dropdown box to readonly, i have the rest of the fields in my form as readonly, cant same to get the dropdown option to be set as readonly

<select readonly name="location">
<option value="Please Select">Please Select</option>
<?php
$location_opts = array(
"Co.Antrim",
"Co.Armagh",
"Co.Down",
"Co.Fermanagh",
"Co.Londonderry",
"Co.Tyrone",
);
foreach($location_opts as $opt){
$selected = ($account["location"]) == $opt ? " selected=true":"";
echo "<option value=\"" . $opt . "\"" . $selected . ">" . $opt . "</option>";
}
?>
</select>

hammer65
02-08-2008, 03:00 PM
How can set a dropdown box to readonly, i have the rest of the fields in my form as readonly, cant same to get the dropdown option to be set as readonly

<select readonly name="location">
<option value="Please Select">Please Select</option>
<?php
$location_opts = array(
"Co.Antrim",
"Co.Armagh",
"Co.Down",
"Co.Fermanagh",
"Co.Londonderry",
"Co.Tyrone",
);
foreach($location_opts as $opt){
$selected = ($account["location"]) == $opt ? " selected=true":"";
echo "<option value=\"" . $opt . "\"" . $selected . ">" . $opt . "</option>";
}
?>
</select>


Why would you need to? The user can't enter arbitrary text into a standard HTML select list anyway.

PRodgers4284
02-08-2008, 03:34 PM
Why would you need to? The user can't enter arbitrary text into a standard HTML select list anyway.

I want the field to be readonly because i have an edit option on the form which allows the user to edit the records. I have the form which displays the the readonly data and then once the user selects the edit it goes to the edit page where the fields are not readonly so they can be edited.

Phil

PRodgers4284
02-08-2008, 03:39 PM
I got it sorted, changed the location field to an input box on the form and then had the dropdown box in the edit form, thanks for your help hammer