Jump to content

[SOLVED] Wierd error in MySQL...Warning: mysql_query(): supplied argument is not a valid


jwwceo

Recommended Posts

Hello,

 

I am making a pop up to give my customers a fast price quote..to do this I am using the same query that I use at another point in my site. However, when I run the query from the pop up, I get this error:

 

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in

 

The query is exactly the same as I've used in another part of my site. Everything should work fine. Any ideas?

 

James

Link to comment
Share on other sites

  $sql = "SELECT * FROM garment WHERE garment_id = '$garment'";
  $sql_result = mysql_query($sql,$connection) or die(mysql_error());
  $row = mysql_fetch_array($sql_result);
  $baseprice = $row[base_cost];

 

 

but it doesn't make sense...this is the same query I use later in my page and it works fine...

Link to comment
Share on other sites

Does it matter? The quotes don't seem to matter..the query works fine the way it is written, just in another location on my site...exactly the same....is it possible something else is going on here....

 

I tried removing the quotes and both ways I get the same error....

Link to comment
Share on other sites

I know...it's bizarre...

 

see for yourself...the form is on this page:

 

http://www.soulgear.net/index.php?option=com_content&task=view&id=2&Itemid=

 

Go to the bottom....click on fast quote....

 

hit submit...see if you get the same thing...

 

there is something bizarre going on here because the same query is used later in the page to figure out the price...

 

 

Link to comment
Share on other sites

I get the same error...

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/jwwceo/www.soulgear.net/popups/quote.php on line 75

 

there is something weird going on...I'm not getting normal errors...

 

could it be anything wrong with the connection or something????

Link to comment
Share on other sites

I didn't read the error you posted carefully but still post the script. The original error you posted is the output from the "or die mysql_error()". It refers to the mysql_query call. So to answer your question yes it could be something wrong with the "connection". The $connection variable doesn't hold the return value from a successful call to mysql_connect().

 

The addition of mysql_num_rows() should not have changed the error because the or die() portion of the script should still have run and ended the scripts execution had something been wrong as it was in your original post which is why I'm still asking that you post the script in its entirety.

 

EDIT: The error is actually a warning from PHP but the same thing applies.

Link to comment
Share on other sites

<?php

include('http://www.soulgear.net/inc/initialize.php');


$shirtselected = 'NULL';
$longsleeveselected = 'NULL';
$tankselected = 'NULL';
$crewselected = 'NULL';
$hoodieselected = 'NULL';

$whiteselected = 'NULL';
$colorselected = 'NULL';

$fc1 = 'NULL';
$fc2 = 'NULL';
$fc3 = 'NULL';
$fc4 = 'NULL';
$fc5 = 'NULL';
$fc6 = 'NULL';
$fc7 = 'NULL';
$fc8 = 'NULL';

$bc1 = 'NULL';
$bc2 = 'NULL';
$bc3 = 'NULL';
$bc4 = 'NULL';
$bc5 = 'NULL';
$bc6 = 'NULL';
$bc7 = 'NULL';
$bc8 = 'NULL';

$rc1 = 'NULL';
$rc2 = 'NULL';
$rc3 = 'NULL';
$rc4 = 'NULL';
$rc5 = 'NULL';
$rc6 = 'NULL';
$rc7 = 'NULL';
$rc8 = 'NULL';

$lc1 = 'NULL';
$lc2 = 'NULL';
$lc3 = 'NULL';
$lc4 = 'NULL';
$lc5 = 'NULL';
$lc6 = 'NULL';
$lc7 = 'NULL';
$lc8 = 'NULL';

$q1 = 'NULL';
$q2 = 'NULL';
$q3 = 'NULL';
$q4 = 'NULL';
$q5 = 'NULL';
$q6 = 'NULL';
$q7 = 'NULL';
$q8 = 'NULL';

$jw = '0';


