Hi all,
I seem to be having a problem with updating a database and I suspect it is the php outputting html that might be the cause, here is the order of the script:
having got the database records out we output some html based on certain criteria being met:
if (($service1 == "true")){
echo "<tr><td><br>Your price for service1 is: £$service1price use this field to update your price:</tr></td><tr><td><input type=\"text\" name=\"service1price\" value=\"\" maxlength=\"25\"></tr></td></br>";
}
else{
echo "<br>You do not provide service1</br>";
}
You can see here that the user can update the price of a service provided they.. provide it!
This works fine, now I need to set the data to be posted back to the database. I post the supplierid because this is a new table and it might be the first time the user is updating the table:
if(isset( $submit ))
{
$supplierid = isset($_POST['supplierid']) ? $_POST['supplierid'] : "";
$service1price = isset($_POST['service1price']) ? $_POST['service1price'] : "";
Now I do some error checking before updating the database:
}
if(!empty($messages)){
displayErrors($messages);
}
else
{
$query = "INSERT INTO supplierprices (supplierid, serviceprice1) VALUES('".$supplierid."', '".$service1price."') ON DUPLICATE KEY UPDATE supplierid = '" . $supplierid . "'";
$result = mysql_query($query, $link) or die('Update failed: ' . mysql_error());
echo $query;
//print_r($query);
mysql_info($link) ;
if(mysql_affected_rows($link) == 0)
{
//$link next to affected rows and mysql query
echo '';
}
else
{
echo 'Your profile has been updated successfully, please click <a href=suppliers.php>here</a> to go back to the main member page.';
}
}
So the above is not completly finished but the query itself is. The problem when I output the query is that having entered a value for serviceprice1 it is empty here.
Any ideas why?
Thanks,
G