Page 1 of 2

php form

Posted: Tue Aug 09, 2005 12:00 am
by olm75
ok i know how much PHP guys hate Dreamweaver but for some reason the form is not querying the variables..... here is the code:ex of the form at http://www.nightspotz.com/testsearch.php DW is easier for me right now im in the process of learning PHP with MySQL more SORRY forgive me......

Code: Select all

<?php require_once('../Connections/connNightspotz.php'); ?> 
<?php 
$currentPage = $_SERVER["PHP_SELF"]; 

$maxRows_rsSRCH = 10; 
$pageNum_rsSRCH = 0; 
if (isset($_GET['pageNum_rsSRCH'])) { 
$pageNum_rsSRCH = $_GET['pageNum_rsSRCH']; 
} 
$startRow_rsSRCH = $pageNum_rsSRCH * $maxRows_rsSRCH; 

$AC_rsSRCH = "1"; 
if (isset($_POST['areacode'])) { 
$AC_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['areacode'] : addslashes($_POST['areacode']); 
} 
$VN_rsSRCH = "2"; 
if (isset($_POST['venuename'])) { 
$VN_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['venuename'] : addslashes($_POST['venuename']); 
} 
$VT_rsSRCH = "3"; 
if (isset($_POST['venuetype'])) { 
$VT_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['venuetype'] : addslashes($_POST['venuetype']); 
} 
$AG_rsSRCH = "4"; 
if (isset($_POST['agegroup'])) { 
$AG_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['agegroup'] : addslashes($_POST['agegroup']); 
} 
$MT_rsSRCH = "5"; 
if (isset($_POST['musictype'])) { 
$MT_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['musictype'] : addslashes($_POST['musictype']); 
} 
mysql_select_db($database_connNightspotz, $connNightspotz); 

//-----this is the correction----------- 
$query_rsSRCH = sprintf ("SELECT * FROM venues"); 
if (!empty($_POST['venuename'])) 
{ 
  $sql .= " and VT = '" . $_POST['venuename']."' "; 
} 
if (!empty($_POST['areacode'])) 
{ 
  $sql .= " and AC = '" . $_POST['areacode']."' "; 
} 
if (!empty($_POST['venuetype'])) 
{ 
  $sql .= " and VT= '" . $_POST['venuetype']."' "; 
} 
if (!empty($_POST['agegroup'])) 
{ 
  $sql .= " and AG = '" . $_POST['agegroup']."' "; 
} 
if (!empty($_POST['musictype'])) 
{ 
  $sql .= " and MT = '" . $_POST['musictype']."' "; 
} 
//------------------------------------------- 

$query_limit_rsSRCH = sprintf("%s LIMIT %d, %d", $query_rsSRCH, $startRow_rsSRCH, $maxRows_rsSRCH); 
$rsSRCH = mysql_query($query_limit_rsSRCH, $connNightspotz) or die(mysql_error()); 
$row_rsSRCH = mysql_fetch_assoc($rsSRCH); 

if (isset($_GET['totalRows_rsSRCH'])) { 
$totalRows_rsSRCH = $_GET['totalRows_rsSRCH']; 
} else { 
$all_rsSRCH = mysql_query($query_rsSRCH); 
$totalRows_rsSRCH = mysql_num_rows($all_rsSRCH); 
} 
$totalPages_rsSRCH = ceil($totalRows_rsSRCH/$maxRows_rsSRCH)-1; 

$queryString_rsSRCH = ""; 
if (!empty($_SERVER['QUERY_STRING'])) { 
$params = explode("&", $_SERVER['QUERY_STRING']); 
$newParams = array(); 
foreach ($params as $param) { 
if (stristr($param, "pageNum_rsSRCH") == false && 
stristr($param, "totalRows_rsSRCH") == false) { 
array_push($newParams, $param); 
} 
} 
if (count($newParams) != 0) { 
$queryString_rsSRCH = "&" . htmlentities(implode("&", $newParams)); 
} 
} 
$queryString_rsSRCH = sprintf("&totalRows_rsSRCH=%d%s", $totalRows_rsSRCH, $queryString_rsSRCH); 

$queryString_rsSrch = ""; 
if (!empty($_SERVER['QUERY_STRING'])) { 
$params = explode("&", $_SERVER['QUERY_STRING']); 
$newParams = array(); 
foreach ($params as $param) { 
if (stristr($param, "pageNum_rsSrch") == false && 
stristr($param, "totalRows_rsSrch") == false) { 
array_push($newParams, $param); 
} 
} 
if (count($newParams) != 0) { 
$queryString_rsSrch = "&" . htmlentities(implode("&", $newParams)); 
} 
} 
$queryString_rsSrch = sprintf("&totalRows_rsSrch=%d%s", $totalRows_rsSrch, $queryString_rsSrch); 
?> 
<?php 
$query_venues = "DELETE FROM venue"; 
mysql_query($query_venue,$srch); 
?>

