Error problems in PHP
Moderator: General Moderators
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
Error problems in PHP
Hello, I added a news script for people to signup and add news that thye want. Well, I am haveing problems viewing the news that is added into the tables of MySQL. This is the error.
Warning: Supplied argument is not a valid MySQL result resource in view_news.php on line 6
I tried so much stuff. I have played with the code and played around in MySQL. Does anyone know what is up with this. This is the code that, that error is from.
-------------------
<?
require ("news_connect.php");
$result = mysql_query ("SELECT headline,news,link,user,timestamp FROM news ORDER BY timestamp DESC LIMIT 5");
while ($data = mysql_fetch_array ($result))
{
?>
-------------------
Thanks if anyone can help!!!
Warning: Supplied argument is not a valid MySQL result resource in view_news.php on line 6
I tried so much stuff. I have played with the code and played around in MySQL. Does anyone know what is up with this. This is the code that, that error is from.
-------------------
<?
require ("news_connect.php");
$result = mysql_query ("SELECT headline,news,link,user,timestamp FROM news ORDER BY timestamp DESC LIMIT 5");
while ($data = mysql_fetch_array ($result))
{
?>
-------------------
Thanks if anyone can help!!!
nope, he wants $data to be the result of mysql_fetch_array in each while-iteration. mysql_fetch_array will return FALSE if no more recordsets are available -> $data will be FALSE -> the loop discontinues.
probably the mysql_query failed an so $result is no result-resource that mysql_fetch_... can use to retrieve the data. Tryto see what mysql thinks about the query 
probably the mysql_query failed an so $result is no result-resource that mysql_fetch_... can use to retrieve the data. Try
Code: Select all
$query = 'SELECT headline,news,link,user,timestamp FROM news ORDER BY timestamp DESC LIMIT 5';
$result = mysql_query ($query) or die(mysql_error());-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
by wrong table do you mean wrong database?
).
Take a look at http://www.php.net/manual/en/function.m ... ect-db.php
kkurkowski is the database, news the table (as you have ordered mysql to use in your queryTable 'kkurkowski.news' doesn't exist
Take a look at http://www.php.net/manual/en/function.m ... ect-db.php
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
K: just post your code in here ( be sure though, to edit out your login/password for your mysql database, as well as the correct path ).
We'll tear it apart, and tell ya what you need to do differently.
Again, make SURE to remove your correct username/password in the script for security reasons.....
We'll tear it apart, and tell ya what you need to do differently.
Again, make SURE to remove your correct username/password in the script for security reasons.....
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
This should be it. It is in the forms page when you fill out all of the text boxes and then hit submit. It sends it to the MySQL database.
Code: Select all
<?
require("news_connect.php");
if(@$action=="submit")
{
if ((!$news_headline) || (!$news_news) || (!$news_link)) {
echo "Please fill in all fields<br>\n";
} else {
mysql_query("INSERT INTO news_news (headline,news,link,user,timestamp) VALUES ('$news_headline','$news_news','$news_link','$user',".time().")");
echo "News added<br>\n";
}}
?>-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
-
kkurkowski
- Forum Commoner
- Posts: 53
- Joined: Mon Dec 09, 2002 4:44 pm
- Location: Michigan
news_connect.php
view_news.php
add_news.php
Thats all there is for the news script. The username one has more code.
Code: Select all
<?
$database_server="localhost";
$database_user="username";
$database_password="password";
$database="database";
$db=mysql_connect($database_server, $database_user, $database_password);
mysql_select_db($database);
?>Code: Select all
<?
global $data;
require ("news_connect.php");
$result = mysql_query ("SELECT headline,news,link,user,timestamp FROM news_news ORDER BY timestamp DESC LIMIT 5");
while ($data == mysql_fetch_array ($result))
{
?>Code: Select all
<?
require("news_connect.php");
if(@$action=="submit")
{
if ((!$news_headline) || (!$news_news) || (!$news_link)) {
echo "Please fill in all fields<br>\n";
} else {
mysql_query("INSERT INTO news_news (headline,news,link,user,timestamp) VALUES ('$news_headline','$news_news','$news_link','$user',".time().")");
echo "News added<br>\n";
}}
?>