Re: how to search recordset
Posted: Thu Jan 20, 2011 4:16 pm
connects to my server. without it nothing works
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
<?php
<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
// the comment variables yielded the error until i typed
// them out. The commented section is the original
// values, below them is the 'new' typed out version
/*
$businesscategory = addslashes($_GET['businesscategory']);
$businesscategory2 = addslashes($_GET['businesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$state = addslashes($_GET['statecounty']);
$county = addslashes($_GET['statecounty']);
$country = addslashes($_GET['country']);*/
$businesscategory = addslashes($_GET['businesscategory']);
// change this variable name -- POINT 1
$businesscategory = addslashes($_GET['businesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$state = addslashes($_GET['statecounty']);
$county = addslashes($_GET['statecounty']);
$country = addslashes($_GET['country']);
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory = '". mysql_real_escape_string($businesscategory) ."' AND
businessname = '". mysql_real_escape_string($businessname) ."' AND townborough =
'". mysql_real_escape_string($townborough) ."' AND city = '". mysql_real_escape_string($city) ."' ";
// purpose of this -- POINT 2
$sql = mysql_query($query);
$businessdetails = mysql_query($query_businessdetails, $recommendingpeople) or die(mysql_error());
$row_businessdetails = mysql_fetch_assoc($businessdetails);
$totalRows_businessdetails = mysql_num_rows($businessdetails);
mysql_free_result($businessdetails);
?>
<?php echo $row_businessdetails['userid']; ?>
<p><?php echo $row_businessdetails['street']; ?></p>
<p><?php echo $row_businessdetails['businesscategory']; ?></p>
<p><?php echo $row_businessdetails['numbername']; ?></p>
<p><?php echo $row_businessdetails['businessname']; ?></p>
<p><?php echo $row_businessdetails['townborough']; ?></p>
<p><?php echo $row_businessdetails['city']; ?></p>
<p><?php echo $row_businessdetails['county']; ?></p>
<p><?php echo $row_businessdetails['state']; ?></p>
<p><?php echo $row_businessdetails['postcode']; ?></p>
<p><?php echo $row_businessdetails['tel1']; ?></p>
?>Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>
<?php $businesscategory = addslashes($_GET['businesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$statecounty = addslashes($_GET['statecounty']);
$country = addslashes($_GET['country']);
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory = '". mysql_real_escape_string($businesscategory) ."' OR businesscategory = '". mysql_real_escape_string($businesscat)."'
AND businessname = '". mysql_real_escape_string($businessname) ."' AND townborough =
'". mysql_real_escape_string($townborough) ."' AND city = '". mysql_real_escape_string($city) ."' ";
$result = mysql_query($query, $recommendingpeople) or die(mysql_error());
$row = mysql_fetch_assoc($result);
$totalRows_businessdetails = mysql_num_rows($businessdetails);
if (!$result) {
echo "Got nothing";
} else {
echo $row_businessdetails['userid']; ?>
<p><?php echo $row_businessdetails['street']; ?></p>
<p><?php echo $row_businessdetails['businesscategory']; ?></p>
<p><?php echo $row_businessdetails['numbername']; ?></p>
<p><?php echo $row_businessdetails['businessname']; ?></p>
<p><?php echo $row_businessdetails['townborough']; ?></p>
<p><?php echo $row_businessdetails['city']; ?></p>
<p><?php echo $row_businessdetails['county']; ?></p>
<p><?php echo $row_businessdetails['state']; ?></p>
<p><?php echo $row_businessdetails['postcode']; ?></p>
<p><?php echo $row_businessdetails['tel1']; ?></p>
}
<?php mysql_free_result($businessdetails);?>Is it an sql error? (If you do receive an sql error please paste ittimoteo wrote:The error gets throught to line 17 which is the $query
Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
// the comment variables yielded the error until i typed
// them out. The commented section is the original
// values, below them is the 'new' typed out version
/*
$businesscategory = addslashes($_GET['businesscategory']);
$businesscategory2 = addslashes($_GET['businesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$state = addslashes($_GET['statecounty']);
$county = addslashes($_GET['statecounty']);
$country = addslashes($_GET['country']);*/
$businesscategory = addslashes($_GET['businesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$state = addslashes($GET_['statecounty']);
$county = addslashes($_GET['county']);
$country = addslashes($_GET['country']);
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory = '". mysql_real_escape_string($businesscategory) ."' AND
businessname = '". mysql_real_escape_string($businessname) ."' AND townborough =
'". mysql_real_escape_string($townborough) ."' AND city = '". mysql_real_escape_string($city) ."' AND state = '". mysql_real_escape_string($state) ."'
AND county = '". mysql_real_escape_string($county) . "' AND country = '". mysql_real_escape_string($country)."'";
$businessdetails = mysql_query($query_businessdetails, $recommendingpeople) or die(mysql_error());
$row_businessdetails = mysql_fetch_assoc($businessdetails);
$totalRows_businessdetails = mysql_num_rows($businessdetails);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?php echo $row_businessdetails['userid']; ?>
<p><?php echo $row_businessdetails['street']; ?></p>
<p><?php echo $row_businessdetails['businesscategory']; ?></p>
<p><?php echo $row_businessdetails['numbername']; ?></p>
<p><?php echo $row_businessdetails['businessname']; ?></p>
<p><?php echo $row_businessdetails['townborough']; ?></p>
<p><?php echo $row_businessdetails['city']; ?></p>
<p><?php echo $row_businessdetails['county']; ?></p>
<p><?php echo $row_businessdetails['state']; ?></p>
<p><?php echo $row_businessdetails['postcode']; ?></p>
<p><?php echo $row_businessdetails['tel1']; ?></p>
</body>
</html>
<?php mysql_free_result($businessdetails);?>Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
$businessname_businessdetails = "1";
if (isset($_GET['businessname'])) {
$businessname_businessdetails = (get_magic_quotes_gpc()) ? $_GET['businessname'] : addslashes($_GET['businessname']);
}
$country_businessdetails = "1";
if (isset($_GET['country'])) {
$country_businessdetails = (get_magic_quotes_gpc()) ? $_GET['country'] : addslashes($_GET['country']);
}
$state_businessdetails = "1";
if (isset($_GET['state'])) {
$state_businessdetails = (get_magic_quotes_gpc()) ? $_GET['state'] : addslashes($_GET['state']);
}
$businesscategory_businessdetails = "1";
if (isset($_GET['businesscategory'])) {
$businesscategory_businessdetails = (get_magic_quotes_gpc()) ? $_GET['businesscategory'] : addslashes($_GET['businesscategory']);
}
$townborough_businessdetails = "1";
if (isset($_GET['townborough'])) {
$townborough_businessdetails = (get_magic_quotes_gpc()) ? $_GET['townborough'] : addslashes($_GET['townborough']);
}
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query_businessdetails = sprintf("SELECT * FROM businessdetails WHERE %s = '%s' OR %s = '%s' OR %s = '%s' OR %s = '%s' OR %s = '%s'", $businesscategory_businessdetails,$businesscategory_businessdetails,$businessname_businessdetails,$businessname_businessdetails,$townborough_businessdetails,$townborough_businessdetails,$state_businessdetails,$state_businessdetails,$country_businessdetails,$country_businessdetails);
$businessdetails = mysql_query($query_businessdetails, $recommendingpeople) or die(mysql_error());
$row_businessdetails = mysql_fetch_assoc($businessdetails);
$totalRows_businessdetails = mysql_num_rows($businessdetails);
?><?php
echo $row_businessdetails['userid']; ?>
<p><?php echo $row_businessdetails['street']; ?></p>
<p><?php echo $row_businessdetails['businesscategory']; ?></p>
<p><?php echo $row_businessdetails['numbername']; ?></p>
<p><?php echo $row_businessdetails['businessname']; ?></p>
<p><?php echo $row_businessdetails['townborough']; ?></p>
<p><?php echo $row_businessdetails['city']; ?></p>
<p><?php echo $row_businessdetails['county']; ?></p>
<p><?php echo $row_businessdetails['state']; ?></p>
<p><?php echo $row_businessdetails['postcode']; ?></p>
<p><?php echo $row_businessdetails['tel1']; ?></p>
<?php mysql_free_result($businessdetails);?>and sometimes this:An appropriate representation of the requested resource /testing.php could not be found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
. ('m' being data in my db)Unknown column 'm' in where clause
timoteo wrote:The error gets throught to line 17 which is the $query.
There is no variable $businesscat definedtimoteo wrote:Code: Select all
$businesscategory = addslashes($_GET['businesscat']); $businessname = addslashes($_GET['businessname']); $townborough = addslashes($_GET['townorborough']); $city = addslashes($_GET['city']); $statecounty = addslashes($_GET['statecounty']); $country = addslashes($_GET['country']); $query = "SELECT * FROM businessdetails WHERE businesscategory = '". mysql_real_escape_string($businesscategory) ."' OR businesscategory = '". mysql_real_escape_string($businesscat)."' AND businessname = '". mysql_real_escape_string($businessname) ."' AND townborough = '". mysql_real_escape_string($townborough) ."' AND city = '". mysql_real_escape_string($city) ."' ";
lol @ line 3, this is a comment?! wtf.timoteo wrote:Parse error: syntax error, unexpected T_STRING in /home/biomagn1/public_html/recommendingpeople.com/testing1.php on line 3
Code: Select all
"SELECT * FROM businessdetails WHERE businesscategory = 'plumber';"Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>
<?php
$businesscategory = "b";
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory = '$businesscategory';";
$result = mysql_query($query, $recommendingpeople) or die(mysql_error());
$row_businessdetails = mysql_fetch_assoc($businessdetails);
$row = mysql_fetch_assoc($result);
if (!$result) {
echo "Got nothing";
} else {
echo $row['businesscategory'];
?>
<?php echo $row_businessdetails['userid']; ?>
<p><?php echo $row_businessdetails['street']; ?></p>
<p><?php echo $row_businessdetails['businesscategory']; ?></p>
<p><?php echo $row_businessdetails['numbername']; ?></p>
<p><?php echo $row_businessdetails['businessname']; ?></p>
<p><?php echo $row_businessdetails['townborough']; ?></p>
<p><?php echo $row_businessdetails['city']; ?></p>
<p><?php echo $row_businessdetails['county']; ?></p>
<p><?php echo $row_businessdetails['state']; ?></p>
<p><?php echo $row_businessdetails['postcode']; ?></p>
<p><?php echo $row_businessdetails['tel1']; ?></p>
</body>
</html>
<?php mysql_free_result($businessdetails);?>Code: Select all
$database_recommendingpeople, $recommendingpeople
Code: Select all
$row_businessdetails = mysql_fetch_assoc($businessdetails);Code: Select all
<?php
//connect to the database here, change these please
$dbhost = 'localhost';
$dbname = 'your db name';
$dbuser = 'your db username';
$dbpass = 'your db password';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db($dbname, $conn);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
$businesscategory = 'b';
$query = "SELECT * FROM businessdetails WHERE businesscategory='$businesscategory';";
$result = mysql_query($query);
if (!$result) {
echo "Got nothing";
} else {
// need the while statement as there is the possibility of more than one row returned
while ($row = mysql_fetch_array($result, MYSQL_ASSOC) {
echo $row['userid'] . '<br />';
echo $row['street'] . '<br />';
echo $row['businesscategory'] . '<br />';
echo $row['numbername'] . '<br />';
echo $row['businessname'] . '<br />';
echo 'That was a result set' . '<br />';
}
}
?>
Code: Select all
<?php
require_once('Connections/recommendingpeople.php');
// I have put this equal to 'french' I assume that this is a valid username in rsusername, if not please change!
$businesscategory = addslashes($_GET['selectbusinesscat']);
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory='$businesscategory';";
$result = mysql_query($query, $recommendingpeople) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if (!$result) {
echo "Got nothing";
} else {
echo $row['country'];
}
?>
Code: Select all
<?php
require_once('Connections/recommendingpeople.php');
$businesscategory = addslashes($_GET['businesscategory']);
$businesscat = addslashes($_GET['selectbusinesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$state = addslashes($_GET['statecounty']);
$county = addslashes($_GET['statecounty']);
$country = addslashes($_GET['country']);
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory = '$businesscat' OR businesscategory='$businesscategory' OR businessname = '$businessname' OR townborough = '$townborough' OR city = '$city' OR state = '$statecounty' OR county = '$county' OR country = '$country';";
$result = mysql_query($query, $recommendingpeople) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if (!$result) {
echo "Got nothing";
} else {
echo $row['country'];
echo $row['businesscategory'];
echo $row['businessname'];
echo $row['numbername'];
echo $row['street'];
echo $row['townborough'];
echo $row['city'];
echo $row['county'];
echo $row['state'];
echo $row['country'];
echo $row['postcode'];
echo $row['country'];
}
?>
Code: Select all
<?php require_once('Connections/recommendingpeople.php'); ?>$maxRows = 10;
$pageNum = 0;
if (isset($_GET['pageNum'])) {
$pageNum = $_GET['pageNum'];
}
$startRow = $pageNum * $maxRows;
$businesscategory = addslashes($_GET['businesscategory']);
$businesscat = addslashes($_GET['selectbusinesscat']);
$businessname = addslashes($_GET['businessname']);
$townborough = addslashes($_GET['townorborough']);
$city = addslashes($_GET['city']);
$state = addslashes($_GET['statecounty']);
$county = addslashes($_GET['statecounty']);
$country = addslashes($_GET['country']);
mysql_select_db($database_recommendingpeople, $recommendingpeople);
$query = "SELECT * FROM businessdetails WHERE businesscategory = '$businesscat' OR businesscategory='$businesscategory' OR businessname = '$businessname' OR townborough = '$townborough' OR city = '$city' OR state = '$statecounty' OR county = '$county' OR country = '$country';";
$result = mysql_query($query, $recommendingpeople) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if (isset($_GET['totalRows'])) {
$totalRows = $_GET['totalRows'];
} else {
$all = mysql_query($query);
$totalRows = mysql_num_rows($all);
}
$totalPages = ceil($totalRows/$maxRows)-1;
<form name="form2" method="post" action="">
<table width="60%" border="10" align="center" cellspacing="10" bgcolor="#FFFFFF">
<tr>
<td class="style8">You searched for: </td>
</tr>
<tr>
<td><?php echo $_GET['businesscategory']?>
<?php echo $_GET['selectbusinesscat']?>
<?php echo $_GET['townorborough']?>
<?php echo $_GET['city']?>
<?php echo $_GET['statecounty']?>
<?php echo $_GET['country']?>
</td>
</tr>
</table>
<p> </p>
<table width="80%" border="10" align="center" cellspacing="10" bgcolor="#FFFFFF" id="results">
<tr class="style8">
<td> </td>
<td>Business:</td>
<td colspan="2">Address:</td>
<td>e-mail, telephone </td>
</tr>
<tr>
<?php do { ?>
<td> </td>
<td><?php echo $row['businesscategory']?></td>
<td><?php echo $row['numbername']?></td>
<td><?php echo $row['street']?></td>
<td><?php echo $row['tel1']?></td>
</tr>
<tr>
<td> </td>
<td><?php echo $row['businessname']?></td>
<td><?php echo $row['townborough']?></td>
<td><?php echo $row['city']?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><?php echo $row['county']?></td>
<td><?php echo $row['state']?></td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><?php echo $row['postcode']?></td>
<td><?php echo $row['country']?></td>
<td> </td>
</tr>
<?php } while ($row_rsrecommendations = mysql_fetch_assoc($rsrecommendations)); ?>
</table>
</form>
?>Code: Select all
<?php } while ($row_rsrecommendations = mysql_fetch_assoc($rsrecommendations)); ?>Code: Select all
<?php } while ($row = mysql_fetch_assoc($result)); ?>