and here's how my table in the database is set up:

Code: Select all

<table name="venues"> 
 <fields> 
  <field name="v_nID" size="5" scale="0" type="int" auto_increment="auto_increment" key="PRI" default="" null="" /> 
  <field name="venuename" size="50" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="address" size="100" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="city" size="100" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="state" size="50" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="zipcode" size="10" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="country" size="50" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="areacode" size="3" scale="0" type="char" key="" default="" null="" /> 
  <field name="phonenumber" size="10" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="faxnumber" size="10" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="email" size="100" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="website" size="100" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="venuetype" size="200" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="agegroup" size="10" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="musictype" size="250" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="dresscode" size="100" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="payment" size="100" scale="0" type="varchar" key="" default="" null="" /> 
  <field name="venuelogo" type="blob" key="" default="" null="" /> 
  </fields> 
  </table>

Posted: Tue Aug 09, 2005 10:39 am
by Ambush Commander
My eyes... :cough: indent your code :cough:

Posted: Tue Aug 09, 2005 11:13 am
by Grim...
Alright, I've put on my anti-ugly glasses.

Here's a few things it would be good to know:

1. What are you trying to achieve?
2. Are you getting any errors?
3. What exactly is going wrong?

ok here it is

Posted: Wed Aug 10, 2005 12:17 am
by olm75
1st http://www.nightspotz.com/testsearch.php
can u go here and test the search out. 2cd its not querying it just shows all the records in the table when u hit submit....now im new to this programming thing but it leaves me to believe that the query is all messed up... i want this so the viewer can use any search field, or any of the fields together to get more narrow results.
so can any of u guys assist me in fixing my mess ups.....
thanks...

ok

Posted: Wed Aug 10, 2005 4:15 am
by olm75
hello is anybody there.....pulling my hair out here

ok im getting error

Posted: Wed Aug 10, 2005 5:43 am
by olm75
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home2/nightsp/public_html/search_results.php on line 104

here's the code: this is line 104: mysql_query($query_venue,$srch);

Code: Select all

<?php require_once('../Connections/connNightspotz.php'); ?> 
<?php 
$currentPage = $_SERVER["PHP_SELF"]; 

$maxRows_rsSRCH = 10; 
$pageNum_rsSRCH = 0; 
if (isset($_GET['pageNum_rsSRCH'])) { 
$pageNum_rsSRCH = $_GET['pageNum_rsSRCH']; 
} 
$startRow_rsSRCH = $pageNum_rsSRCH * $maxRows_rsSRCH; 

$areacode_rsSRCH = "1"; 
if (isset($_POST['areacode'])) { 
$areacode_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['areacode'] : addslashes($_POST['areacode']); 
} 
$venuename_rsSRCH = "2"; 
if (isset($_POST['venuename'])) { 
$venuename_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['venuename'] : addslashes($_POST['venuename']); 
} 
$venuetype_rsSRCH = "3"; 
if (isset($_POST['venuetype'])) { 
$venuetype_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['venuetype'] : addslashes($_POST['venuetype']); 
} 
$agegroup_rsSRCH = "4"; 
if (isset($_POST['agegroup'])) { 
$agegroup_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['agegroup'] : addslashes($_POST['agegroup']); 
} 
$musictype_rsSRCH = "5"; 
if (isset($_POST['musictype'])) { 
$musictype_rsSRCH = (get_magic_quotes_gpc()) ? $_POST['musictype'] : addslashes($_POST['musictype']); 
} 
mysql_select_db($database_connNightspotz, $connNightspotz); 

//-----this is the correction----------- 
$query_rsSRCH = sprintf ("SELECT * FROM venues"); 
if (!empty($_POST['venuename'])) 
{ 
  $sql .= " and venuename = '" . $_POST['venuename']."' "; 
} 
if (!empty($_POST['areacode'])) 
{ 
  $sql .= " and areacode = '" . $_POST['areacode']."' "; 
} 
if (!empty($_POST['venuetype'])) 
{ 
  $sql .= " and venuetype= '" . $_POST['venuetype']."' "; 
} 
if (!empty($_POST['agegroup'])) 
{ 
  $sql .= " and agegroup = '" . $_POST['agegroup']."' "; 
} 
if (!empty($_POST['musictype'])) 
{ 
  $sql .= " and musictype = '" . $_POST['musictype']."' "; 
} 
//------------------------------------------- 

