Forum Moderators: coopster

Message Too Old, No Replies

what is wrong here?

         

halloweb

1:34 pm on Sep 27, 2004 (gmt 0)

10+ Year Member


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/.../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');
?>

coopster

1:49 pm on Sep 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Seems you aren't connecting to your database in the db_connect() function.
$conn = db_connect();
Have you checked there yet?

halloweb

2:04 pm on Sep 27, 2004 (gmt 0)

10+ Year Member



this is include_fns.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]

coopster

2:25 pm on Sep 27, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



During development, I always turn all error_reporting [php.net] on so I can see what messages I am getting and why. Try something like this to see what is going on.

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.

halloweb

2:45 pm on Sep 27, 2004 (gmt 0)

10+ Year Member



this is headlines.php
------------------------------------------------------
<?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">';
<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]

mincklerstraat

4:30 pm on Sep 27, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Halloweb, just a note that might help you attract more help here, if you can leave just the parts of the code that are causing the actual error and snip out, for example, all those echo / print statements, people will be more likely to see what your problem is in a single glance rather than having to read through your code. So all those print statements you can replace with /* snip - output various stuff */ in your message here, or something like that. Postings with long lines of code often get neglected here, and really they're somewhat against the grain of the charter: [webmasterworld.com...] .

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.

halloweb

5:05 pm on Sep 27, 2004 (gmt 0)

10+ Year Member



fixed this and then another buggy page: login.php is stuck at 'You must enter your username and password to proceed' as processed in that login.php

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]