Free Web Hosting Forum
(#1 (permalink))
Old
Junior Member
jreynolds22 is on a distinguished road
 
Posts: 3
Join Date: Jun 2012
Default PHP Error Message - 07-09-2012, 11:54 PM

I'm creating a web page using php, but I continue to get the following error message: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource on line 37 when trying to open the page. Below is the code that I have. Any help is greatly appericated.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>

<head>
<title>Weekday PM Pullouts</title>
<link rel="stylesheet" type="text/css" href="../styles.css">
<link rel="stylesheet" type="text/css" href="../print.css" media="print">
<script script type="text/javascript" src="../functions.js"></script>
</head>

<body>

<h1 class="hidden">WEEKDAY PM PULL-OUTS</h1>

<div id="noprint" class="header" align="center">
<ul>
<li><a href="#" onclick="show_alert()">All</a></li>
<li><a href="#" onclick="show_alert()">Channel 1</a></li>
<li><a href="#" onclick="show_alert()">Channel 4</a></li>
<li><a href="javascript:window.print()">Print</a></li>
</ul>
</div>

<?php
$con = mysql_connect($localhost,$user,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("pullouts", $con);

$result = mysql_query ("SELECT * FROM pullouts WHERE pullouts.day='Weekday' AND pullouts.time > '12:00:00' AND pullouts.effective='2012/03/12' ORDER BY pullouts.time");

while($row = mysql_fetch_array($result))
{
echo $row['check'] . " " . $row['time'] . " - " . $row['details'] . " " . $row['day'] . " " . $row['channel'] . " " . $row['yard'] . " " . $row['effective'];
echo "<br />";
}
mysql_close($con);
?>

</body>
</html>
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
Senior Member
grace1004 is on a distinguished road
 
Posts: 732
Join Date: Dec 2010
Default 07-10-2012, 05:29 AM

Is your database set up in 000webhost.com server? If so, db_name should be something like:
axxxxxxx_dbname, not "pullouts" as shown below.

mysql_select_db("pullouts", $con);
Reply With Quote
(#3 (permalink))
Old
Doug Lochert's Avatar
Senior Member
Doug Lochert is on a distinguished road
 
Posts: 361
Join Date: Jun 2012
Location: Canada
Default 07-10-2012, 04:23 PM

Quote:
$result = mysql_query ("SELECT * FROM pullouts WHERE pullouts.day='Weekday' AND pullouts.time > '12:00:00' AND pullouts.effective='2012/03/12' ORDER BY pullouts.time");
You have already referenced the db table pullouts in the SQL call, there is no need to continue referencing the pullouts table again for actual fields within it. [WHERE pullouts.day='Weekday'] should be [WHERE day='Weekday']
Reply With Quote
(#4 (permalink))
Old
Junior Member
jreynolds22 is on a distinguished road
 
Posts: 3
Join Date: Jun 2012
Default 07-11-2012, 01:07 AM

Quote:
Originally Posted by grace1004 View Post
Is your database set up in 000webhost.com server? If so, db_name should be something like:
axxxxxxx_dbname, not "pullouts" as shown below.

mysql_select_db("pullouts", $con);
Thanks, I tried that, buy still no luck.
Reply With Quote
(#5 (permalink))
Old
Junior Member
jreynolds22 is on a distinguished road
 
Posts: 3
Join Date: Jun 2012
Default 07-11-2012, 01:08 AM

Quote:
Originally Posted by Doug Lochert View Post
You have already referenced the db table pullouts in the SQL call, there is no need to continue referencing the pullouts table again for actual fields within it. [WHERE pullouts.day='Weekday'] should be [WHERE day='Weekday']
Ok, trying to move from access to php and learn all the new tricks. Thanks for the knowledge.
Reply With Quote
(#6 (permalink))
Old
Doug Lochert's Avatar
Senior Member
Doug Lochert is on a distinguished road
 
Posts: 361
Join Date: Jun 2012
Location: Canada
Default 07-11-2012, 04:09 AM

Quote:
<?php
$con = mysql_connect($localhost, $user, $password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pullouts", $con);
?>
It's always a good idea to check DB calls for errors, similar to the error check in the mysql_connect() you used above... but there is an easier (and tidier) way.

Secondly, it appears that you are using a config file to store the DB login details. It is also a good idea to store the DB name in same way, providing a 2nd barrier of security if users access the source code. See below:

Code:
$con = @mysql_connect($localhost, $user, $password) or die (mysql_error());
$db = @mysql_select_db($dbname, $con) or die (mysql_error());
*define $dbname in same config file as $user,$password etc.

Note: Prepending calls with "@" suppresses the error message (best used when site goes live so users don't see the errors/urls etc) but is also ignored when mysql_error is appended to the same call (during development).

Last edited by Doug Lochert; 07-11-2012 at 04:12 AM.
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com