phppup Posted February 22, 2012 Share Posted February 22, 2012 I am able to view record numbers 22, 84, and 203 by exectuing my PHP script with the correct record ID. However, what I really want to do is have a simple form whereby I can input the desired record number and have it upload the data for me. I imagine it would look something like this: "SELECT * FROM mytable WHERE id = specified_record" but need a bit of guidance to get the HTML input fields 'name' into the PHP request. Quote Link to comment https://forums.phpfreaks.com/topic/257548-selecting-a-record/ Share on other sites More sharing options...
spiderwell Posted February 22, 2012 Share Posted February 22, 2012 you can call the input field anything you like in the html, just use the same name to retrieve it in the php when submited. <input type="text" name="record"> <? $record = $_POST['record']; "SELECT * FROM mytable WHERE id = " . $record ?> of course you need to add security to this to prevent sql injection, but hopefully that gives you the idea Quote Link to comment https://forums.phpfreaks.com/topic/257548-selecting-a-record/#findComment-1320093 Share on other sites More sharing options...
AyKay47 Posted February 22, 2012 Share Posted February 22, 2012 First, I would specify a query that would produce all of the ID numbers to display to the user and have it populate a drop down list. <form action='' method='post'> <select name='record_id'> <?php $sql = "select ID from table"; $query = mysql_query($sql) or die($sql . "<br />" . mysql_error()); if(mysql_num_rows($query) > 0) { while($row = mysql_fetch_assoc($query)) { $record_id = $row['ID']; echo '<option value="' . $record_id . '">' . $record_id . '</option>'; } } ?> </select> </form> then, wherever you have the form action pointing to, you would add this code to grab the value of the select tag. $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; //check for $record_id emptiness if(!empty($record_id)) { //execute code block } Quote Link to comment https://forums.phpfreaks.com/topic/257548-selecting-a-record/#findComment-1320094 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 So I would have: $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; //check for $record_id emptiness if(!empty($record_id)) { "SELECT * FROM mytable WHERE id = $record_id " } Is that correct?? Am I missing any brackets or braces?? Quote Link to comment https://forums.phpfreaks.com/topic/257548-selecting-a-record/#findComment-1320107 Share on other sites More sharing options...
AyKay47 Posted February 22, 2012 Share Posted February 22, 2012 So I would have: $record_id = (isset($_POST['record_id'])) ? $_POST['record_id'] : ''; //check for $record_id emptiness if(!empty($record_id)) { "SELECT * FROM mytable WHERE id = $record_id " } Is that correct?? Am I missing any brackets or braces?? if this code is on the page where you form action points to, it will hold the select value correctly, but the code your posted itself will not actually do anything. You also forgot to store the SQL string inside of a variable. Quote Link to comment https://forums.phpfreaks.com/topic/257548-selecting-a-record/#findComment-1320110 Share on other sites More sharing options...
phppup Posted February 22, 2012 Author Share Posted February 22, 2012 THANKS.... i'll keep this open and let you know how it works out. Quote Link to comment https://forums.phpfreaks.com/topic/257548-selecting-a-record/#findComment-1320117 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.