This is a discussion on MySQL PHP Code problem. Please help! within the MySQL Database forums, part of the Database Forums category; I'm stuck and trying to learn how to fix something. I have a code written in php/html that ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
I'm stuck and trying to learn how to fix something.
I have a code written in php/html that accessed a MySQL database just fine until my ISP upgraded. Here's the local host info: localhost a.. Server version: 4.1.22-standard b.. Protocol version: 10 c.. Server: Localhost via UNIX socket d.. MySQL charset: UTF-8 Unicode (utf8) e.. phpMyAdmin - 2.10.0.2 a.. MySQL client version: 4.1.22 b.. Used PHP extensions: mysql Here is my problem: <?php $query = "select html from UpcomingEvents where ID = ".$ID; $result = mysql_query($query); $row = mysql_fetch_array($result); echo $row['html']; ?> This worked prior to any changes. I should be able to click on September 6 Face-to-Face meeting and get that info and then click on September 8-9 MS Bike Tour and have it pull up that info, however that's not happening. Instead I am getting the error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/carenclu/public_html/eventdetail.php on line 40 I can assign the ID with a specific database row number and have it pull up that information but I need it to be dynamic and pull according to the name of the event and give the appropriate information. Can anyone explain to me why this is not reading anymore? I figure there is some change with the new MySQL but I'm not experienced enough to know what to look for. Any help will be greatly appreciated. I've got several books and have been looking on the internet for example code but I can't find anything that assigns and reads an ID the way this was originally set up. Thanks, cc |
|
|||
|
On Sep 5, 2:33 pm, "Cindy Chambers" <cchambers...@comcast.net> wrote:
> > $result = mysql_query($query); try here instead: $result = mysql_query($query) or die (mysql_error()); to get the error msg from MySQL the $result that you are getting back is not what is expected > > $row = mysql_fetch_array($result); |
|
|||
|
Thank you Herb.
"Herb" <herb_k@mail.com> wrote in message news:1189017678.946711.159380@d55g2000hsg.googlegr oups.com... > On Sep 5, 2:33 pm, "Cindy Chambers" <cchambers...@comcast.net> wrote: > >> >> $result = mysql_query($query); > > try here instead: $result = mysql_query($query) or die > (mysql_error()); > > to get the error msg from MySQL > > the $result that you are getting back is not what is expected >> >> $row = mysql_fetch_array($result); > |
|
|||
|
Well it tells me it's a syntax error so that I knew. Here's what it sent as
an error: 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 I'm back to what is different from the old and new versions. "Herb" <herb_k@mail.com> wrote in message news:1189017678.946711.159380@d55g2000hsg.googlegr oups.com... > On Sep 5, 2:33 pm, "Cindy Chambers" <cchambers...@comcast.net> wrote: > >> >> $result = mysql_query($query); > > try here instead: $result = mysql_query($query) or die > (mysql_error()); > > to get the error msg from MySQL > > the $result that you are getting back is not what is expected >> >> $row = mysql_fetch_array($result); > |
|
|||
|
"Cindy Chambers" <cchambers777@comcast.net> wrote in
news:rZudnU1Y04DmkELbnZ2dnUVZ_qSonZ2d@comcast.com: > Well it tells me it's a syntax error so that I knew. Here's what it > sent as an error: 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 > > I'm back to what is different from the old and new versions. Learn how to debug. You have a syntax error. It won't work in either version. Are you certain you know what your query is? Before sending it to MySQL, echo it out... betcha there's a syntax error. echo $query |
|
|||
|
On Sep 5, 4:11 pm, "Cindy Chambers" <cchambers...@comcast.net> wrote:
> Well it tells me it's a syntax error so that I knew. not necessarily so, it could have been another type of problem. E.g., a switch from some non *nix to a *nix OS could uncover a problem with case in a table name. > Here's what it sent as > an error: 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 > > I'm back to what is different from the old and new versions. But you now do know that syntax is truly the problem. Since it's a mystery kind of syntax problem, I'd next echo the $query to see if it truly contains what you think it contains. e.g.: echo ">$query<"; I'd also retype the line that assigns the string to $query, just in case there's some weird encoding thing going on that can't be seen. Just a shot in the dark... |
|
|||
|
On Wed, 05 Sep 2007 20:33:14 +0200, Cindy Chambers
<cchambers777@comcast.net> wrote: > I'm stuck and trying to learn how to fix something. > > I have a code written in php/html that accessed a MySQL database just > fine > until my ISP upgraded. I'd assume it's the PHP upgrade... So not really a MySQL problem, but what the heck :P > Here's the local host info: > > localhost > a.. Server version: 4.1.22-standard > b.. Protocol version: 10 > c.. Server: Localhost via UNIX socket > d.. MySQL charset: UTF-8 Unicode (utf8) > e.. > phpMyAdmin - 2.10.0.2 > a.. MySQL client version: 4.1.22 > b.. Used PHP extensions: mysql > Here is my problem: > > <?php > > $query = "select html from UpcomingEvents where ID = ".$ID; Check out register_globals in the PHP documentation, and why it should be OFF, I think this is the most likely problem after an upgrade of PHP. Use something like: $ID = intval($_GET['ID']); //or intval($_POST['ID']);, depending on the method $query = "select html from UpcomingEvents where ID = ".$ID; -- Rik Wasmus |
|
|||
|
Rik,
Thanks! That's exactly what I needed. Your code has everything reading perfectly again. Thank you so much! cc "Rik Wasmus" <luiheidsgoeroe@hotmail.com> wrote in message news:op.tx7dryow5bnjuv@metallium.lan... On Wed, 05 Sep 2007 20:33:14 +0200, Cindy Chambers <cchambers777@comcast.net> wrote: > I'm stuck and trying to learn how to fix something. > > I have a code written in php/html that accessed a MySQL database just > fine > until my ISP upgraded. I'd assume it's the PHP upgrade... So not really a MySQL problem, but what the heck :P > Here's the local host info: > > localhost > a.. Server version: 4.1.22-standard > b.. Protocol version: 10 > c.. Server: Localhost via UNIX socket > d.. MySQL charset: UTF-8 Unicode (utf8) > e.. > phpMyAdmin - 2.10.0.2 > a.. MySQL client version: 4.1.22 > b.. Used PHP extensions: mysql > Here is my problem: > > <?php > > $query = "select html from UpcomingEvents where ID = ".$ID; Check out register_globals in the PHP documentation, and why it should be OFF, I think this is the most likely problem after an upgrade of PHP. Use something like: $ID = intval($_GET['ID']); //or intval($_POST['ID']);, depending on the method $query = "select html from UpcomingEvents where ID = ".$ID; -- Rik Wasmus |