Page 1 of 1

Update Form. Update old details with new details from same

Posted: Wed Jan 13, 2010 1:59 pm
by Roegadyn
I am sorry for the starter question but its something I have been pulling my hair out with all day now. I have a simple database setup. Its an assignment and not a real world application. I have created forms to put data into the database, I have forms to delete data from the database and they were not too bad for me to make and to an extent understand. I really struggle with programming its not my strong point and probably never will be but I do have a slight desire to learn php and MySql. Anyway enough waffle and onto the problem.

I have a form that has 5 text fields for a CustomerID, CustomerSurname, CustomerFirstName, CustomerAddress and CustomerTelephoneNumber. under the heading of old customer details. Then below that on the same form under the heading Enter the new customer details, I have the same text fields in which to enter the new customers details. So what I need to do with the php code is take those old details that have been entered in the text fields and update them in the database with the details entered in the second lot of text fields that are under the new customer details heading. So what I imagine to happen is the program looks at the form say right old customer details are here, lets update in the MySql database those old details with the second lot of details on this form.

The code for the form looks like

Code: Select all

<html>
<head>
<title> Industial Fasteners </title>
</head>
<body>
<h1> Update Customer Details Form </hl>
<h2> Please enter the customers old details</h2>
<form action="Update.php" method="post">
<table>
<tr>
<td>CustomerNumber:
<td><input type="text" name="CustomerNumber" />
</tr>
<tr>
<td>CustomerSurname:
<td><input type="text" name="CustomerSurname" />
</tr>
<tr>
<td>CustomerFirstName:
<td><input type="text" name="CustomerFirstName" />
</tr>
<tr>
<td>CustomerAddress:
<td><input type="text" name="CustomerAddress" />
</tr>
<tr>
<td>CustomerTelephoneNumber:
<td><input type="text" name="CustomerTelephoneNumber" />
</tr>
</table>
<h2> Please enter the new customer details</h2>
<form action="Update.php" method="post">
<table>
<tr>
<td>CustomerNumber:
<td><input type="text" name="CustomerNumber" />
</tr>
<tr>
<td>CustomerSurname:
<td><input type="text" name="CustomerSurname" />
</tr>
<tr>
<td>CustomerFirstName:
<td><input type="text" name="CustomerFirstName" />
</tr>
<tr>
<td>CustomerAddress:
<td><input type="text" name="CustomerAddress" />
</tr>
<tr>
<td>CustomerTelephoneNumber:
<td><input type="text" name="CustomerTelephoneNumber" />
</tr>
</table>
</form>
</body>
</html>
I hope this makes sense. Thank you for any help.




.

Re: Update Form. Update old details with new details from same

Posted: Wed Jan 13, 2010 2:40 pm
by AbraCadaver
Why would you enter the old details? Retrieve the old details from the database, populate the form fields with the old values so that you can change them and submit.

Re: Update Form. Update old details with new details from same

Posted: Wed Jan 13, 2010 2:47 pm
by abushahin
Hey I had to do a similar thing at uni where new details needed to be updated to existing customers etc, so what i did was add a textfield to enter a surname or id etc then retrieve the info from db from into the add customer form about the related id, surname, that way once the info is retrived you can echo it to the textfields etc

Code: Select all

<input type="text" name="Sname" [b]value="<?php echo $name?>"[/b]>
dont forget your not going to add again you need to submit to another php page where it updates to surname = "whatever".

Re: Update Form. Update old details with new details from same

Posted: Wed Jan 13, 2010 3:06 pm
by Roegadyn
Thank you abushahin, I shall take a look at that and see what I can do.

AbraCadaver I am not sure if the way I am thinking of trying to do this is the correct way. There may well be a far simpler way or more logical way to do this. I just in my own way of thinking thought that it would be best to be able to say to the database I want to change value CustomerID 1, CustomerSurname Jones, CustomerFirstName Bob, CustomerAddress 1 Any Street to Customer ID 1, CustomerSurname Jones, CustomerFirstName Bob, CustomerAddress Any Avenue. Although in that example I am doing far more work than needs to be done as I am inputting 5 fields of data to change one probably two fields.

I am so stuck with php and it is a completely new concept to me. I am literally in way over my head with it. And as an aging user I dont tend to take in information as well as I used to do. So there is probably a far simpler more logical way for me to make a form, tell the database I want to change Bobs address to this and press the submit button. And for it to do its thing. I just dont know what it is at this moment.

Thank you for the replys.

Re: Update Form. Update old details with new details from same

Posted: Wed Jan 13, 2010 5:30 pm
by AbraCadaver
I'll give you the idea and then you can read at php.net or check some tutorials. After you come up with some code and get stuck I'll help you out.

1. Query the database to get the data for the record you want to edit
2. Display the form with the data as the values of the inputs
3. A user can then change the data that is in the inputs and click submit
4. You will then update that record with the new data