if(isset($_POST['submit'])) {


   $garment=$_POST['garment'];
   $color=$_POST['color'];
   $frontcolors=$_POST['frontcolors'];
   $backcolors=$_POST['backcolors'];
   $rightcolors=$_POST['rightcolors'];
   $leftcolors=$_POST['leftcolors'];
   $quantity=$_POST['quantity'];

   $sql = "SELECT * FROM garment WHERE garment_id = '$garment'";
   $sql_result = mysql_query($sql,$connection) or die(mysql_error());
   $row = mysql_fetch_array($sql_resultjw);
   $baseprice = $row[base_cost];

   $sql = "SELECT * FROM garment_price WHERE garment_id = $productid[$garment] AND quantity = '$quantity'";
   $sql_result = mysql_query($sql,$connection);
   $row = mysql_fetch_array($sql_result);
   $markupamount = $row[markup];

   $sql2 = "SELECT * FROM imprint_price WHERE quantity = '$quantity'";
   $sql2_result = mysql_query($sql2,$connection);
   $row2 = mysql_fetch_array($sql2_result);
   {
   $firstlocation = $row2[price];
   $additionalcolor = $row2[color_price];
   $additionallocation = $row2[location_price];
   }

   $sql3 = "SELECT * FROM garment_color WHERE color_id = '$color'";
   $sql3_result = mysql_query($sql3,$connection);
   $row3 = mysql_fetch_array($sql3_result);
   $colorcost = $row3[color_option_cost];
   $cost2XL = $row3['2XL_option_cost'] * $quantity_2XL;
   $cost3XL = $row3['3XL_option_cost'] * $quantity_3XL;
   $cost4XL = $row3['4XL_option_cost'] * $quantity_4XL;
   $cost5XL = $row3['5XL_option_cost'] * $quantity_5XL;

   if ($frontcolors)
   {
   if (!$locations)
   {
   $locations ++;
   }
   else
   {
   $additionallocations ++;
   }
   if ($frontcolors>1)
   {
   $additionalcolors += ($frontcolors -1);
   }
   }
   if ($backcolors)
   {
   if (!$locations)
   {
   $locations ++;
   }
   else
   {
   $additionallocations ++;
   }
   if ($backcolors>1)
   {
   $additionalcolors += ($backcolors -1);
   }
   }
   if ($leftcolors)
   {
   if (!$locations)
   {
   $locations ++;
   }
   else
   {
   $additionallocations ++;
   }
   if ($leftcolors>1)
   {
   $additionalcolors += ($leftcolors -1);
   }
   }
   if ($rightcolors)
   {
   if (!$locations)
   {
   $locations ++;
   }
   else
   {
   $additionallocations ++;
   }
   if ($rightcolors>1)
   {
   $additionalcolors += ($rightcolors -1);
   }
   }

   $thisprice = $baseprice + ($baseprice * $markupamount/100) + $colorcost;
   $thisprice += ($locations * $firstlocation) + ($additionallocations * $additionallocation) + ($additionalcolors * $additionalcolor);
   $thissubtotal = $thisprice * $quantity;
   $sizeprices = $cost2XL + $cost3XL + $cost4XL + $cost5XL;
   $thistotalprice = ($thisprice * $quantity) + $sizeprices;
   $thisprice = number_format(round($thisprice, 2),2);
   $sizeprices = number_format(round($sizeprices, 2),2);
   $thissubtotal = number_format(round($thissubtotal, 2),2);
   $thistotalprice = number_format(round($thistotalprice, 2),2);








         echo $garment;
         echo $color;
         echo $frontcolors;
         echo $backcolors;
         echo $rightcolors;
         echo $leftcolors;
         echo $quantity;
         echo $baseprice;

   }



if ($garment =='1'){$shirtselected  = 'SELECTED';}
if ($garment =='2'){$longsleeveselected  = 'SELECTED';}
if ($garment =='5'){$tankselected  = 'SELECTED';}
if ($garment =='4'){$crewselected  = 'SELECTED';}
if ($garment =='3'){$hoodieselected  = 'SELECTED';}

if ($color =='50'){$whiteselected = 'SELECTED';}
if ($color =='34'){$coloredselected = 'SELECTED';}

if ($frontcolors == '1'){$fc1 = 'SELECTED';}
if ($frontcolors == '2'){$fc2 = 'SELECTED';}
if ($frontcolors == '3'){$fc3 = 'SELECTED';}
if ($frontcolors == '4'){$fc4 = 'SELECTED';}
if ($frontcolors == '5'){$fc5 = 'SELECTED';}
if ($frontcolors == '6'){$fc6 = 'SELECTED';}
if ($frontcolors == '7'){$fc7 = 'SELECTED';}
if ($frontcolors == '8'){$fc8 = 'SELECTED';}

