Forum Moderators: coopster
I am trying to update existing records and to identify each record im using their id number.
The problem i think is somehow the id is not getting passed so the query fails to work.
i then simply echoed out the query to see what happens, and it clearly show that the id variablr didnt contain the id number.
Here is the script, update.php, that i am using to update the existing record.
-------------
?php
require_once("../../admin/includes/connection.php");
if(isset($_POST['submit']))
{
$title=$_POST['title'];
$first_name=$_POST['first_name'];
$surname=$_POST['surname'];
$position=$_POST['position'];
$company_name=$_POST['company_name'];
$company_email=$_POST['company_email'];
$company_fax=$_POST['company_fax'];
$company_telephone_number=$_POST['company_telephone_number'];
$address_1=$_POST['address_1'];
$address_2=$_POST['address_2'];
$address_3=$_POST['address_3'];
$town=$_POST['town'];
$county=$_POST['county'];
$post_code=$_POST['post_code'];
$free_sample=$_POST['free_sample'];
$order_sent=$_POST['order_sent'];
///spacer
$errors .= (empty($post_code)) ? "<span class=\"emptyFields\">postcode</span>" : "";
$errors .= (empty($company_name)) ? "<span class=\"emptyFields\">company name</span>" : "";
$errors .= (empty($company_telephone_number)) ? "<span class=\"emptyFields\">telepone number</span>" : "";
$errors .= (empty($company_email)) ? "<span class=\"emptyFields\">email</span>" : "";
//need to add country, product and state
if (!$errors)
{
if(!get_magic_quotes_gpc())
{
$title = addslashes($title);
$first_name = addslashes($first_name);
$surname = addslashes($surname);
$position= addslashes($position);
$company_name = addslashes($company_name);
$company_email = addslashes($company_email);
$company_fax = addslashes($company_fax);
$company_telephone_number= addslashes($company_telephone_number);
$address_1= addslashes($address_1);
$address_2= addslashes($address_2);
$address_3= addslashes($address_3);
$town= addslashes($town);
$county= addslashes($county);
$post_code= addslashes($post_code);
$free_sample= addslashes($free_sample);
$order_sent= addslashes($order_sent);
}
if ( (isset($_GET['ID'])) && (is_numeric($_GET['ID'])) ) { //correctly accessed
$id=$_GET['ID'];
} else {
$errors[] = 'You have accessed this page incorrectly.';
}
$query = "UPDATE order_enquiries SET
title='$title',
first_name='$first_name',
surname='$surname',
position='$position',
company_name='$company_name',
company_email='$company_email',
company_fax='$company_fax',
company_telephone_number='$company_telephone_number',
address_1='$address_1',
address_2='$address_2',
address_3='$address_3',
town='$town',
county='$county',
post_code='$post_code',
free_sample='$free_sample',
post_code='$post_code',
order_sent='$order_sent'
WHERE id='$id'";
$return = mysql_query($query);
echo "$query";
}
}
?>
-------------
kind regards
Dazzclub
I did that, in the action it read "update.php?ID=[id]" but that didnt work, the id number just didnt display. But because the actual update form echo's the original records in the input fields i changed your suggestion to this update.php?ID=<?php echo $id ; ?> and it works.
Was this a good approach?
kind regards
Dazzclub