checkboxes

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
chrisackford
Forum Newbie
Posts: 4
Joined: Sat Dec 09, 2006 6:50 am

checkboxes

Post by chrisackford »

ok i have built this script and i want the check boxes if checked to add Yes to the data base and No if it asant how could i do this

Code: Select all

<?php
include("./dbconnect.php");//include the file that connects to the database
if(!empty($name)) {
$name = addslashes($name);
$user = addslashes($user);
$usernumber = addslashes($usernumber);
$year = addslashes($year);
$interviewed = addslashes($interviewed);
$accepted = addslashes($accepted);
$trial = addslashes($trial);
$course = addslashes($course);
$warnings = addslashes($warnings);
$comments = addslashes($comments);

$date = date("F j, Y");//set up the date format
$date2 = mktime();

$sql = "INSERT INTO manager (id, name, user, usernumber, year, date, interviewed, accepted, trial, course, warnings, comments ) VALUES ('NULL', '$name', '$user', '$usernumber', '$year', '$date', '$interviewed', '$accepted', '$trial', '$course', '$warnings', '$comments')";
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
echo "Database Updated <br /> <a href=viewmanager.php> Go Back! </a>.";
} else {
?>
<form name="manager" method="post" action="<?php echo $PHP_SELF; ?>">
<p>Please fill out all of the following fields:</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="117"><font size="1">Name*: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="name" size="50">
</font></td>
</tr>
<tr>
<td width="117"><font size="1">Username*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="user" size="50">
</font></td>
</tr>
<tr>
<td width="117"><font size="1">User Number*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="usernumber" size="5">
</font></td>
</tr>
<td width="117"><font size="1">year*:</font></td>
<td width="577">
<font size="1">
<select name="year">
  <option value="07">7</option>
  <option value="08">8</option>
  <option value="09">9</option>
  <option value="10">10</option>
  <option value="11">11</option>
</select>
</font></td>
</tr>
<tr>
<td width="117"><font size="1">interviewed*:</font></td>
<td width="577"><input name="interviewed" type="checkbox" value="" /></td>
</tr>
<tr>
<td width="117"><font size="1">Accepted*:</font></td>
<td width="577"><input name="accepted" type="checkbox" value="" /></td>
</tr>
<tr>
<td width="117"><font size="1">Trial*:</font></td>
<td width="577">
<input name="trial" type="checkbox" value="" /></td>
</tr>
<tr>
<td width="117"><font size="1">Course*:</font></td>
<td width="577">
<input name="course" type="checkbox" value="" /></td>
</tr>
<td width="117"><font size="1">Comments*:</font></td>
<td width="577"><textarea name="comments" cols="43" rows="10" id="comments"></textarea></td>
</tr>
</table>
<input name="warnings" type="hidden" value="0" />
<p>
<font size="1">
<input type="submit" name="Submit" value="Submit"></font>
</p>
</form> <?php
}//end this function
?>
thansk for the help :)
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Your code appears to be under the assumption that register_globals is on. While it may be for your current server, this is a pretty old way of constructing pages and is highly recommended to update several things. Chiefly
  • addslashes() to mysql_real_escape_string()
  • $_POST for each of the fields being submitted
  • isset() or array_key_exists() to check if they exist before attempting to use them. This is the solution to your question as well.
  • 'NULL' and NULL are two different things to a database. You want the latter.
  • rename keyword fields in database to non-keywords. e.g. "date"
  • use native date format of database instead of your own
  • stop using $PHP_SELF in any form it may be in. "#" is safer.
I also noticed you're using <font> tags. That's pretty old school too. ;)
chrisackford
Forum Newbie
Posts: 4
Joined: Sat Dec 09, 2006 6:50 am

Post by chrisackford »

feyd wrote:Your code appears to be under the assumption that register_globals is on. While it may be for your current server, this is a pretty old way of constructing pages and is highly recommended to update several things. Chiefly
  • addslashes() to mysql_real_escape_string()
  • $_POST for each of the fields being submitted
  • isset() or array_key_exists() to check if they exist before attempting to use them. This is the solution to your question as well.
  • 'NULL' and NULL are two different things to a database. You want the latter.
  • rename keyword fields in database to non-keywords. e.g. "date"
  • use native date format of database instead of your own
  • stop using $PHP_SELF in any form it may be in. "#" is safer.
I also noticed you're using <font> tags. That's pretty old school too. ;)
this is goin to sound really stupid but... i dident understand a word of that and mate gave me the script and i edited it changing the form please help me :D
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Sorry, I'm not going to do the work for you.
chrisackford
Forum Newbie
Posts: 4
Joined: Sat Dec 09, 2006 6:50 am

Post by chrisackford »

feyd wrote:Sorry, I'm not going to do the work for you.
i just dident get what u meant comeon im 15 and i wanna learn :D
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

chrisackford wrote:
feyd wrote:Sorry, I'm not going to do the work for you.
i just dident get what u meant comeon im 15 and i wanna learn :D
Take it one step at a time, I think what Feyd said is very straight forward. So what exactly don't you understand?
chrisackford
Forum Newbie
Posts: 4
Joined: Sat Dec 09, 2006 6:50 am

Post by chrisackford »

Jcart wrote:
chrisackford wrote:
feyd wrote:Sorry, I'm not going to do the work for you.
i just dident get what u meant comeon im 15 and i wanna learn :D
Take it one step at a time, I think what Feyd said is very straight forward. So what exactly don't you understand?
# $_POST for each of the fields being submitted
# isset() or array_key_exists() to check if they exist before attempting to use them. This is the solution to your question as well.
# rename keyword fields in database to non-keywords. e.g. "date"
# use native date format of database instead of your own
# $_POST for each of the fields being submitted
were ?
# isset() or array_key_exists() to check if they exist before attempting to use them. This is the solution to your question as well.
totaly dont get
# rename keyword fields in database to non-keywords. e.g. "date"
dose he mean for like "interviewed" put like "iv" in the database ?
# use native date format of database instead of your own
for think im just going to say :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Each of those listed have had at least a few threads written on them. Have you searched?
Post Reply