I'm trying to figure out how to update a table with information taken from an exploded variable but I can't figure out what's going wrong...
I've got two tables - orders and services.
I've got a form with a select box whose text is taken from two separate columns and whose value is the two concantented columns. I then want to take that concantented value and explode it and update the table with both bits going into separate columns. Trouble is that the first column is being updated with the unexploded info and the second column gets nothing. Can't figure out which bit is going wrong.
This is what I've got:
The select box and query (which I should add is being replicated multiple times on the page):
Code: Select all
<select name="service" >
<option value="Choose">Choose a Size</option>
<?php
$result = @mysql_query("SELECT service_name, service_price
FROM services
ORDER BY service_id ASC
");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
while ($row = mysql_fetch_array($result)) {
$service_name = $row['service_name'];
$service_price = $row['service_price'];
$option_value = $row['service_name'] .'-' . $row['service_price'] ;
$service_details = explode("-", $option_value);
$service_name = htmlspecialchars($service_name);
echo '<option value="' . $option_value . '">' . $service_name . ' – ' . $service_price .'</option>';
}
$formid = $formid + 1; ?>
</select>Code: Select all
if (isset($_POST['value'])){ // if value set, add items to order table
$service_details = explode("-", '$_POST[$option_value]');
$service_update = '$_POST[$service_details[0]]';
$price_update = '$_POST[$service_details[1]]';
$result = @mysql_query("INSERT INTO orders
SET id = '$_POST[custid]',
photoref = '$_POST[value]',
qty = '$_POST[qty]',
service = '$service_update',
price = '$price_update',
date = CURDATE();
");
if (!$result) {
exit('<p>Error performing query: ' . mysql_error() . '</p>');
}
}