Update Form. Update old details with new details from same

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Roegadyn
Forum Newbie
Posts: 2
Joined: Wed Jan 13, 2010 1:39 pm

Update Form. Update old details with new details from same

Post 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.




.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
abushahin
Forum Commoner
Posts: 42
Joined: Wed Nov 25, 2009 12:35 pm
Location: london

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

Post 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".
Roegadyn
Forum Newbie
Posts: 2
Joined: Wed Jan 13, 2010 1:39 pm

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

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

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

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply