Jump to content

Recommended Posts

Hi all,

I have a data base with the following table:

 

---member_data---

id ^ mid ^fieldname^ fieldvalue

1 - 2 - applicant - Seth Smith

2 - 4 - firstname - Chris

3 - 4 - lastname - Cooper

4 - 7 - full_name - Joey Jones

5 - 7 - occupation - Programmer

6 - 7 - phone - 800-555-1212

 

 

And below is a snippet that I use to display the selected members data for editing

 

-------------------------------

<table>

<tr>

<td>Name:</td>

<td>Value:</td>

</tr>

<?php

 

$query = "SELECT * FROM member_data WHERE mid='$mid'";

$result= mysql_query($query);

  while($row = mysql_fetch_array($result)) {

 

  $fieldname = $row["fieldname"];

  $fieldvalue = $row["fieldvalue"];

 

?>

<tr>

<td><input type="text" name="<?php echo $fieldname;?>" value="<?php echo $fieldname;?>"></td>

<td><input type="text" name="<?php echo $fieldvalue;?>" value="<?php echo $fieldvalue;?>"></td>

<?php } ?>

</tr>

</table>

-------------------------------

 

My question is:

 

- using the Db example above:

- lets say Ive selected mid#7 (member id 7) to edit which is displayed using the snippet code from above.

- once displayed how do I edit  mid#7  given the fact that  mid#7  is located on 3 seperate rows from the same table?

 

Thank you,

Dave

 

 

*ALSO - I tried the snippet below which did Not work.

 

foreach($_POST as $key => $val) {

$sql = "UPDATE member_data SET fieldname='$key', fieldvalue='$val' WHERE mid='$mid'";

$result = mysql_query($sql);

}

you see - I already have a script where you can:

 

Type in any random external URL (must be URL of Form page), then click Submit.

Next, the script grabs ALL the name attributes + value attributes from all of the <INPUT TAGs> within that Form page.

Then - those name attributes + value attributes are INSERTED into the Db.

 

 

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

*Example below takes (2) random Form pages and...

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

 

 

RANDOM FORM PAGE (a):

----------------------------------------

<input type="text" name="fname" value="Sam">

<input type="text" name="lname" value="Smith">

<input type="text" name="anything" value="whatever">

 

 

WOULD BE INSERTED IN Db LIKE:

----------------------------------------

id ^ mid ^fieldname^ fieldvalue

1 - 1 - fname - Sam

2 - 1 - lname - Smith

3 - 1 - anything - whatever

 

 

 

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

*Now lets Grab/Insert a different random Form.. (see below)

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

 

 

RANDOM FORM PAGE (b):

----------------------------------------

<input type="text" name="user" value="Richard">

<input type="text" name="alias" value="Rambo">

<input type="text" name="music" value="jazz">

<input type="text" name="age" value="22">

<input type="text" name="car" value="Honda">

 

 

APPENDED IN Db NOW LOOKS LIKE:

----------------------------------------

id ^ mid ^fieldname^ fieldvalue

1 - 1 - fname - Sam

2 - 1 - lname - Smith

3 - 1 - anything - whatever

4 - 2 - user - Richard

5 - 2 - alias - Rambo

6 - 2 - music - jazz

7 - 2 - age - 22

8 - 2 - car - Honda

 

 

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

You see - the script processes random external

Form pages, so the <INPUT TAG> name + value

attributes are NOT unique and will vary majority of

the time from Form to Form.

 

I just dont know how to UPDATE them in the Db.

::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

 

Simple fix, instead of having this:

$fieldname = $row["fieldname"];
$fieldvalue = $row["fieldvalue"];

 

replace it with:

 

$fieldname = $row["fieldname"];
$fieldvalue = $row["id"];

 

Basically, you want to update the row with that unique ID since you already have the row you need when you requested the needed rows WHERE mid = X.

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.