Wednesday, 15 April 2015

php - Get information out of sql and put it in a form -



php - Get information out of sql and put it in a form -

so need info out of sql , set in dropdown in form. here's have... i'm lost.. info has been prepopulated sql. believe top part relatively right , don't know how reference in form.

php

<?php $id= $_get['id']; $conn = mysql_connect("localhost", "root", "") or die (mysql_error()); mysql_select_db("assignment 3", $conn); $sql = "select schoolname schooltable id=$id"; $result=mysql_query($sql, $conn) or die(mysql_error()); while ($row=mysql_fetch_assoc($result)){ foreach($row $name => $value){ print "$name = $value</br>"; } } mysql_data_seek($result, 0); while ($row=mysql_fetch_assoc($result)){ //select id, firstname, lastname userlist $school = $row["schoolname"]; $grad = $row["lastname"]; } ?>

html

<div class="form-group"> <label class='col-xs-4 control-label'>what school did go undergrad? </label> <div class='col-xs-8'> <select class="form-control background" id='dropdown'> <option>"<?php print $schoolname ?>"</option> <option>"<?php print $schoolname ?>"</option> <option>"<?php print $schoolname ?>"</option> <option>"<?php print $schoolname ?>"</option> <option value="bing">"<?php print $schoolname ?>"</option> </select> <input type="hidden" name="id" id='id' value="<?php print $id ?>"> <input type="hidden" name="editmode" value="edit"> </div> </div

here go

<?php if(!isset($_get['id']]){ echo 'id= not nowadays in url. exiting.'; homecoming false; } $id = intval($_get['id']); $conn = mysql_connect("localhost", "root", "mis42520!$") or die (mysql_error()); mysql_select_db("assignment 3", $conn); $sql = "select * schooltable id='" . mysql_real_escape_string($id) . "'"; $result = mysql_query($sql, $conn) or die(mysql_error()); $schools = array(); while ($row = mysql_fetch_assoc($result)) { $schools[] = $row; } ?> <div class="form-group"> <label class='col-xs-4 control-label'>what school did go undergrad? </label> <div class='col-xs-8'> <select class="form-control background" id='dropdown'> <?php foreach($schools $school){?> <option value="<?php echo $school['schoolname'];?>"><?php echo $school['schoolname'];?></option> <?php } ?> </select> <input type="hidden" name="id" id='id' value="<?php echo $id ?>"> <input type="hidden" name="editmode" value="edit"> </div> </div

php mysql sql forms

No comments:

Post a Comment