Jump to content

Select data into a form, and then update data using the same form


Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.