Answered
Checkboxes don't work in search from
I am trying to build a search form to select data from two
tables:
TABLE 1
h_genres
fields - h_genre_id, (primary key), user.id (foreign key), contrib._to. (text field), Advertising (set ‘Y’,’N’) and Editor (set ‘Y’,’N’)
TABLE 2
user
with fields user_id (primary key), first_name, last_name
The search form has checkboxes for the items I want to search on: Advertising and/or Editor
Here’s the code:
<form id="form1" name="search" method="post" action="results2.php">
<input type="checkbox" name="Advertising" value="Y" id="Advertising" />
<label for="checkbox">Advertising</label>
<p>
<input type="checkbox" name="Annual_Reports" value="Y" id="Annual_Reports" />
<label for="checkbox2">Annual Reports</label>
</p>
<p>
<input type="checkbox" name="Leader_Content" value="Y" id="Leader_Content" />
<label for="checkbox3">Leader</label>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
I thought I could pass the values of these inputs to a query in a POST variable. When I check the Advertising box on the search form and submit it, I see the ‘Y’ is passed to the results form.
Here’s the code from the variable dump on the results page:
<!-- BEGIN VARIABLE DUMP -->
<!-- BEGIN GET VARS -->
<!-- -->
<!-- BEGIN POST VARS -->
<!-- { Advertising = 'Y', Submit = 'Submit' } -->
In the results form I set a variable var to $_POST[‘Y’]
But all I’m getting for results are user records that are not associated with the h_genres records.
Here’s the code from the results form:
<?php require_once('../Connections/xxxx.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$var_getHAUW = "some";
if (isset($_POST['Y'])) {
$var_getHAUW = (get_magic_quotes_gpc()) ? $_POST['Y'] : addslashes($_POST['Y']);
}
mysql_select_db($database_hauw, $hauw);
$query_getHAUW = sprintf("SELECT h_genres.user_id, h_genres.contrib_to, h_genres.Advertising, h_genres.Annual_Reports, h_genres.Leader_Content, `user`.first_name, `user`.last_name FROM h_genres, `user` WHERE h_genres.user_id=`user`.user_id AND Advertising=%s", GetSQLValueString($var_getHAUW, "text"));
$getHAUW = mysql_query($query_getHAUW, $hauw) or die(mysql_error());
$row_getHAUW = mysql_fetch_assoc($getHAUW);
$totalRows_getHAUW = mysql_num_rows($getHAUW);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table border="0">
<tr>
<td>user_id</td>
<td>contrib_to</td>
<td>Advertising</td>
<td>Annual_Reports</td>
<td>Leader_Content</td>
<td>first_name</td>
<td>last_name</td>
</tr>
<tr>
<td><?php echo $row_getHAUW['user_id']; ?></td>
<td><?php echo $row_getHAUW['contrib_to']; ?></td>
<td><?php echo $row_getHAUW['Advertising']; ?></td>
<td><?php echo $row_getHAUW['Annual_Reports']; ?></td>
<td><?php echo $row_getHAUW['Leader_Content']; ?></td>
<td><?php echo $row_getHAUW['first_name']; ?></td>
<td><?php echo $row_getHAUW['last_name']; ?></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($getHAUW);
?>
<?php
Any help would be greatly appreciated.
TABLE 1
h_genres
fields - h_genre_id, (primary key), user.id (foreign key), contrib._to. (text field), Advertising (set ‘Y’,’N’) and Editor (set ‘Y’,’N’)
TABLE 2
user
with fields user_id (primary key), first_name, last_name
The search form has checkboxes for the items I want to search on: Advertising and/or Editor
Here’s the code:
<form id="form1" name="search" method="post" action="results2.php">
<input type="checkbox" name="Advertising" value="Y" id="Advertising" />
<label for="checkbox">Advertising</label>
<p>
<input type="checkbox" name="Annual_Reports" value="Y" id="Annual_Reports" />
<label for="checkbox2">Annual Reports</label>
</p>
<p>
<input type="checkbox" name="Leader_Content" value="Y" id="Leader_Content" />
<label for="checkbox3">Leader</label>
</p>
<p>
<input type="submit" name="Submit" value="Submit" />
</p>
</form>
I thought I could pass the values of these inputs to a query in a POST variable. When I check the Advertising box on the search form and submit it, I see the ‘Y’ is passed to the results form.
Here’s the code from the variable dump on the results page:
<!-- BEGIN VARIABLE DUMP -->
<!-- BEGIN GET VARS -->
<!-- -->
<!-- BEGIN POST VARS -->
<!-- { Advertising = 'Y', Submit = 'Submit' } -->
In the results form I set a variable var to $_POST[‘Y’]
But all I’m getting for results are user records that are not associated with the h_genres records.
Here’s the code from the results form:
<?php require_once('../Connections/xxxx.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$var_getHAUW = "some";
if (isset($_POST['Y'])) {
$var_getHAUW = (get_magic_quotes_gpc()) ? $_POST['Y'] : addslashes($_POST['Y']);
}
mysql_select_db($database_hauw, $hauw);
$query_getHAUW = sprintf("SELECT h_genres.user_id, h_genres.contrib_to, h_genres.Advertising, h_genres.Annual_Reports, h_genres.Leader_Content, `user`.first_name, `user`.last_name FROM h_genres, `user` WHERE h_genres.user_id=`user`.user_id AND Advertising=%s", GetSQLValueString($var_getHAUW, "text"));
$getHAUW = mysql_query($query_getHAUW, $hauw) or die(mysql_error());
$row_getHAUW = mysql_fetch_assoc($getHAUW);
$totalRows_getHAUW = mysql_num_rows($getHAUW);
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table border="0">
<tr>
<td>user_id</td>
<td>contrib_to</td>
<td>Advertising</td>
<td>Annual_Reports</td>
<td>Leader_Content</td>
<td>first_name</td>
<td>last_name</td>
</tr>
<tr>
<td><?php echo $row_getHAUW['user_id']; ?></td>
<td><?php echo $row_getHAUW['contrib_to']; ?></td>
<td><?php echo $row_getHAUW['Advertising']; ?></td>
<td><?php echo $row_getHAUW['Annual_Reports']; ?></td>
<td><?php echo $row_getHAUW['Leader_Content']; ?></td>
<td><?php echo $row_getHAUW['first_name']; ?></td>
<td><?php echo $row_getHAUW['last_name']; ?></td>
</tr>
</table>
</body>
</html>
<?php
mysql_free_result($getHAUW);
?>
<?php
Any help would be greatly appreciated.