$query_limit_rsSRCH = sprintf("%s LIMIT %d, %d", $query_rsSRCH, $startRow_rsSRCH, $maxRows_rsSRCH); 
$rsSRCH = mysql_query($query_limit_rsSRCH, $connNightspotz) or die(mysql_error()); 
$row_rsSRCH = mysql_fetch_assoc($rsSRCH); 

if (isset($_GET['totalRows_rsSRCH'])) { 
$totalRows_rsSRCH = $_GET['totalRows_rsSRCH']; 
} else { 
$all_rsSRCH = mysql_query($query_rsSRCH); 
$totalRows_rsSRCH = mysql_num_rows($all_rsSRCH); 
} 
$totalPages_rsSRCH = ceil($totalRows_rsSRCH/$maxRows_rsSRCH)-1; 

$queryString_rsSRCH = ""; 
if (!empty($_SERVER['QUERY_STRING'])) { 
$params = explode("&", $_SERVER['QUERY_STRING']); 
$newParams = array(); 
foreach ($params as $param) { 
if (stristr($param, "pageNum_rsSRCH") == false && 
stristr($param, "totalRows_rsSRCH") == false) { 
array_push($newParams, $param); 
} 
} 
if (count($newParams) != 0) { 
$queryString_rsSRCH = "&" . htmlentities(implode("&", $newParams)); 
} 
} 
$queryString_rsSRCH = sprintf("&totalRows_rsSRCH=%d%s", $totalRows_rsSRCH, $queryString_rsSRCH); 

$queryString_rsSrch = ""; 
if (!empty($_SERVER['QUERY_STRING'])) { 
$params = explode("&", $_SERVER['QUERY_STRING']); 
$newParams = array(); 
foreach ($params as $param) { 
if (stristr($param, "pageNum_rsSrch") == false && 
stristr($param, "totalRows_rsSrch") == false) { 
array_push($newParams, $param); 
} 
} 
if (count($newParams) != 0) { 
$queryString_rsSrch = "&" . htmlentities(implode("&", $newParams)); 
} 
} 
$queryString_rsSrch = sprintf("&totalRows_rsSrch=%d%s", $totalRows_rsSrch, $queryString_rsSrch); 
?> 
<?php 
$query_venues = "DELETE FROM venues"; 
mysql_query($query_venue,$srch); 
?>

Posted: Wed Aug 10, 2005 6:07 am
by shiznatix
$query_venues = "DELETE FROM venues";

that is not a valid query. you have to supply a WHERE clause to that. if you want to completly empty the table there is probebly a EMPTY thing but i dunno how to use it.

a valid query would look like

Code: Select all

DELETE FROM venues WHERE field_name = '$variable'

Posted: Wed Aug 10, 2005 7:46 am
by feyd
shiznatix wrote:that is not a valid query
pssst, no it isn't:

Code: Select all

DELETE [LOW_PRIORITY] [QUICK] [IGNORE] FROM tbl_name
       [WHERE where_definition]
       [ORDER BY ...]
       [LIMIT row_count]

Code: Select all

TRUNCATE `tableName`
will remove all rows from a table better/faster/whatever

lol

Posted: Thu Aug 11, 2005 6:18 pm
by olm75
ok what is the solution can somebody test the code and see what they get so i can get a solution to this problem......why am i getting the error from my above post.....

Posted: Fri Aug 12, 2005 5:32 am
by feyd
$connNightspotz isn't valid to MySQL.

ok so

Posted: Fri Aug 12, 2005 8:30 am
by olm75
ok so what do i use then.....can u please give me a solution...
thanks...

Posted: Fri Aug 12, 2005 8:37 am
by feyd
sorry, make that $srch.. I'd imagine, if you changed it to $connNightspotz or removed it, it should work.. this is really basic debugging...

y this error

Posted: Fri Aug 12, 2005 5:27 pm
by olm75
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near ' , venuetype, agegroup, musictype, address, FROM venues_new WH

and the query is :
mysql_select_db($database_connNightspotz, $connNightspotz);
$query_rsSRCH = sprintf("SELECT v_nID, %s, %s, venuetype, agegroup, musictype, address, %s FROM venues_new WHERE %s AND %s", $venuename_rsSRCH,$areacode_rsSRCH,$areacode_rsSRCH,$venuename_rsSRCH,$areacode_rsSRCH);
$query_limit_rsSRCH = sprintf("%s LIMIT %d, %d", $query_rsSRCH, $startRow_rsSRCH, $maxRows_rsSRCH);
$rsSRCH = mysql_query($query_limit_rsSRCH, $connNightspotz) or die(mysql_error());
$row_rsSRCH = mysql_fetch_assoc($rsSRCH);

Posted: Fri Aug 12, 2005 7:49 pm
by feyd
you must quote strings.

ok, but

Posted: Sat Aug 13, 2005 11:05 am
by olm75
you know it would be helpful if you show me what you are talking about.....