Jump to content

How to "Edit" data retrieved from My SQL and repost


NutinElse2do

Recommended Posts

All,

 

Looking for a litte direction. PHP form to a My SQL database. Data is entered pushed to DB, you are then redirected to the "output" of all the data that was ever entered from the DB.

 

Where do I start to make several of the fields on the "output" page editable?

 

If more information is needed, let me know. If there is some reading that will best suit me, please point the way!

 

Partial output:

 

$query="SELECT * FROM  xxxxxxx";

$result=mysql_query($query);

 

$num=mysql_numrows($result);

 

mysql_close();

 

echo "<b><center>Database Output</center></b><br><br>";

 

$i=0;

while ($i < $num) {

 

$id=mysql_result($result,$i,"id");

$field_1=mysql_result($result,$i,"field_1");

$field_2=mysql_result($result,$i,"field_2");

$field_3=mysql_result($result,$i,"field_3");

 

edited

 

<table border="1">

<tr>

<th>Record</th>

<th>Date</th>

<th>Time</th>

 

edited

 

<?

$i=0;

while ($i < $num) {

 

$id=mysql_result($result,$i,"id");

$field_1=mysql_result($result,$i,"field_1");

$field_2=mysql_result($result,$i,"field_2");

$field_3=mysql_result($result,$i,"field_3");

 

?>

 

<tr>

<td><font face="Arial, Helvetica, sans-serif"><? echo $id; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo $field_1; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo $field_2; ?></font></td>

<td><font face="Arial, Helvetica, sans-serif"><? echo $field_3; ?></font></td>

 

</tr>

 

<?

$i++;

}

 

echo "</table>";

 

 

Thanks

 

Nutin

 

 

Link to comment
Share on other sites

Sensei, thanks for the typo catch - appreciate it..

 

Yesideez -- Let me see if I understand you correctly..

 

The FORM that has returned the data stored from the DB, needs another "button" for editing that calls up that record by itself, then rewrites it to the DB?

 

Do you recommend some reading material , web sites?  This is a little beyond my "level 2"  knowledge.

 

Thanks Nutin

Link to comment
Share on other sites

If you know how to create a form, then you can do it.

 

When you build the form, you just set the Values to the fields you are reading in.  When they hit submit, it writes it back, with all the info pre-filled in and the changes they made.

Link to comment
Share on other sites

Excuse my ignorance, but if the DB already has a ID for each record why would I have to assign a value to it.

 

Can I just use a PHP script to call out the original DB record and edit that? What about a having the user enter the DB ID number and call it up that way?

 

Way to many thoughts on the way to do this.

 

Sorry to bug you guys with trivial stuff

Link to comment
Share on other sites

You have to assign an ID because when you send a UPDATE sql query, you need to specify what row you want to update.

 

So you are calling the original record and editing it.  Don't rely on the user entering something, you need to make sure it's set in your code for the correct ID.

Link to comment
Share on other sites

You know when you go down a rat whole, and you just cant seem to see anything else except what your doing.....

 

So... as I started getting in more trouble, I wrote this, to update my database, I have no clue if its even in the right format, or right anything. I been on this project for..  I dunno, weeks!!  Anyway. Thanks for letting me ramble a little.

 

The DB will have less than 20 active records at a time, so I thought that the "user" can enter the ID# on a text line that they need to edit and go from there.

 

Can you look at this and tell me if it will update the DB the way I "THINK" it will.. (If I am totally off base, please feel free to delete this post..  ;D I wont be able to test it on my server til the AM so I was hoping you can all save me the trouble and give me a thumbs up or down or go back and read more..  Thanks again

 

$id=$_GET['id'];

$username="username";

$password="password";

$database="dbname";

 

mysql_connect(localhost,$username,$password);

 

$query=" SELECT * FROM dbname WHERE id='$id'";

$result=mysql_query($query);

$num=mysql_numrows($result);

mysql_close();

 

$i=0;

while ($i < $num) {

$field_1=mysql_result($result,$i,"field_1");

$field_2=mysql_result($result,$i,"field_2");

$field_3=mysql_result($result,$i,"field_3");

$field_4=mysql_result($result,$i,"field_4");

$field_5=mysql_result($result,$i,"field_5");

$field_6=mysql_result($result,$i,"field_6");

$field_7=mysql_result($result,$i,"field_7");

$field_8=mysql_result($result,$i,"field_8");

$field_9=mysql_result($result,$i,"field_9");

$field_10=mysql_result($result,$i,"field_10");

 

++$i;

}

 

 

$query="UPDATE dbname SET field_1 = '$new_field_1', field_2 = '$new_field_2',

field_3 = '$new_field_3', field_4 = '$new_field_4', field_5 = '$new_field_5',

field_6 = '$new_field_6', field_7 = '$new_field_7',  field_8 = '$new_field_8,  field_9 = '$new_field_9,

field_10 = '$new_field_10, WHERE id = '$new_id'";

mysql_query($query);

echo "Record Updated";

mysql_close();

 

 

<form action="updated.php" method="post">

<input type="hidden" name="new_id" value="<? echo $id; ?>">

CMR Number: <input type="text" name="new_field_1" value="<? echo $field_1; ?>"><br>

Case: <input type="text" name="new_field_2" value="<? echo $field_2; ?>"><br>

System: <input type="text" name="new_field_3" value="<? echo $field_3; ?>"><br>

Date: <input type="text" name="new_field_4" value="<? echo $field_4; ?>"><br>

Time: <input type="text" name="new_field_5" value="<? echo $field_5; ?>"><br>

Contact Name: <input type="text" name="new_field_6" value="<? echo $field_6; ?>"><br>

Contact Number: <input type="text" name="new_field_7" value="<? echo $field_7; ?>"><br>

Status: <input type="text" name="new_field_8" value="<? echo $field_8; ?>"><br>

Work : <input type="text" name="new_field_9" value="<? echo $field_9; ?>"><br>

Email: <input type="text" name="new_field_10" value="<? echo $field_10; ?>"><br>

<input type="Submit" value="Update">

</form>

 

 

Link to comment
Share on other sites

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.