Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 11th, 2008, 11:43 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problem with passing variable in php 5

Hi,

I'm stumped and hope someone here can help me

I have a php page with a search form that capture 2 variables 'where' and 'what'

I use a form on that page and capture the values in the form and pass them through the url to the search results page that queries my table and echoes back the search results.

Code:
<form action="advsearchresults.php" method="get">
The search results page is not providing any records when I know they exit. I see the variables in the ensuing url

I editing the query and swapped literal text for the variables and the query ran and echoed the records back. But it won't process the variables. Here is the top section of my code. I have tried everything and cannot figure it out. It worked previously in php 4 but stopped when the host upgraded to php 5

Code:
<?php require_once('Connections/dbh.php'); ?>
<?php
$maxRows_Recordset1 = 100;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

$colname_Recordset1 = "1";
if (isset($_POST[''])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST[''] : addslashes($_POST['']);
}

/* Test $what  & $where$GETVARs for empty. If either are empty, return to main page.
 * Not classy, but more graceful than MySQL error.
 */
if (!isset($_GET['what']) || !isset($_GET['where'] ))  {
    header("Location: index.php");
    exit();
    }

mysql_select_db($database_piercin, $dbh);
$query_Recordset1 = sprintf("SELECT * FROM gallery WHERE $_GET['where'] LIKE $_GET['what'] ORDER BY artist ASC", $colname_Recordset1);
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $dbh) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>
I also used to have wildcards in the 'what' of % and not sure if that would still work or not. I'm willing to up the "containing" and make people search for complete but would love to put that functionality back in also.

Thanks in advance.

Joy

 
Old July 14th, 2008, 12:05 PM
Friend of Wrox
 
Join Date: Dec 2003
Posts: 488
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Can you post the whole html form?

What is this trying to do:

$colname_Recordset1 = "1";
if (isset($_POST[''])) {
  $colname_Recordset1 = (get_magic_quotes_gpc()) ? $_POST[''] : addslashes($_POST['']);
}

We already know that your form is doing a GET, so this will always be "1".

--
Charlie Harvey's website - linux, perl, java, anarchism and punk rock: http://charlieharvey.org.uk





Similar Threads
Thread Thread Starter Forum Replies Last Post
passing php variable to perl nriv08 PHP How-To 0 March 27th, 2008 10:38 AM
Passing javascript variable to html or php ashraf_gawdat Javascript How-To 3 July 12th, 2006 02:48 PM
Problem passing multiple arguments to php script method PHP How-To 0 February 8th, 2006 09:03 AM
passing php variable to javascript and vice versa onmcv Beginning PHP 0 March 24th, 2005 01:00 PM
Passing variable to a public variable Hudson40 Access VBA 2 February 25th, 2005 06:23 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.