vomitbomb Posted May 14, 2008 Share Posted May 14, 2008 Is it possible to pull values from the database and put them into forms? I want to pull up a specific order and repopulate the order forms so that order can be changed or updated. Thanks. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 14, 2008 Share Posted May 14, 2008 You would do something like this: <?php //include the connections include 'db.php'; //make the proper query "Safely" (this is just simple for time sake $sql = mysql_query("SELECT * FROM tableName WHERE id = '{$_GET['id']}'"); if(mysql_num_rows($sql) > 0){ $row = mysql_fetch_array($sql); echo'<form action="#" method="post"> <input type="text" name="text1" value="'.$row['column1'].'" /> <input type="submit" value="SEND!" /> </form>'; }else{ echo 'Invalid ID'; } ?> Quote Link to comment Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 Ok I'm trying to figure it out, I realise it sends it to the forms, but how can I write in on the orderform so the forms get populated with these results? Quote Link to comment Share on other sites More sharing options...
jonsjava Posted May 14, 2008 Share Posted May 14, 2008 show us the code, and I'll rework it to do it for you. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 14, 2008 Share Posted May 14, 2008 I don't know if your explaining this correctly or what, but the above code will populate the text field with what ever is in the database. Quote Link to comment Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 ah k I get what you're explaining, nah I need this to send this to another document. $fname = $_POST['fname']; echo $fname; echo '<label>First <input type="text" name="fname" id="fname" value="$fname"/> </label>' Ok the echo up there gives me the right information, although on this particular form it just leaves $fname instead of it's value. I've also tried value=' echo $fname; '> Quote Link to comment Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 Cool I managed to get the value into the form, but now I can't reset the form because the value is set to $fname. :-\ <input type="text" name="fname" id="fname" value='<? echo $fname;?>'> and the reset: <input type="reset" value="Reset Fields" /> Any idea on how I can reset this? Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 14, 2008 Share Posted May 14, 2008 Try this: function resetFields(){ var inputs = document.getElementsByTagName('input'); for(var i=0;i < inputs.length;i++){ inputs[i].value = ''; } } <input type="reset" value="Reset Fields" onclick="resetFields()" /> Quote Link to comment Share on other sites More sharing options...
vomitbomb Posted May 14, 2008 Author Share Posted May 14, 2008 function resetFields(){ var inputs = document.getElementsByTagName('input'); for(var i=0;i < inputs.length;i++){ inputs[i].value = ''; } } am I meant to be changing something there? causes an error on the second line. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted May 14, 2008 Share Posted May 14, 2008 OK, with the reset button, it just sets it to its original state, you have to use a button to do this: <script type="text/javascript"> function resetFields(){ var inputs = document.getElementsByTagName('input'); for(var i=0;i < inputs.length;i++){ if(inputs[i].getAttribute("type") == "text"){ inputs[i].value = ''; } } } </script> <form name="form1"> <input type="text" value="cat" /> <input type="button" value="Clear" onclick="resetFields()" /> </form> Quote Link to comment Share on other sites More sharing options...
vomitbomb Posted May 15, 2008 Author Share Posted May 15, 2008 ok this works well for the first name, but not for anything else.. hmm //Update order echo'<form action="order.php" method="post"> <input type="hidden" name="fname" value="'.$row['fname'].'" /> <input type="hidden" name="lname" value="'.$row['lname'].'" /> <input type="submit" value="Update-Order" /> </form>'; and then: <label>First <input type="text" name="fname" id="fname" value='<? echo "$fname" ?>' /> </label> <label>Surname <input type="text" name="lname" id="lname" value='<? echo "$lname" ?>' /> </label> Anyone know why? Quote Link to comment Share on other sites More sharing options...
vomitbomb Posted May 15, 2008 Author Share Posted May 15, 2008 ok I got that to work. Didn't like the include I used for all the $_POST for some reason. This only works on text menus and wont work on list menus, anyone know why? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.