Forum Moderators: coopster
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/.../oef/cms/headlines.php on line 12
reference: full php script
<?php
include('include_fns.php');
include('header.php');
$conn = db_connect();
$pages_sql = 'select * from pages order by code';
$pages_result = mysql_query($pages_sql, $conn);
while ($pages = mysql_fetch_array($pages_result)) {
$story_sql = "select * from stories
where page = '".$pages['code']."'
and published is not null
order by published desc";
$story_result = mysql_query($story_sql, $conn);
if (mysql_num_rows($story_result)) {
$story = mysql_fetch_array($story_result);
print '<table border="0" width="400">';
print '<tr>';
print '<td rowspan="2" width="100">';
if ($story[picture])
print "<img src=\"resize_image.php?image=$story[picture]\" />";
print '</td>';
print '<td>';
print '<h3>'.$pages['description'].'</h3>';
print $story['headline'];
print '</td>';
print '</tr>';
print '<tr><td align="right">';
print '<a href="page.php?page='.$pages['code'].'">';
print '<font size="1">Read more '.$pages['code'].' ...</font>';
print '</a>';
print '</table>';
}
}
include('footer.php');
?>
<?php
include_once('db_fns.php');
?>
there you have db_fns.php
with
<?php
function db_connect()
{
$result = @mysql_pconnect('localhost', 'content', 'password');
if (!$result)
return false;
if (!@mysql_select_db('content'))
return false;
return $result;
}
?>
[edited by: ergophobe at 5:24 pm (utc) on Sep. 27, 2004]
[edit reason] codee dump snipped [/edit]
function db_connect()
{
//$result = @mysql_pconnect('localhost', 'content', 'password');
$result = mysql_connect('localhost', 'content', 'password') or exit('Could not connect (' . mysql_errno() . '): ' . mysql_error()); # Test mode only
if (!$result)
return false;
//if (!@mysql_select_db('content'))
if (!@mysql_select_db('content')) or exit('Could not select database (' . mysql_errno() . '): ' . mysql_error()); # Test mode only
return false;return $result;
}
You'll notice I also removed the error suppression (@) from the mysql functions during test mode. This should give you more detail when troubleshooting your database connections.
$conn = db_connect();
$pages_sql = 'select * from pages order by code';
$pages_result = mysql_query($pages_sql, $conn);
while ($pages = mysql_fetch_array($pages_result))
{
$story_sql = "select * from stories
where page = '".$pages['code']."'
and published is not null
order by published desc";
$story_result = mysql_query($story_sql, $conn);
if (mysql_num_rows($story_result))
{
$story = mysql_fetch_array($story_result);
print '<table border="0" width="400">';
<snip> lots of other output</snip>
print '</table>';
}
}
?>
--------------------------------------------------
gives this error online in headlines.php:
-----------------------
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/.../headlines.php on line 10
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/.../headlines.php on line 12
---------------------------------------------------
<?php
$conn = db_connect();
$sql = "select * from stories
where page = '$page'
and published is not null
order by published desc";
$result = mysql_query($sql, $conn);
while ($story = mysql_fetch_array($result))
{
print '<h2>'.$story['headline'].'</h2>';
<snip> lots of other output</snip>
print date('M d, H:i', $story['modified']);
print '</font>';
}
?>
--------------------------------------------------
gives this error online in page.php:
-----------------------
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/.../pages.php on line 21
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/.../pages.php on line 23
---------------------------------------------------
[edited by: ergophobe at 5:29 pm (utc) on Sep. 27, 2004]
[edit reason] code dump snipped [/edit]
I know it isn't easy being a newbie, especially where you don't know where your code isn't working. You'll probably want to learn some rudimentary debugging techniques, like outputting variables with echo $variable; stopping code execution at places to see what's done / what's not with die() etc. Basic php tutorial at php.net is worth looking at too.
coding login.php
----------------------------------------------------------------
<?php
include('include_fns.php');
if ( (!isset($HTTP_POST_VARS['username'])) ¦¦ (!isset($HTTP_POST_VARS['password'])) ) {
print 'You must enter your username and password to proceed';
exit;
}
<snip>extraneous code</snip>
?>
coding include_fns.php
------------------------------------------------------------------
<?php
include_once('db_fns.php');
include_once('user_auth_fns.php');
include_once('select_fns.php');
session_start();
?>
<snip>extraneous code</snip>
coding user_auth_fns.php
------------------------------------------------------------------
<?php
<snip>extraneous code</snip>
function check_auth_user()
// see if somebody is logged in and notify them if not
{
global $HTTP_SESSION_VARS;
if (isset($HTTP_SESSION_VARS['auth_user']))
return true;
else
return false;
}
?>
<snip>extraneous code</snip>
[edited by: ergophobe at 5:33 pm (utc) on Sep. 27, 2004]
[edit reason] snipped code dump [/edit]