TheStalker Posted July 11, 2008 Share Posted July 11, 2008 Hi, I am trying to create a edit customer page. I have a drop down box with the customers IDs in sourced from the database table. When i select a customerID i would like the text boxes to fill with the data about that customer e.g. surname, first name etc so i can edit it and then update the database. dose anyone have any surgestions on a simple way of doing this? do i need a fetch like ;while($row = mysql_fetch_array($result))? this is what ive come up with so far but it dosnt work: <?php $dbhost = 'localhost'; $dbuser = 'root'; $dbpass = ''; $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql'); $dbname = 'randv'; mysql_select_db($dbname); ?> <center> <table border='0' width='300'> <form> <tr> <td><p>CustomerID:</td><td><?php print "<SELECT NAME=results>"; // Search alternativeDishes $query = "SELECT CustomerID FROM customers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { foreach ($line as $value) { print "<OPTION value='$value'"; } print ">$value</OPTION>"; } ?></td> <?php $result = mysql_query("SELECT * FROM customers WHERE CustomerID = '$value'");?> <tr> <td><p>Surname:</td> <td><input type="text" name="surname" value="<?php echo $row ['Surname']?>" /></td> </tr> <tr> <td><p>Forename:</td> <td><input type="text" name="forename" /></td> </tr> Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/ Share on other sites More sharing options...
TheStalker Posted July 11, 2008 Author Share Posted July 11, 2008 just this min got this to work but it dosnt change when i chnage the CustomerID in the drop down box <td><p>Surname:</td> <td><input type="text" name="surname" value="<?php $result = mysql_query("SELECT * FROM customers WHERE CustomerID = '$value'"); ;while($row = mysql_fetch_array($result)) echo $row ['Surname']?>" /></td> Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/#findComment-587487 Share on other sites More sharing options...
peuge Posted July 11, 2008 Share Posted July 11, 2008 just this min got this to work but it dosnt change when i chnage the CustomerID in the drop down box <td><p>Surname:</td> <td><input type="text" name="surname" value="<?php $result = mysql_query("SELECT * FROM customers WHERE CustomerID = '$value'"); ;while($row = mysql_fetch_array($result)) echo $row ['Surname']?>" /></td> Dont know but it could be WHERE CustomerID = '$value'" should be WHERE CustomerID = $value" Otherwise try result = mysql_query("SELECT surname FROM customers WHERE id=$value"); while($row = mysql_fetch_array($result)) { ?> <form> <textarea name="aboutme" cols="40" rows="5"> <?php echo stripslashes($row['surname']); ?> </textarea><br> </form> Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/#findComment-587558 Share on other sites More sharing options...
peuge Posted July 11, 2008 Share Posted July 11, 2008 Sorry meant to say: $result = mysql_query("select * FROM `news` WHERE `id`='.$id'"); Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/#findComment-587571 Share on other sites More sharing options...
TheStalker Posted July 11, 2008 Author Share Posted July 11, 2008 none of that worked for me any other ideas ive come to a stop with this now Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/#findComment-587608 Share on other sites More sharing options...
mbeals Posted July 11, 2008 Share Posted July 11, 2008 you've got some crazy stuff going on in your html. There is at least one unclosed <td> tag and putting a <form> tag inside a table block is bad juju. <center> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="POST" name="names"> <table border='0' width='300'> <tr> <td><p>CustomerID:</p></td> <td> <SELECT NAME='results' onchange="this.form.submit();"> <?php // Search alternativeDishes $query = "SELECT CustomerID FROM customers"; $result = mysql_query($query); while ($line = mysql_fetch_array($result)) { echo "<OPTION value='$line[0]'>$line[0]</OPTION>"; }?> </SELECT> </td> </tr> <?php if($value=$_POST['results']){ $result = mysql_query("SELECT * FROM customers WHERE CustomerID = '$value'"); $surname = mysql_result($result,0,'surname'); $forename = mysql_result($result,0,'forename'); } ?> <tr> <td>Surname:</td> <td><input type="text" name="surname" value="<?php echo $surname ?>" /></td> </tr> <tr> <td>Forename:</td> <td><input type="text" name="forename" value="<?php echo $forename?>"/></td> </tr> </table> </form> </center> There, I cleaned it up and fixed some stuff. Besides the html and php being funky, the reason it wasn't working was because you weren't processing the form. The flow of this type of thing is: 1. enter data into form 2. submit form 3. page calls itself and passes data from form 4. page checks for form data and if it is there, uses it. The original script wasn't passing the form data to anything and it wasn't listening for any form data Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/#findComment-587610 Share on other sites More sharing options...
TheStalker Posted July 11, 2008 Author Share Posted July 11, 2008 thanks so much for that, it works a treat. Im still really new to php and web programming, some of the things you put in ive never even seen so thanks again Link to comment https://forums.phpfreaks.com/topic/114256-fill-text-boxes-with-data-from-mysql-table-help-please/#findComment-587710 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.