You are here: PHP/MySQL and Checkboxes « All PHP « IT news, forums, messages
PHP/MySQL and Checkboxes

Posted by sloane.irwin on 05/26/06 20:27

I've created an entry form for my database and it includes four
checkboxes. I am also making an 'edit page', where I wan't to use the
same form as the entry form so that users can click the edit link from
the main display table, change all or just a few values, and it will
then change that row in the db.

With the entry form I get an Undefined Index notice when the checkboxes
are not checked, but no errors if they are checked. Why would this be?

As for the view/edit page, How do I make it so the checkboxes will
appear checked or unchecked whether or not the specific feature is
present on that line of the db?

form code and db_update.php code as follows:

<html>
<head>
<title>New Computer Database Entry</title>
<link href="2col_leftNav.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
..style1 {color: #334d55}
..style2 {
font-size: 100%;
color: #334d55;
}
-->
</style>
</head>
<body>
<p align="center"><img src="osu-hort-logo-color.gif" width="469"
height="173" /></a></p>
<form method="get" action="db_update1.php">
<label><span class="Boldtitle">Initial Information:</span><span
class="story"><br>
<br>
<br>
Inventory#
<input type="text" name="inventory">
</span></label>


<span class="story">
<label>Service Tag/Serial #
<input type="text" name="serial">
</label>
</span>
<p class="style1">

<span class="story">
<label>First Name
<input type="text" name="first">
</label>

<label>Last Name
<input type="text" name="last">
</label>
</span></p>
<p class="story"><span class="style1"><strong>Primary User
Name</strong></span>
<input type="text" name="pri_user">
<span class="style1"><strong>Primary User E-Mail </strong></span>
<input type="text" name="email">
</p>
<p class="story"><span class="story">
<label>Purchase Date
<input type="text" name="buy_date">
</label>

<span class="style1"><strong>Warranty Expiration</strong></span>
<label>
<input type="text" name="warranty">
</label>
</span></p>
<p class="story style1">

<span class="story">
<label>Vendor
<input type="text" name="vendor">
</label>
<label>Computer Name
<input type="text" name="computer_name">
</label>
</span></p>
<p class="story style1"><span class="story">
<label>Date Entered
<input type="text" name="date_entered">
</label>
</span></p>
<strong class="Boldtitle style2">Location:</strong>
</p>
</p>
<p class="style1">


<span class="story">
<label>City
<input type="text" name="city">
</label>

<label>Location Building
<select name="building">
<option>Farm</option>
<option>Gourley</option>
<option>Gourley Greenhouse</option>
<option>Home</option>
<option>Howlett</option>
<option>Howlett Greenhouse</option>
<option>Kottman</option>
<option>Turf Center</option>
<option>Williams</option>
<option>Williams Greenhouse</option>
<option selected>OPGC (BIO CONTAINMENT)</option>
<option>Other</option>
</select>
</label>
</span></p>
<p class="style1">


<span class="story">
<label> </label>

<label>Room Number</label>

<label>
<input name="room" type="text" size="6" maxlength="4">
<br>
<br>
<br>
<br>
</label>
</span>
<label><span class="Boldtitle">Computer Information:</span></label>
<span class="story">
<label><br>
<br>
</label>

<label>Brand</label>

<label>
<input name="brand" type="text">
</label>

<label>Model
<input type="text" name="model">
</label>
</span></p>
<p class="style1">


<span class="story">
<label></label>
<label>OS
<input name="os" type="text" size="10" maxlength="10">
</label>

<label>Processor Speed (GHz)
<input name="processor" type="text" size="8" maxlength="8">
</label>
</span>
<p class="style1">


<span class="story">
<label></label>

<label>Memory Size (Mb)
<input name="memory" type="text" size="8" maxlength="8">
</label>

<label>HD Size (Gb)
<input name="hd" type="text" size="8" maxlength="8">
</label>
</span></p>
<p class="style1">


<span class="story">
<label></label>

<label>CD-ROM</label>
<input type="checkbox" name="drive1" value="yes">
<label>CD-RW</label>
<input type="checkbox" name="drive2" value="yes">
<label>DVD-ROM</label>
<input type="checkbox" name="drive3" value="yes">
<label>DVD-RW</label>
<input type="checkbox" name="drive4" value="yes">
</span></p>
<p class="story">.</p>
<p class="story"><strong>Additional Information: </strong></p>
<p class="style1">
<label>
<textarea name="comments" cols="65" rows="8"></textarea>
</label>
<BR>
</p>
<p class="style1"> <br />
<input type="submit" value="Submit">
</p>
</form>

</body>
</html>




<html>
<body>
<?
require('db_login.php');
require('db_connect.php');

// the table you want to add to

$table = 'data';


// begin the query

$query = "INSERT INTO $table(";


// add fieldnames to insert

$query .= 'inventory' . ',';
$query .= 'date_entered' . ',';
$query .= 'first' . ',';
$query .= 'last' . ',';
$query .= 'serial' . ',';
$query .= 'city' . ',';
$query .= 'brand' . ',';
$query .= 'model' . ',';
$query .= 'email' . ',';
$query .= 'building' . ',';
$query .= 'room' . ',';
$query .= 'computer_name' . ',';
$query .= 'pri_user' . ',';
$query .= 'warranty' . ',';
$query .= 'vendor' . ',';
$query .= 'os' . ',';
$query .= 'processor' . ',';
$query .= 'memory' . ',';
$query .= 'hd' . ',';
$query .= 'drive1' ;
$query .= 'drive2' ;
$query .= 'drive3' ;
$query .= 'drive4' ;
$query .= 'comments' ;



// end fieldnames and begin values

$query = $query . ') VALUES(';


// get values from $_REQUEST

$query = $query . '"' . $_REQUEST['inventory'] . '", ';
$query = $query . '"' . $_REQUEST['date_entered'] . '", ';
$query = $query . '"' . $_REQUEST['first'] . '", ';
$query = $query . '"' . $_REQUEST['last'] . '", ';
$query = $query . '"' . $_REQUEST['serial'] . '", ';
$query = $query . '"' . $_REQUEST['city'] . '", ';
$query = $query . '"' . $_REQUEST['brand'] . '", ';
$query = $query . '"' . $_REQUEST['model'] . '", ';
$query = $query . '"' . $_REQUEST['email'] . '", ';
$query = $query . '"' . $_REQUEST['building'] . '", ';
$query = $query . '"' . $_REQUEST['room'] . '", ';
$query = $query . '"' . $_REQUEST['computer_name'] . '", ';
$query = $query . '"' . $_REQUEST['pri_user'] . '", ';
$query = $query . '"' . $_REQUEST['warranty'] . '", ';
$query = $query . '"' . $_REQUEST['vendor'] . '", ';
$query = $query . '"' . $_REQUEST['os'] . '", ';
$query = $query . '"' . $_REQUEST['processor'] . '", ';
$query = $query . '"' . $_REQUEST['memory'] . '", ';
$query = $query . '"' . $_REQUEST['hd'] . '", ';
$query = $query . '"' . $_REQUEST['drive1'] . '", ';
$query = $query . '"' . $_REQUEST['drive2'] . '", ';
$query = $query . '"' . $_REQUEST['drive3'] . '", ';
$query = $query . '"' . $_REQUEST['drive4'] . '", ';
$query = $query . '"' . $_REQUEST['comments'] . '"';


// end query

$query = $query . ')';


// run INSERT query


mysql_query($query, $db);

include('db_close.php');
?>

<script language="javascript">
<!--
drfgh
location.href = 'display2.php';

//-->
</script>
</body>
</html>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация