JJohnsenDK Posted December 4, 2006 Share Posted December 4, 2006 I have this script where i want the text in the dropdown menu to be update to my database when pressed submit. The script works fine if i do a input type="text". But when i use the dropdown the text doesnt update, why?[code]<?php include('mysql_connect.php'); $hent = "SELECT * FROM wof_pl"; $bestgk = mysql_query($hent) or die(mysql_error()); ?> <form action="<?php $_SERVER['PHP_SELF'] ?>" method="post" > <br /> <select name="d1"> <?php $hent = "SELECT * FROM wof_pl"; $bestgk = mysql_query($hent) or die(mysql_error()); while ($vis = mysql_fetch_array($bestgk)){ $df = $vis['wof_pl_pos']; if ($df == "Forsvar"){ ?> <option value="<?php $df = $vis['wof_pl_name']; ?>"><?php $df = $vis['wof_pl_name']; echo $df; ?></option> <?php } } ?> </select> <br /><br /> <input type="submit" value="send" name="submit" /> </form><?php if(isset($_POST['submit'])){ $hent = mysql_query("INSERT INTO wof_best SET wof_best_d1 = '".$_POST['d1']."'"); }?>[/code] Link to comment https://forums.phpfreaks.com/topic/29432-resolved-why-doesnt-this-script-update-database/ Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 Try some debugging first.[code=php:0]$hent = mysql_query("INSERT INTO wof_best SET wof_best_d1 = '".$_POST['d1']."'") or die(mysql_error());[/code] Link to comment https://forums.phpfreaks.com/topic/29432-resolved-why-doesnt-this-script-update-database/#findComment-135057 Share on other sites More sharing options...
JJohnsenDK Posted December 4, 2006 Author Share Posted December 4, 2006 Well there isnt a error really because the script inserts a blank field into the database, as if there isnt any text in the drop down menu. My quess is how do i update the database with the text or option i select in the dropdown menu? Link to comment https://forums.phpfreaks.com/topic/29432-resolved-why-doesnt-this-script-update-database/#findComment-135062 Share on other sites More sharing options...
trq Posted December 4, 2006 Share Posted December 4, 2006 Im not sure what your doing in your option tag but it should be like...[code]<option value="<?php echo $vis['wof_pl_name']; ?>"><?php echo $vis['wof_pl_name']; ?></option>[/code] Link to comment https://forums.phpfreaks.com/topic/29432-resolved-why-doesnt-this-script-update-database/#findComment-135073 Share on other sites More sharing options...
JJohnsenDK Posted December 5, 2006 Author Share Posted December 5, 2006 It works... Thanks alot for your time and help thorpe ;D Link to comment https://forums.phpfreaks.com/topic/29432-resolved-why-doesnt-this-script-update-database/#findComment-135453 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.