retro Posted June 8, 2008 Share Posted June 8, 2008 I have a page, new.php, which either adds a new user to a database, or edits an existing user (depending on how you accessed it.. it uses $_GET['id]). It has various input boxes, as you'd expect for name, address etc. The action for the form is save.php. Here is the content of save.php: <?php header("Location: ./"); ?> <? //Connect to DB & check for errors include("dbinfo.inc.php"); $connection = mysql_connect($server,$username,$password); if (!$connection) { echo mysql_errno().": ".mysql_error()."<br/>"; exit; } if(!mysql_select_db($database)) { echo("Database not found<br>"); } //retrieve post data $id = $_POST["id"]; $FirstName = $_POST["firstname"]; $MiddleName = $_POST["middlename"]; $LastName = $_POST["lastname"]; $Town = $_POST["town"]; $Street = $_POST["street"]; $PostCode = $_POST["postcode"]; $houseno = $_POST["houseno"]; $MobilePhone = $_POST["mobilephone"]; $HomePhone = $_POST["homephone"]; $OfficePhone = $_POST["officephone"]; $Email = $_POST["email"]; $Homepage = $_POST["homepage"]; if ($id != '') { //Edit current record $query = "UPDATE customers SET firstname='" . $FirstName . "',middlename='" . $MiddleName . "',lastname='" . $LastName . "', town='" . $Town . "',street='" . $Street . "',postcode='" . $PostCode . "',houseno='" . $houseno . "', mobilehone='" . $MobilePhone . "',homephone='" . $HomePhone . "',officephone='" . $OfficePhone . "', email='" . $Email . "',homepage='" . $Homepage . "' WHERE id=" . $id; } else { //Add new record $query = "INSERT INTO customers(firstname,middlename,lastname,town,street,postcode,houseno,mobilephone,homephone,officephone,email,homepage) VALUES ( '" . $FirstName . "', '" . $MiddleName . "', '" . $LastName . "', '" . $Town . "', '" . $Street . "', '" . $PostCode . "', '" . $houseno . "', '" . $MobilePhone . "', '" . $HomePhone . "', '" . $OfficePhone . "', '" . $Email . "', '" . $Homepage . "' )"; } //Update DB $result = mysql_query ($query) or die("SQL Error: " . mysql_error()); mysql_close(); ?> I have two problems... 1. Creating a new user works fine. Editing a user puts their details into the input boxes, which can be altered. However, clicking save doesn't update the record. It seems to perform fine (going back to the home page) with no errors, but the records haven't updated. 2. I want to have it so that once the page has been submitted, it goes to the order page (order.php), filling in the customer details automatically. I can do this on an existing contact by using a button with onclick="window.location.href='order.php?id=<?php echo $id ?>'" However, as the ID field (auto incrementing) has not been created in the database, I cannot do this within save.php (or I would edit the header location). Could anyone make any suggestions on either of these problems? Thanks in advance for any advice! Link to comment https://forums.phpfreaks.com/topic/109282-solved-problem-with-mysql-saveupdate-script/ Share on other sites More sharing options...
retro Posted June 9, 2008 Author Share Posted June 9, 2008 Never mind, I sorted it myself. The first part was a simple spelling error, and the second part can be solved with mysql_insert_id(). I have an issue with the second part, but I'll mark this resolved and start again with that! Link to comment https://forums.phpfreaks.com/topic/109282-solved-problem-with-mysql-saveupdate-script/#findComment-561343 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.