Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating Database

Status
Not open for further replies.

mondeoman

MIS
Dec 7, 2006
203
GB
I have a page on my web site where the user can update members details. The SQL I am using is this:

mysql_query("UPDATE tblMembers SET FirstName='$field2',Surname='$field3',Role='$field4',Address1='$field5',Address2='$field6',Address3='$field7',Address4='$field8',PostCode='$field9',Telephone='$field10',email='$field11' WHERE eventid ='$id'");

The form Code is:

<form id="form1" name="form1" method="post" action="">

<table width="49%" border="0" align="center">

<td width="35%"></td>

<tr>

<td>Member No</td>
<td><input name="member_id" type="text" id="member_id" /></td>
</tr>
<tr>
<td>First Name</td>

<td><input name="FirstName" type="text" id="FirstName" /></td>
</tr>
<tr>
<td>Surname</td>

<td><input name="Surname" type="text" id="Surname" /></td>
<tr>
<td>Role</td>

<td><input name="Role" type="text" id="Role" /></td>
<tr>
<td>Address</td>

<td><input name="Address1" type="text" id="Address1" /></td>
</tr>
<td></td>
<td><input name="Address2" type="text" id="Address2" /></td>
</tr>
<td></td>
<td><input name="Address3" type="text" id="Address3" /></td>
</tr>
<td></td>
<td><input name="Address4" type="text" id="Address4" /></td>
</tr>
<td>Post Code</td>

<td><input name="PostCode" type="text" id="PostCode" /></td>
</tr>
<td>Telephone</td>

<td><input name="Telephone" type="text" id="Telephone" /></td>
</tr>
<td>email</td>

<td><input name="email" type="text" id="email" /></td>
</tr>
</tr>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>
</form></p></td> </tr></table></td> </tr></table></td> </tr></table>

This works but the user has to replace all fields if amendments need to be made. What I want is that the user needs only to update a specific field ratehr than all of them.

I incorrectly put this question on the wrong forum but was told I could achieve this by :

* populate all form fields with the current values
* the user changes what has to be changed and leaves all others unchanged
* you just save all form fields

As a simpleton can someone tell me how to do this please?

I have provided a link to a text file that has all the page's code.
 
Hi

Ouch. First was not clear how all that works, but I got it now :
[ul]
[li]you display the table of data and the empty form[/li]
[li]the visitor enters the ID of the data to edit and the details[/li]
[/ul]
This usually is done differently :
[ul]
[li]you display the table of data[/li]
[li]the visitor chooses the data to edit[/li]
[li]you display the form, populated with the chosen data[/li]
[/ul]
For this, your script will have to be rewritten, not a routine task without a database. ( At least not for me. )

However, there is a dirty workaround : all the data is present in the table, so use JavaScript to populate the form with the data. Sorry, if you choose this, the discussion will be off-topic here too. However I strongly recommend to not go the easy way : as pointed out in the initial thread, your PHP has security holes so should be modified anyway.


Feherke.
 
First I agree with feherke that your code is extremely vulnerable, unless you are actually cleaning your variables somewhere you are not showing us.

Anyway, to retain all the values, and seeing as this all appears to be in the same file, just use your variables to populate your form:

Code:
[gray]
  <td>First Name</td>

      <td><input name="FirstName" type="text" id="FirstName" [red]value="<?PHP echo $field2 ?>"[/red] /></td>
    </tr>
        <tr>
        <td>Surname</td>
     
      <td><input name="Surname" type="text" id="Surname" [red]value="<?PHP echo $field3 ?>"[/red]  /></td>
[/gray]
etc...





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi

Phil said:
Anyway, to retain all the values, and seeing as this all appears to be in the same file, just use your variables to populate your form:
That would not really help. Variable $field2 & co. get values after the form was submitted. But the solution to the OP's problem would be to populate the form before displaying it to the visitor.

mondeoman, I tried to reproduce your database so I can put some code together, but then I realized that is pointless in this moment. We do not have enough information about what happens there. Why are you displaying the member_id then compare it with eventid when updating.

So please give us some explanation.

Feherke.
 
You are assuming he wants to show the form from the database, no where is this even implied.

I just assumed he wanted to offer the chance to modify any values previously submitted by the user in case he made a mistake.

If he wants to populate from the database to offer the chance to update an existing record, then it would take much more code of course, but also more information on his part, like how the users are choosing which record to update, and whether or not every user would have right to update ever record. Is there some kind of security in place etc...



----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Hi

Phil said:
You are assuming he wants to show the form from the database, no where is this even implied.
No, I am not assuming, just strongly recommending.

Currently he displays the IDs together with the data in a table, then the visitor has to enter the ID together with the data in a form.

Then he saves all received data to the specified ID (?). The OP simply wishes a way to save not every field, just those fields, the visitor filled, so unfilled fields to not overwrite previously filled fields.

I think this approach is wrong enough to not help the OP solving it. Sadly I do not understand what he is doing there with the IDs, so I can not post a better code for now.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top