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!
I want to change the value of a variable $price IF a check box is checked...
I have the following code...however the value is still displaying 1000 suggesting its not going through the loop even though the box is checked.
<form name="form1" method="post" action="">
<input name="tb11" type="checkbox" id="tb11" value="checkbox" checked="checked" />
Phantom Chaparral: <?php
require_once('../mysql_connect.php'); //Connect to the database
// Make the query
$query = "SELECT price as a FROM boat WHERE boat_id=1";
$result = @mysql_query ($query); //Run the query
if ($result) {// If it ran OK display the records.
//Table header.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '£' . $row['a'] . '
';
$price = $row[a];
echo $price;
}
mysql_free_result ($result); //Free up the resources.
} else {//if it did not run ok.
echo '<p class="error">The current users could not be retrieved. We apologise for any inconvenience.</p>'; //Public message.
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; //Debugging message.
}
?><br />
<input name="tb12" type="checkbox" id="tb12" value="checkbox" checked="checked" />
Painted name of boat:
<?php
// Make the query
$query = "SELECT option1_price as b FROM boat WHERE boat_id=1";
$result = @mysql_query ($query); //Run the query
if ($result) {// If it ran OK display the records.
//Table header.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '£' . $row['b'] . '
';
$price = 1000;
if(isset($_POST['tb12']))
{
$price = 4000;
}
echo $price;
}
mysql_free_result ($result); //Free up the resources.
} else {//if it did not run ok.
echo '<p class="error">The current users could not be retrieved. We apologise for any inconvenience.</p>'; //Public message.
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; //Debugging message.
}
?><br />
<input name="tb13" type="checkbox" id="tb13" value="checkbox" />
Canopy:
<?php
// Make the query
$query = "SELECT option2_price as c FROM boat WHERE boat_id=1";
$result = @mysql_query ($query); //Run the query
if ($result) {// If it ran OK display the records.
//Table header.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '£' . $row['c'] . '
';
$price = $price * 0.9;
echo $price;
}
mysql_free_result ($result); //Free up the resources.
} else {//if it did not run ok.
echo '<p class="error">The current users could not be retrieved. We apologise for any inconvenience.</p>'; //Public message.
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; //Debugging message.
}
?><br />
<input name="tb14" type="checkbox" id="tb14" value="checkbox" />
Increase engine size to 400cc: <?php
// Make the query
$query = "SELECT option3_price as d FROM boat WHERE boat_id=1";
$result = @mysql_query ($query); //Run the query
if ($result) {// If it ran OK display the records.
//Table header.
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
echo '£' . $row['d'] . '
';
}
mysql_free_result ($result); //Free up the resources.
} else {//if it did not run ok.
echo '<p class="error">The current users could not be retrieved. We apologise for any inconvenience.</p>'; //Public message.
echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; //Debugging message.
}
mysql_close(); //Close the database connection.
?><br />
</form>
I've read only the first line so there may be more problems. Anyway, there is a problem on the first line so fix it and if that doesn't work post here and I would check the whole code.