if ($backcolors == '1'){$bc1 = 'SELECTED';}
if ($backcolors == '2'){$bc2 = 'SELECTED';}
if ($backcolors == '3'){$bc3 = 'SELECTED';}
if ($backcolors == '4'){$bc4 = 'SELECTED';}
if ($backcolors == '5'){$bc5 = 'SELECTED';}
if ($backcolors == '6'){$bc6 = 'SELECTED';}
if ($backcolors == '7'){$bc7 = 'SELECTED';}
if ($backcolors == '8'){$bc8 = 'SELECTED';}

if ($rightcolors == '1'){$rc1 = 'SELECTED';}
if ($rightcolors == '2'){$rc2 = 'SELECTED';}
if ($rightcolors == '3'){$rc3 = 'SELECTED';}
if ($rightcolors == '4'){$rc4 = 'SELECTED';}
if ($rightcolors == '5'){$rc5 = 'SELECTED';}
if ($rightcolors == '6'){$rc6 = 'SELECTED';}
if ($rightcolors == '7'){$rc7 = 'SELECTED';}
if ($rightcolors == '8'){$rc8 = 'SELECTED';}

if ($leftcolors == '1'){$lc1 = 'SELECTED';}
if ($leftcolors == '2'){$lc2 = 'SELECTED';}
if ($leftcolors == '3'){$lc3 = 'SELECTED';}
if ($leftcolors == '4'){$lc4 = 'SELECTED';}
if ($leftcolors == '5'){$lc5 = 'SELECTED';}
if ($leftcolors == '6'){$lc6 = 'SELECTED';}
if ($leftcolors == '7'){$lc7 = 'SELECTED';}
if ($leftcolors == '8'){$lc8 = 'SELECTED';}

if ($quantity == '144'){$q1 = 'SELECTED';}
if ($quantity == '250'){$q2 = 'SELECTED';}
if ($quantity == '500'){$q3 = 'SELECTED';}
if ($quantity == '1000'){$q4 = 'SELECTED';}
if ($quantity == '2000'){$q5 = 'SELECTED';}
if ($quantity == '3000'){$q6 = 'SELECTED';}
if ($quantity == '5000'){$q7 = 'SELECTED';}
if ($quantity == '10000'){$q8 = 'SELECTED';}


      echo $garment;
      echo $color;
      echo $frontcolors;
      echo $backcolors;
      echo $rightcolors;
      echo $leftcolors;
      echo $quantity;






print<<<EOF

<html>
<head>
<title>SoulGear.com -Fast Quote</title>
<link href="http://www.soulgear.net/inc/style.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
<!--
focus();
//-->
</script>
</head>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" bgcolor="#FFFFFF" background="http://www.vectortees.com/images/popupbg.gif">
<script language="JavaScript">
<!--
function ChooseSize(id) {
window.opener.document.productForm.elements["options[2]"].selectedIndex = id;
self.close();
}
//-->
</script>

<center>
<table border=0 cellpadding=0 cellspacing=0 width=480>
<tr>
<td colspan='2'><img src="images/clear.gif" width=1 height=15></td>
</tr>
<tr valign=top>
<td><img src="http://www.vectortees.com/images/title_sizing_chart.gif" width=204 height=22></td>
<td align=right><a href="javascript:self.close()"><img src="http://www.vectortees.com/images/closewindow.gif" width=84 height=11 border=0></td>
</tr>
<tr>
<td colspan='2'><img src="images/clear.gif" width=1 height=8></td>
</tr>
<tr>
<td colspan=2 align=center>
<table border=0 cellpadding=3 cellspacing=0 width=450>
<tr>
<td>
<table border=0 cellpadding=4 cellspacing=1>
<tr>
<td class="sizingwhite" colspan='4'>MEASUREMENT (INCHES)</td>
</tr>
<tr>

<form name="quoteform" method="post" action="http://www.soulgear.net/popups/quote.php">

<td class="sizingblue"> Style</td>
<td class="sizingblue">
  <select name="garment">
    <option value="1" {$shirtselected}>Basic 6.1 oz Tee</option>
    <option value="2" {$longsleeveselected}>6.1 oz Long Sleeve Tee</option>
    <option value="5" {$tankselected}>6.1 oz Tank Top</option>
    <option value="3" {$hoodieselected}>10 oz. Hooded Sweatshirt</option>
    <option value="4" {$crewselected}>10. oz Crew Neck Sweatshirt</option>
  </select></td>
<td class="sizingblue">Color</td>
<td>

<select name="color">
    <option value="50" {$whiteselected}>White</option>
    <option value="34" {$coloredselected}>Colored</option>
  </select></td>
