pughy Posted February 12, 2008 Share Posted February 12, 2008 hi, I want to select data from a table and display it in a form and then change this data in the form and then update the table. I have managed to select the data from the table and display it in a form, but i have tried several ways to update this data but i'm having no luck. The table is called 'organisers'. My code so far is: <? session_start(); $stored_username = $_SESSION['organiserid']; if ($stored_username == NULL){ echo "<SCRIPT LANGUAGE='Javascript'>"; echo "window.location='http://index.php';"; echo "</SCRIPT>"; } else include "organiseronlyhead.php"; { //connect to server $dbconnect=mysql_connect('host', 'username', 'password'); //select your database $dbselect=mysql_select_db('dbname'); //set query parameter for your table $query="SELECT * FROM organisers WHERE organiserid='$stored_username'"; //run the query into your SQL server $run=mysql_query($query); //get the number of rows your query has returned. $rows=mysql_num_rows($run); ?> <center>My Details</center> <? echo "username:"; echo $stored_username; ?> <? //make a simple cycle to run through all your returned records echo '<table align="center">'; //here is the cycle. note the way I made it, it will run as many times as the number of names have been returned from your databes. Instead of $rows, you can limit the cylce to any nymber. For example 5 times for ($i=0; $i<$rows; $i++) { //loading returned values from database into an array $result=mysql_fetch_array($run); echo ' <FORM ACTION="updateorganiser.php" METHOD="POST" class="style1"> <tr> <td>Password:</td> <td><input name="password'.$i.'" value="'.$result['password'].'" /></td> </tr> <tr> <td>Email:</td> <td><input name="email'.$i.'" value="'.$result['email'].'" /></td> </tr> <tr> <td>First Name:</td> <td><input name="fname'.$i.'" value="'.$result['fname'].'" /></td> </tr> <tr> <td>Last Name:</td> <td><input name="lname'.$i.'" value="'.$result['lname'].'" /></td> </tr><tr> <td>Address Line 1:</td> <td><input name="addressline1'.$i.'" value="'.$result['addressline1'].'" /></td> </tr><tr> <td>Address Line 2:</td> <td><input name="addressline2'.$i.'" value="'.$result['addressline2'].'" /></td> </tr><tr> <td>Town:</td> <td><input name="town'.$i.'" value="'.$result['town'].'" /></td> </tr> <tr> <td>County:</td> <td><input name="county'.$i.'" value="'.$result['county'].'" /></td> </tr><tr> <td>Postcode:</td> <td><input name="postcode'.$i.'" value="'.$result['postcode'].'" /></td> </tr><tr> <td>Telephone:</td> <td><input name="telephone'.$i.'" value="'.$result['telephone'].'" /></td> </tr><tr> <td>Mobile:</td> <td><input name="mobile'.$i.'" value="'.$result['mobile'].'" /></td> </tr> <tr> <td> <input type="SUBMIT" name="submit" value="Update"> </td> </tr>'; //the cylce ends here } echo '</table>'; } ?> The submit button will go to updateorganiser.php It is this page i am really struggling with, i can't even display the data from the form on this page never mind try and update the table. Is the above code the best way to get data in a form,so i can change it. does anyone have any ideas were i'm going wrong Any help would be much appreciated thanks Quote Link to comment https://forums.phpfreaks.com/topic/90723-select-data-into-a-form-and-then-update-data-using-the-same-form/ 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.