Page 1 of 1
check box
Posted: Fri Apr 21, 2006 6:40 am
by wilko18
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.
Any ideas?
Code: Select all
$price = 1000;
if(isset($_POST['tb12']))
{
$price = 4000;
}
echo $price;
Posted: Fri Apr 21, 2006 6:46 am
by JayBird
show you html form code too
Posted: Fri Apr 21, 2006 6:53 am
by wilko18
Code: Select all
<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>
Posted: Fri Apr 21, 2006 7:48 am
by Oren
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.
You have this:
Code: Select all
<form name="form1" method="post" action="">
You need to type the path to tell the form where you want the info to be sent to - like this: action="[path_here]" (it's blank in your code).
Posted: Fri Apr 21, 2006 5:00 pm
by John Cartwright
leaving the action blank will just send the form to the current url.
Secondly, I'm a bit confused by the OP's post, are you wanting to loop over checkboxes and insert their values to a grand total price?