MannyG Posted March 31, 2010 Share Posted March 31, 2010 Hey I have encountered a problem with a form page I am using which takes the information from a row of an html table (dynamic html table that displays mysql data). I have the form page acting as an edit information screen where I would have text fields for entries the user may want to edit. What I want to do is pre-load the information from table (that specific row selected) into the text field's. I have used an auto_increment field from the mysql table to differentiate the value however every time i try to run this query through the form to print out the selected result it does not work. <?php ##Connection to Database $conn = mysql_connect("machine", "", "") or die("Could not connect : " . mysql_error()); mysql_select_db("my_db", $conn) or die("Could not select database"); $Auto_id = $_GET['Auto_id']; // this shows in url as 1,2,3 is my auto_inc field in database $test = "SELECT * FROM build WHERE build_id = '$Auto_id'"; //simple query where build_id is also an auto_increment field in database that pertains to this field mysql_query($test); echo "<center>"; echo "<form method='POST' action='editInsert.php'>"; //editInsert.php is just me running queries to database using $_POST so i can update values, have tested and it works when i manually enter a 'value' for each form input but i want the form textfields to automatically load the row data echo "<h1><b>Edit Results</b></h1></br>"; echo "<p class='hlight'><b>Codeline</b>"; echo "<input type='text' name='codeline' value='".$test['version']."' maxlength='10' size='10'>"; echo "</p>"; echo "<p class='hlight'><b>Bundle</b>"; echo " <input type='text' name='bundle' value='' maxlength='10' size='10'>"; echo "</p>"; echo "<p class='hlight'><b>Device</b>"; echo " <input type='text' name='device' value='' maxlength='10' size='10'>"; echo " </p>"; echo " <p class='hlight'><b>Java Precert</b>"; echo " <input type='text' name='java' value='' maxlength='10' size='10'>"; echo "</p>"; echo " <p class='hlight'><b>MMS</b>"; echo "<input type='text' name='mms' value='' maxlength='10' size='10'>"; echo " </p>"; echo "<p class='hlight'><b>Branch</b>"; echo " <input type='text' name='branch' value='' maxlength='10' size='10'>"; echo "</p>"; echo "<p class='hlight'><b>JC</b>"; echo "<input type='text' name='jc' value='' maxlength='10' size='10'>"; echo " </p>"; echo "<p>" ; echo "<input type='submit' name='submit' value='Submit'>"; echo "<input type='button' name='cancel' value='Cancel' onclick='location.href='index.php''>"; echo " <input type='hidden' name='Auto_id' value = '' >"; echo "</p>"; echo "</form>"; echo "</div>"; echo "</center>"; ?> Sorry if it is a little messy, I tried I tried it in the first line with 'codeline' as the field I wanted to check out. Basically just want to load the info from the table to these particular text fields. I have checked the query in MySQL cmd and it works fine, so I know its not a query issue. Thanks~ Edit** There is a value that appears in the textfield, and the value is 'S' ...not sure what it means or what I can do about it? Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/ Share on other sites More sharing options...
irkevin Posted March 31, 2010 Share Posted March 31, 2010 Try this, <?php $conn = mysql_connect("machine", "", "") or die("Could not connect : " . mysql_error()); mysql_select_db("my_db", $conn) or die("Could not select database"); $Auto_id = $_GET['Auto_id']; // this shows in url as 1,2,3 is my auto_inc field in database $test = "SELECT * FROM build WHERE build_id = '$Auto_id'"; $result = mysql_query($test); while($row = mysql_fetch_array($result)){ $version = $row['version']; } echo $version; ?> YOu need to iterate over the data using the while loop. Try it and let me know Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/#findComment-1034851 Share on other sites More sharing options...
tomtimms Posted March 31, 2010 Share Posted March 31, 2010 I am a bit lost, how are you passing "Auto_id" to this form? Is there a previous page that you have that is passing the id to this page in which you are getting it? Other wise the above example works you just need to change echo "<input type='text' name='codeline' value='" . $test['version'] . "' maxlength='10' size='10'>"; to echo "<input type='text' name='codeline' value='" . $version . "' maxlength='10' size='10'>"; Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/#findComment-1034854 Share on other sites More sharing options...
MannyG Posted March 31, 2010 Author Share Posted March 31, 2010 @irkevin It worked!!! Thank you so much!!! However I have another question D: I need to load data into all the other textfields so within the while loop can I still do that? so would I will change the query and here is something i'd like to check out... <?php $test = ""SELECT build.bundle, devices.devicename, build.version, Auto_id FROM build, devices, build_device_test WHERE ((build.build_id = build_device_test.$'Auto_id') AND (devices.deviceID = build_device_test.$'Auto_id'))"; $result = mysql_query($test); while($row = mysql_fetch_array($result)){ $version = $row ['version']; $bundle = $row['bundle']; } ?> so if i did like 4-5 of these it would be fine? also these will not print out all the instances of the variables? I made it in the query (the joins i added) that there would be the $Auto_id is what they must be equal too...does that sound plausible? @tomtimms Yes I forgot to mention I passed the value from a button via href link into tjhis page (Auto_id) Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/#findComment-1034870 Share on other sites More sharing options...
irkevin Posted March 31, 2010 Share Posted March 31, 2010 Well, as a start, I don't really understand your query. What's this: build_device_test.$'Auto_id' Please clarify. If you could show how your table are set up, that would be a good place to start! Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/#findComment-1034873 Share on other sites More sharing options...
tomtimms Posted March 31, 2010 Share Posted March 31, 2010 You don't have to do it in a while loop, you can just use mysql_fetch_array and then load the values into your form. $test = ""SELECT build.bundle, devices.devicename, build.version, Auto_id FROM build, devices, build_device_test WHERE ((build.build_id = build_device_test.$'Auto_id') AND (devices.deviceID = build_device_test.$'Auto_id'))"; $result = mysql_query($test); $row = mysql_fetch_array($result); then you can just pop the array values into your form values. echo "<input type='text' name='codeline' value='" . $row['version'] . "' maxlength='10' size='10'>"; Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/#findComment-1034885 Share on other sites More sharing options...
MannyG Posted March 31, 2010 Author Share Posted March 31, 2010 Ah thank you tomtimm's works perfect! That is exactly what I needed/wanted to do Thanks again!~~ Link to comment https://forums.phpfreaks.com/topic/197149-php-form-and-mysql/#findComment-1034899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.