View Full Version : MySQL/php error
ph0t0man
03-29-2008, 05:16 PM
Hi folks,
I just migrated my website from fatcow over to bluehost. I was having phpMyAdmin connection problems for 4 months, and they never were able to fix the problem. After many false promises, and a ticket being open for days without a response, I decided it was time to move on. Timing couldn't have been better - my account expired 3/31 with them...
I had a few initial hiccups, but I've gotten most everything transferred over without a problem. However, I'm having one issue that I cannot resolve with my limited php/MySQL experience. So, here it is:
Here is the page that uses the php code, and as of right now is outputting an error:
http://www.alphalensrental.com/lensdetail.php?lensid=20
The error reads:
Error in result1: 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 '' at line 1
The php code in that section is:
$query1 = "SELECT LensID, LensType, LensName, numberowned, instock, 1week, 2week, 3week, ship, deposit, focalwide, focaltele, apmax, apmin, filtersize, weight, minfoc, length, make, lenswarning, lensdescription FROM lenslist WHERE LensID=$lensid" or die ('Error in query1: '. mysql_error());
$result1 = mysql_query($query1) or die ('Error in result1: '. mysql_error());
The odd thing is, this code was running fine on my old host. The only thing I've changed since the switch-over is the or die part, so that it now outputs the error message to my web page. I know I am connecting to the database fine as this page works just fine, and uses the same connector and loginconfig files:
http://www.alphalensrental.com/lens.php
Any help with the syntax problem would be greatly appreciated. And yes, I know my site needs a little help on the graphic design side :)
If you need more of the php code, just let me know...
Thanks in advance for any help!!!
TheWebHostingHero
03-29-2008, 06:50 PM
There's no use for the "or die..." part on the first line that's for sure.
$query1 = "SELECT LensID, LensType, LensName, numberowned, instock, 1week, 2week, 3week, ship, deposit, focalwide, focaltele, apmax, apmin, filtersize, weight, minfoc, length, make, lenswarning, lensdescription FROM lenslist WHERE LensID = '$lensid'";
$result1 = mysql_query($query1) or die ('Error in result1: '. mysql_error());
You could also try to echo the value of $query1 and copy the SQL query to phpMyAdmin to see if it works.
ph0t0man
03-29-2008, 07:22 PM
There's no use for the "or die..." part on the first line that's for sure.
removed.
You could also try to echo the value of $query1 and copy the SQL query to phpMyAdmin to see if it works.
echoing $query1 only outputs exactly what I am inputing...
I've found one error in my code, but now that it is fixed, nothing is happening :/ Error somewhere else in my php code? The error I tracked down was ...WHERE LensID='$lensid'"; I had left out the ' ' when I originally wrote the code. I don't know enough to know why it wasn't a problem before.
The entire php code for this page now reads:
<?php
include 'loginconfig.php';
include 'connector.php';
$query1 = "SELECT LensID, LensType, LensName, numberowned, instock, 1week, 2week, 3week, ship, deposit, focalwide, focaltele, apmax, apmin, filtersize, weight, minfoc, length, make, lenswarning, lensdescription FROM lenslist WHERE LensID='$lensid'";
$result1 = mysql_query($query1) or die ('Error in result1: '. mysql_error());
while($row = mysql_fetch_assoc($result1)) {
echo "<TABLE class=\"alr\" width=900><TR><TD vAlign=top align=center width=90%>".
"<TABLE class=\"alr3\" width=100%><TR><TD vAlign=top align=center width=350 colSpan=1 rowSpan=1>".
"<P><BIG><span>{$row['LensName']}</span></BIG></P></TD><TD><P align=center><FONT size=5><B>";
if ($row['instock'] == 1){
echo "<B>In Stock: <FONT size=5 COLOR=Green>Yes</FONT></B>";
}
else{
echo "<B>In Stock: <FONT size=5 COLOR=Gray>No</FONT></B>";
}
echo"</span></P>".
"</TD></TR><TR><TD vAlign=top align=center width=350><P><BIG></BIG><P><a><A HREF=http://www.alphalensrental.com/lensdetail.php?lensid={$row['LensID']} class=\"highlightit\"><img src=http://www.alphalensrental.com/lensimages/400/{$row['LensID']}.jpg></a></P>".
"</TD><TD><P align=center><FONT size=4>".
"<B>1week: $ {$row['1week']}<br>2weeks: $ {$row['2week']}<br>3weeks: $ {$row['3week']}<P align=center>deposit: $ {$row['deposit']}.00<br>shipping: $ {$row['ship']}</FONT></B></P>".
"<TABLE border=2 align=center><TR width=40% align=center><TD vAlign=top align=center width=150>".
"<form target=\"paypal\" action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\"><table><tr><td><input type=\"hidden\" name=\"on0\" value=\"duration\">duration</td><td><select name=\"os0\"><option value=\"1 week\">1 week<option value=\"2 weeks\">2 weeks<option value=\"3 weeks\">3 weeks</select></td></tr><tr><td><input type=\"hidden\" name=\"on1\" value=\"shipdate\">shipdate</td><td><select name=\"os1\"><option value=\"immediately\">immediately<option value=\"reservation\">reservation</select></td></tr></table><input type=\"image\" src=\"https://www.paypal.com/en_US/i/btn/x-click-but22.gif\" border=\"0\" name=\"submit\" alt=\"Make payments with PayPal - it's fast, free and secure!\"><img alt=\"\" border=\"0\" src=\"https://www.paypal.com/en_US/i/scr/pixel.gif\" width=\"1\" height=\"1\"><input type=\"hidden\" name=\"add\" value=\"1\"><input type=\"hidden\" name=\"cmd\" value=\"_cart\"><input type=\"hidden\" name=\"business\" value=\"davi0906@umn.edu\"><input type=\"hidden\"".
"name=\"item_name\" value=\"{$row['LensName']}\"><input type=\"hidden\" name=\"item_number\" value=\"1x{$row['LensID']}\"><input type=\"hidden\" name=\"amount\" value=\"{$row['deposit']}\"><input type=\"hidden\" name=\"page_style\" value=\"AlphaLensRental\"><input type=\"hidden\" name=\"no_shipping\" value=\"0\"><input type=\"hidden\" name=\"return\" value=\"http://www.alphalensrental.com/thankyou.html\"><input type=\"hidden\" name=\"cancel_return\" value=\"http://www.alphalensrental.com/notransaction.html\"><input type=\"hidden\" name=\"cn\" value=\"reservation or other notes\"><input type=\"hidden\" name=\"currency_code\" value=\"USD\"><input type=\"hidden\" name=\"lc\" value=\"US\"><input type=\"hidden\" name=\"bn\" value=\"PP-ShopCartBF\"></form>".
"</TD></TR></TABLE><EM><FONT size=1></FONT></EM></P><P><EM><FONT size=1></FONT></EM><EM><FONT size=1></P><P align=center>".
"</TD></TR></TABLE><TABLE class=\"alr4\" width=100%>".
"<TR><TD width=33%>Make</TD><TD><span>";
if ($row['make']==1){
echo "Minolta";
}
else if ($row['make']==2){
echo "Sony";
}
else if ($row['make']==3){
echo "Tamron";
}
else {
echo "other";
}
echo "</span></TD><TD width=33% colSpan=1 rowSpan=1>Filter Size </TD><TD><span>";
$filter = $row['filtersize'];
if($filter == 0){
echo "NA";
}
else{
echo "{$row['filtersize']}mm";
}
echo "</span></TD></TR><TR><TD width=33% colSpan=1 rowSpan=1>Focal Length</TD><TD><span>{$row['focalwide']}";
if ($row['focaltele'] != $row['focalwide']) {
echo "-{$row['focaltele']}";
}
echo "mm</span></TD><TD>Weight</TD><TD><span>{$row['weight']} lb</span></TD></TR><TR>".
"<TD>Aperture</TD><TD><span>f/{$row['apmax']} - f/{$row['apmin']} </span></TD><TD>Length (in)</TD><TD><span>{$row['length']}</span></TD>".
"</TR><TR><TD>Min Focusing Distance (ft)</TD><TD><span >{$row['minfoc']} </span></TD></TR></TABLE></TABLE><P><span>".
"<TABLE class=\"alr\" width=900><TR><TD vAlign=top align=center width=100%><FONT COLOR=red>";
// if ({$row['lenswarning']} != 'NULL') {
echo "{$row['lenswarning']}";
// }
echo "</FONT><P>{$row['lensdescription']}</span></P>".
"</TD><TD vAlign=top align=center></TABLE>";
}
mysql_close($conn);
?>
ph0t0man
03-29-2008, 07:43 PM
I've found one error in my code
Maybe not...nothing works if the ' ' are in there...so that must be incorrect?
It's a strugglefest overhere...
felgall
03-29-2008, 07:52 PM
What exactly does the echo statement output. That's what mySQL actually sees and so knowing how that reads is more useful that the PHP code because it shows us hot it looks after the PHP values are substituted.
ph0t0man
03-29-2008, 08:02 PM
What exactly does the echo statement output. That's what mySQL actually sees and so knowing how that reads is more useful that the PHP code because it shows us hot it looks after the PHP values are substituted.
Check it out here:
http://www.alphalensrental.com/lensdetail2.php?lensid=1
This is what it is outputting:
SELECT LensID, LensType, LensName, numberowned, instock, 1week, 2week, 3week, ship, deposit, focalwide, focaltele, apmax, apmin, filtersize, weight, minfoc, length, make, lenswarning, lensdescription FROM lenslist WHERE LensID=
It appears that $lensid isn't being transferred into the code the way I need it to be? That is what is happening. I just checked by substituting $lensid with 1 and now it is loading from my database properly. So...the error is in this line of code:
$query1 = "SELECT LensID, LensType, LensName, numberowned, instock, 1week, 2week, 3week, ship, deposit, focalwide, focaltele, apmax, apmin, filtersize, weight, minfoc, length, make, lenswarning, lensdescription FROM lenslist WHERE LensID=$lensid";
Why isn't the lens id in the url transferred into $lensid?
felgall
03-29-2008, 09:29 PM
Do you have the statement to assign it across?
$lensid = $_GET['lensid'];
If that statement to actually assign the value to the field in the first place is missing then that would explain the problem. Possibly your old host was using an antiquated version of PHP that had register globals on so that the assignment was made automatically. The register globals field was on by default in PHP prior to PHP 4.2. In 4.2 the default was changed to off since it was realised that doing those assignments automatically is a potential security hole. The setting itself has been removed from PHP 6 so that it will no longer be possible to change it from the default when that version is released.
n9ucs
03-29-2008, 09:35 PM
try LensID='".$lensid."'
ph0t0man
03-29-2008, 09:42 PM
Do you have the statement to assign it across?
$lensid = $_GET['lensid'];
Nope, and this code is now working for what I am doing.
Possibly your old host was using an antiquated version of PHP that had register globals on so that the assignment was made automatically. The register globals field was on by default in PHP prior to PHP 4.2. In 4.2 the default was changed to off since it was realised that doing those assignments automatically is a potential security hole. The setting itself has been removed from PHP 6 so that it will no longer be possible to change it from the default when that version is released.
Everything else they were using was antiquated, so I wouldn't be surprised...So glad to be done with them.
I really appreciate the help - should have come here sooner. Thanks to all who have responded, you've all helped in some way, shape, or form. This will be another nice place to put in the bookmarks and visit on occasion.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.