</tr>
<tr >
<td class="sizingblue" colspan='4'>Please enter the number of ink colors for each location</td>
</tr>
<tr >
<td class="sizingblue" colspan='4'>
<table border='1'>
<tr>
<td>Front:</td>
<td>Back:</td>
<td>Right Sleeve:</td>
<td>Left Sleeve:</td>
</tr>
<tr>
<td width="25%">
  <select name="frontcolors">
    <option value="1" {$fc1}>1</option>
    <option value="2" {$fc2}>2</option>
    <option value="3" {$fc3}>3</option>
    <option value="4" {$fc4}>4</option>
    <option value="5" {$fc5}>5</option>
    <option value="6" {$fc6}>6</option>
    <option value="7" {$fc7}>7</option>
    <option value="8" {$fc8}>8</option>
  </select>
</td>
<td width="25%">
  <select name="backcolors">
        <option value="1" {$bc1}>1</option>
    <option value="2" {$bc2}>2</option>
    <option value="3" {$bc3}>3</option>
    <option value="4" {$bc4}>4</option>
    <option value="5" {$bc5}>5</option>
    <option value="6" {$bc6}>6</option>
    <option value="7" {$bc7}>7</option>
        <option value="8" {$bc8}>8</option>
  </select>
</td>
<td width="25%">
  <select name="rightcolors">
        <option value="1" {$rc1}>1</option>
    <option value="2" {$rc2}>2</option>
    <option value="3" {$rc3}>3</option>
    <option value="4" {$rc4}>4</option>
    <option value="5" {$rc5}>5</option>
    <option value="6" {$rc6}>6</option>
    <option value="7" {$rc7}>7</option>
        <option value="8" {$rc8}>8</option>
  </select>
</td>
<td width="25%">
  <select name="leftcolors">
        <option value="1" {$lc1}>1</option>
    <option value="2" {$lc2}>2</option>
    <option value="3" {$lc3}>3</option>
    <option value="4" {$lc4}>4</option>
    <option value="5" {$lc5}>5</option>
    <option value="6" {$lc6}>6</option>
    <option value="7" {$lc7}>7</option>
        <option value="8" {$lc8}>8</option>
  </select>
</td>
</tr>
</table>




</td>

</tr>
<tr>
<td class="sizingblue" colspan='4'>Quantity:

<select name="quantity">
    <option value="144" {$q1}>144</option>
    <option value="250" {$q2}>250</option>
    <option value="500" {$q3}>500</option>
    <option value="1000" {$q4}>1000</option>
    <option value="2000" {$q5}>2000</option>
    <option value="3000" {$q6}>3000</option>
    <option value="5000" {$q7}>5,000</option>
    <option value="10000" {$q8}>10,000</option>
  </select><input type="submit" name="submit" value="submit" ></td>


</tr>

</table></td>

</tr>
</form>
<tr>
<td>
Your Price:  $0.00
</td>
</tr>



<tr>
<td class="sizingblue" colspan='2'>
<p><img src="http://www.vectortees.com/images/bluearrow.gif" width=8 height=10>Free Professional Custom Artwork<br>
<img src="http://www.vectortees.com/images/bluearrow.gif" width=8 height=10>Free Shipping in the USA<br>
<img src="http://www.vectortees.com/images/bluearrow.gif" width=8 height=10>Free PDF Proof<br>
<img src="http://www.vectortees.com/images/bluearrow.gif" width=8 height=10>Low Price Guarantee</p>
</td>
</tr>
</table></td>
</tr>
</table>

</body>
</html>
EOF;




?>

Link to comment
Share on other sites

You should be including the file "initialize.php" using the filesystem path.

include($_SERVER['DOCUMENT_ROOT'].'/inc/initialize.php');

 

Assuming "initialize.php" holds the relevant mysql_connect call with the appropriate checks as to the success or failure of the connection, the query should now work as expected. You should still use mysql_num_rows in the way I explained however.

 

If you have further difficulties put the following at the top of your script as well.

 

error_reporting(E_ALL);

 

Link to comment
Share on other sites

Note first that using what I posted you're using the absolute filesystem path to the file.

 

Using

include('http://www.soulgear.net/inc/initialize.php');

 

You include the file through the webserver which means that initialize.php is parsed as any php file would first by the webserver and only the output is included in your file. The same as if someone used a web browser to navigate to your script.

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.