Jump to content

MySQL PHP Form Query not working


iceblox

Recommended Posts

Hi Everyone,

 

Ive been working on this new site and the form page has about 7 different drop downs on it and they all go to the same results page so my Query looks abit tricky. I thought i had it but i keep getting an error.

 

The error is

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/yoursite.com/httpdocs/mobile-phone-deals/deals_new.php on line 13

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /usr/local/psa/home/vhosts/yoursite.com/httpdocs/mobile-phone-deals/deals_new.php on line 137

 

and this is the result page query

 

$query = "SELECT * FROM deals WHERE NetworkName = '$_POST[NetworkName]' AND PhoneCost BETWEEN 0 AND '$_POST[PhoneCost]' AND ContractLength  BETWEEN 0 AND '$_POST[ContractLength]' AND FreeMins BETWEEN '$_POST[FreeMins]' AND 9999 AND FreeTexts BETWEEN '$_POST[FreeTexts]' AND 9999";

$result = mysql_query($query);

 

Any ideas?

Link to comment
Share on other sites

try this

<?php

$query = "SELECT * FROM deals WHERE NetworkName = '{$_POST['NetworkName']}' AND PhoneCost BETWEEN 0 AND '{$_POST['PhoneCost']}' AND ContractLength  BETWEEN 0 AND '{$_POST['ContractLength']}' AND FreeMins BETWEEN '{$_POST['FreeMins']}' AND 9999 AND FreeTexts BETWEEN '{$_POST['FreeTexts']}' AND 9999";

$result = mysql_query($query) or die(mysql_error());
?>

Link to comment
Share on other sites

Thanks MADTechie used that code and found the error. Missed typed one of the columns! LoL

 

 

Can i ask you one other thing in my drop down it gives me the option to select "ANY" so lets say Network they can either specify the network or view the deals from all the networks how would this be coded in?

Link to comment
Share on other sites

i would probably code it like this

 

<?php
$network = ($_POST['NetworkName'] != "Any")?"NetworkName = '{$_POST['NetworkName']}' AND ":"";
$query = "SELECT * FROM deals WHERE $network PhoneCost BETWEEN 0 AND '{$_POST['PhoneCost']}' AND ContractLength  BETWEEN 0 AND '{$_POST['ContractLength']}' AND FreeMins BETWEEN '{$_POST['FreeMins']}' AND 9999 AND FreeTexts BETWEEN '{$_POST['FreeTexts']}' AND 9999";
?>

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.