473,327 Members | 2,055 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

IF and Radio Buttons

I have the following code which connects to a database and sets the
value of counter to '0' and the date to be either the current date or a
users own date. The database connects via an included script as this is
a contribution for OSCommerce. Each section (the set date today and set
date custom) works fine by itself (with the other half commented out)
but I cant make it so the option is available via radio buttons, what am
I doing wrong?

Thanks in advance,
Ben

P.S. This is the code I am using

<?php
include('includes/application_top.php');
?>
<html>
<body>
<?php
//OS Commerce Counter Reset v0.15
//Author: Ben Allen

if ($submit) {
//Validation
$flag="OK"; // This is the flag and we set it to OK
$msg=""; // Initializing the message to hold the error messages
//Set Query Variables
$query = "UPDATE counter SET counter = 0";
$today = date("Ymd");
$datetoday = "UPDATE counter SET startdate = $today";
//Set Date=Today
if ($setdate="true") {
$counterquery = mysql_query($query);
$datequery = mysql_query($datetoday);
echo "Counter Reset Succesfully";
}else{
//Set Date Custom
if ($setdate="false") {
//Edit Database:
$customdate = mktime(0, 0, 0, $month, $day, $year);
$datecustom = strftime("%Y%m%d", $customdate);
$datecustomquery = "UPDATE counter SET startdate = $datecustom";
$counterquery = mysql_query($query);
$datecustomresult = mysql_query($datecustomquery);
echo "Counter Reset Succesfully";
}
}else {
//Display Form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<table width="260" border="0" align="center" height="90"> <tr
align="center" valign="middle">
<td height="31"> <div align="right" class="content">
<div align="left">
<input name="setdate" type="radio" value="true">
Today</div>
</div>
<div align="left"> </div></td></tr>
<tr align="center" valign="middle"> <td height="25"> <div
align="right"><font color="FBC300"></font></div>
<div align="left"><font color="FBC300">
<input name="setdate" type="radio" value="false">
</font>
<input name="day" type="text" id="day" size="2" maxlength="2">
<input name="month" type="text" id="month" size="2"
maxlength="2">
<input name="year" type="text" id="year" size="4" maxlength="4">

(dd/mm/yyyy) </div></td></tr> <tr align="center"
valign="middle"> <td> <div align="center">
<input type="Submit" name="submit" value="Enter" class="button"> </div>
<div align="center"></div></td></tr> </table>
<font color="FBC300"> </font></form>
<?php
} // end if
require(DIR_WS_INCLUDES . 'application_bottom.php');
?>
</body>
</html>
Jul 17 '05 #1
2 1782
"Ben Allen" <"ben.allen"@\"your.tonsils\"btinternet.com> kirjoitti
viestissä:da**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I have the following code which connects to a database and sets the value
of counter to '0' and the date to be either the current date or a users own
date. The database connects via an included script as this is a
contribution for OSCommerce. Each section (the set date today and set date
custom) works fine by itself (with the other half commented out) but I cant
make it so the option is available via radio buttons, what am I doing
wrong?

if ($setdate="true") {...
if ($setdate="false") {...


== is the comparison operator, = is assignment. When you assign the string
"true" to $setdate, of course it is true. Instead you need to compare
them...

if ($setdate=="true") {...
if ($setdate=="false") {...

--
"I am pro death penalty. That way people learn
their lesson for the next time." -- Britney Spears

et****************@5P4Mgmail.com
Jul 17 '05 #2
Kimmo Laine wrote:
"Ben Allen" <"ben.allen"@\"your.tonsils\"btinternet.com> kirjoitti
viestissä:da**********@nwrdmz03.dmz.ncs.ea.ibs-infra.bt.com...
I have the following code which connects to a database and sets the value
of counter to '0' and the date to be either the current date or a users own
date. The database connects via an included script as this is a
contribution for OSCommerce. Each section (the set date today and set date
custom) works fine by itself (with the other half commented out) but I cant
make it so the option is available via radio buttons, what am I doing
wrong?

if ($setdate="true") {...
if ($setdate="false") {...

== is the comparison operator, = is assignment. When you assign the string
"true" to $setdate, of course it is true. Instead you need to compare
them...

if ($setdate=="true") {...
if ($setdate=="false") {...

Brilliant thanks, I knew it had to be some simple newbie mistake, thanks
once again.

Ben
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: sman | last post by:
Hi, I recently read this article on About.com on how to create required fields for a form: http://javascript.about.com/library/scripts/blformvalidate.htm Everything works great except that there...
2
by: Jeff | last post by:
I'm trying to create a dynamic form that can have multiple groups of radio buttons (each group has two buttons) with the same name. Essentially, the form allows a user to enter as many names as...
4
by: Oscar Monteiro | last post by:
I Have to sets of Radio buttons like so: <input type="radio" name=p1 value=1> <input type="radio" name=p1 value=2> <input type="radio" name=p1 value=3> <br> <input type="radio" name=p2 value=1>...
6
by: Craig Keightley | last post by:
I have a page that has n number of radio groups (yes/No) how can i prevent the form being submitted if more than one radio group is not selected? By default all radio groups are unchecked ...
2
by: Rob | last post by:
Hi all, I've got multiple sets of radio button that are dynamically created in code and populated by a database query. The query returns about 20 recordsets with 3 radio buttons per recordset and...
2
by: James P. | last post by:
Help, I need to display radio buttons on a form. The data is from SQL table: each row in each table is displayed as a radio button. I have multiple SQL tables so I understand I need to put...
1
by: kenny8787 | last post by:
Hi, can anyone help here? I have the following code generated from a database, I want to have javascript calculate the costs of the selected items using radio buttons, subtotal the costs and...
2
by: dpazza | last post by:
Hi, I'm creating a quiz on using a form in VB 2005 express. I have four sets of questions and answers (labels and radio buttons) and I change between which set of questions is currently shown on...
4
by: Blasting Cap | last post by:
I have a page that has a number of radio buttons that will be displayed to different access levels of a user who logs in to my website. For instance, if there are a dozen buttons, user1 will see...
11
by: Twayne | last post by:
Hi, Newbie to PHP here, no C or other relevant background, so pretty niave w/r to the nuances etc. but I think this is pretty basic. XP Pro, SP2+, PHP 4.4.7, XAMPP Local Apache Server...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.