hi have following code:
$dropdown = "<select name='test'>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['name']}'>{$row['name']}</option>"; } $dropdown .= "\r\n</select>"; echo $dropdown; <form name="input" action="databaseupdate.php" method="post"> select car want edit , fill in form, followed clicking update button. <br> carname: <input type="text" name="nameupdate"> year build: <input type="text" name="yearupdate"> <input type="submit" value="update"> </form>
and 1 (databaseupdate.php):
<?php $username = "root"; $password = "usbw"; $hostname = "localhost"; $db_name = "examples"; $tbl_name = "cars"; mysql_connect("$hostname", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select db"); $nameupdate = $_post['nameupdate']; $yearupdate = $_post['yearupdate']; $test = $_post['test']; $query = "update cars set name = '$nameupdate', year = '$yearupdate' id='$test'"; mysql_query($query) or die (mysql_error()); if($query){ echo "successful"; echo "<br>"; echo "<a href='databaseconnect.php'>back main page</a>"; } else { echo "error"; } ?>
so, list populated car names database, point don't know how id comes car's name.
i have tried query says "wher id='$test'" (as can see in code) returns empty.
example of want:
if select "mercedes" dropdownlist , want update textboxes want code know mercedes has id of 1.
i don't know how can , hope can me out here.
thanks.
first of include dropdown inside form.
second if want id drop down selection, fetch id db car name in $result
, this:
$dropdown = "<select name='test'>"; while($row = mysql_fetch_assoc($result)) { $dropdown .= "\r\n<option value='{$row['id']}'>{$row['name']}</option>"; } $dropdown .= "\r\n</select>"; <form name="input" action="databaseupdate.php" method="post"> select car want edit , fill in form, followed clicking update button. <br> echo $dropdown; carname: <input type="text" name="nameupdate"> year build: <input type="text" name="yearupdate"> <input type="submit" value="update"> </form>
done.
Comments
Post a Comment