Forum Moderators: coopster
$page_result = mysql_query($page_sql);
Check this out for the right syntax of mysql_query:
[php.net ]
Warning: mysql_fetch_field(): supplied argument is not a valid MySQL result resource in /usr/local/www/test.php on line 58
I tried
$page_myrow = mysql_fetch_array($page_result);
$page_myrow = mysql_fetch_row($page_result);
$page_myrow = mysql_fetch_field($page_result);
54 <?php
55 if ($page) {
56 $page_sql = "SELECT * FROM SPI_html WHERE page_name=$page";
57 $page_result = mysql_query($page_sql);
58 $page_myrow = mysql_fetch_array($page_result);
59 $body = $page_myrow["body"];
60 echo $body;
61 }
62 ?>
I get the same error all the time.
[edited by: CIAimages at 4:43 pm (utc) on June 14, 2004]
try this now
$page_sql = "SELECT * FROM SPI_html WHERE page_name=$page";
echo $page_sql;
then take a look at the constructed query and see if there are any errors in it. I often take the output query and connect to sql, in my case with putty, and then test the query there.
I usually get the same error but then i can look at the table itself and check all the columns and the data to make sure I am doing what I thought I was doing and it makes it easier to fix the query.
Some people obviously do this with phpmyadmin but I am a command line mysql'er. ;)
I see no error in the sql statment
I looked at my db via phpMyAdmin and I see no error in my table eather. But I am new at php and mysql so here is how my table look like
Field Type Null
page_name text No
title text No
description text No
keywords text No
body text No
Could the error come from the fact that I use the same connection for 2 different table processing?
// Connect to the mySQl server
// ***************************
$db = mysql_connect($host, $username, $password) or die("Could not connect to host.");
mysql_select_db($database, $db) or die("Could not find database.");
// Get all the Info from the mySQl DB
// **********************************
$sql = "SELECT * FROM SPI_html";
$result = mysql_query($sql);
as well for this script
$page_sql = "SELECT * FROM SPI_html WHERE page_name=$page";
3. create a function to sinplify it (functions a held in memory)
function condb()
{$db = mysql_pconnect($host, $username, $password) or die("Could not connect to host.");
mysql_select_db($database, $db) or die("Could not find database.");}
then every page you need to connect to the db simply type
condb();