View Full Version : I get an mySQL and I don't know why

10-22-2005, 06:08 PM
I get an error when i try to open this (error is shown below) and i don't know why, could anyone help me out? I'm trying to create a news submitting system for my website, so far unsuccesful (I hardly know anything about mySQL and PHP) and followed a tutorial on this subject, but it doesnt seem to work.


include_once "config.php";

$q = mysql_query("SELECT * FROM $table ORDER BY id DESC LIMIT $limit"); // That queries the database


$title = $r["title"];

$news = $r["news"];

$body = nl2br($news);

$author = $r["author"];

$link = "mailto:".$r["email"];

$date = $r["date"];

echo "<table width=\"100%\" cellspacing=\"O\" cellpadding=\"0\" style=\"margin-top: 2px; margin-bottom: 2px;\">";
echo "<tr>";
echo "<td id=\"header\">";
echo "<b>News Subject: </b>" . $title;
echo "</td>";
echo "<td id=\"header\">";
echo "<b>Date: </b>" . $date;
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan=\"2\" id=\"newsmessage\">";
echo $body;
echo "<br /><br /><i>Posted by " . $author . "</i>";
echo "</td>";
echo "</tr>";
echo "</table>";




Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/wcs-clan.net/httpdocs/news/test.php on line 8

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/httpd/vhosts/wcs-clan.net/httpdocs/news/test.php on line 12

Creative Insanity
10-22-2005, 10:11 PM
This says it all really.
supplied argument is not a valid

Have a look at line 8 and make sure it is valid.

10-23-2005, 09:01 AM
Omg.. I made it work, made some alterations, and now it just refuses to work. Is there something seriously wrong with me? I didn't even alter line 29.. and I get this error:

Warning: mysql_error(): supplied argument is not a valid MySQL-Link resource in /home/httpd/vhosts/wcs-clan.net/httpdocs/news/addnews.php on line 29

I don't understand what the error is, I've looked everywhere and it should work.. it did before?!

$cfgProgDir = 'login/';
include($cfgProgDir . "secure.php");


require_once "config.php";

if(isset($_POST['submit'])) {

$author = $_POST['author'];
$title = $_POST['title'];
$time = date("m-d-Y @ h:i:s");
$content = nl2br(htmlentities($_POST['content']));

$query = "INSERT INTO news (author, title, content, date_time) VALUES ('$author', '$title', '$content', '$time')";
$result = mysql_query($query);

if($result) {

echo "<title>Success!</title>";
echo "The news has been posted!";

} else {

echo "<title>Error!</title>";
echo "There was a error submitting the news to the database! Please try again.";
echo mysql_error($result); //The error was found on this line? what the hell is wrong with it?


} else {
<title>Add news</title>
<style type="text/css">
body {
background-color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
font-size: 12px;

#header {
border-bottom: 1px dashed #000000;
text-align: right;
width: 100%;
font-size: 18px;
color: #990000;
padding: 0px;

a:link {
color: #0066CC;
text-decoration: none;

a:visited {
color: #0066CC;
text-decoration: none;

a:hover {
color: #0066CC;
text-decoration: underline;
<div align="center" style="background-color: #CCCCCC; border: 1px dashed #666666; width: 80%; text-align: center;">
<table width="80%" align="center">
<tr align="center">
<td colspan="2" id="header">Add News</td>
<td align="right">Author: </td>
<td align="left"><form action="addnews.php" method="post"><input type="text" value="<?php echo $login ?>" name="author"></td>
<td align="right">Title: </td>
<td align="left"><input type="text" name="title"></td>
<td align="right">Content:</td>
<td align="left"><textarea name="content" cols="80" rows="10'"></textarea></td>
<td colspan="2" align='right'><input type="submit" name="submit" style="background-color: #CCCCCC; border: 1px solid #666666;" value="Submit"></form></td>
<p>If you want to log out, click <a href="logout.php">here</a>.<br /></p>
<p>Click <a href="news.php">here</a> to view the news.</p>


Creative Insanity
10-23-2005, 09:09 AM
Don't pay too much attention to the line number errors as that just gives you somewhere to start.
What I do when I get these type of errors I comment out the lines reported until I get no more errors.
Then I work from the last line commented out and work up from there.
Nine times out of ten you will find the error and it is nornaly something so simple and stupid hehe.

10-23-2005, 09:12 AM
If I comment out the lines, the script itself wouldn't work, and it would find multiple errors.. the line where the error should be should even be line 29 or prior to that line.. well i used the script, and it worked, then i alter something BELOW that line and now it says it's found an error. This just doesn't make sence to me.
echo mysql_query($query); theres nothing wrong with this is ther?

Creative Insanity
10-23-2005, 05:05 PM
Ok when it does work.. is it on the same sql server or a differant one. If a differant one then is that the same version as the one it does work on?
I had this problem a few weeks back. A script worked fine on my development server and not on my hosters server. I found the reason was they were using an older version of mysql.. and when they updated that for me all was fine.
Just trying to think of paths you can take.

Hmm else what?


} else {

10-24-2005, 09:59 AM

try this

add an @ so the code looks like this


then wrap your mysql_close($cnx); in an if

if (totalRows_close >0){



10-24-2005, 06:58 PM
Thanks for helping me guys, but I've found an easier way.. I just downloaded a free news submitting system that just has about everything, a small downer is that it uses plain text files to store it's data, but seeing as i myself can't use mysql admin or anything like that (my host won't allow that) it's for the best. I still need to learn almost everything there is to know about PHP and mySQL.. but I just can't seem to put myself on it. I guess I'll wait untill next week (vacation coming up). Dam school keeps me occupied alot.. I really want to learn php and mysql, I just love what you can do with it.

Thanks for your reply's,

Creative Insanity
10-24-2005, 07:32 PM
If you want to learn Mattias then you are going to have to change hosters to one that gives access to phpMyadmin and such like.

10-24-2005, 09:09 PM
Yeah, the problem is, I'm under aged (16) and my dad won't let me do payments over the internet, I don't even have a bank account i can acces yet. The way i got round this problem is i rented some space of a good mate's server, plus he got me my two domainnames: www.matty-industries.be and www.wcs-clan.net. So I'll have to do with that for at least a year, it's a real pain, cause like you said Ci, I will only be able to learn if i have acces to mysql admin. I know that, but that's a downer to having such paranoid parents, who think the internet is the unsecurest place of all.. I see their point of view in some way... but yeah I'm stuck with it as it is for now.

Thanks for your concern Ci, I really appriciate what you've done for me so far... I really consider you my "guru" hehe. Can't thank you enough.

P.S.: you can call me Matt Ci, easier to prounounce for you guys, plus I like it alot more than Mattias :P

Creative Insanity
10-24-2005, 09:57 PM
Now this rings a bell.. did you use to be a member of psthings and webthings Matt?

Anywhoo.. just install them on your local system.
Make yourself a development server with apache etc and there will be no holding you back. :)

10-25-2005, 04:16 PM
Ci, you asked me to join these forums :P, it's me Matt, remember? (matt was already taken on these forums).

I installed an apache server earlier.. but I didn't know how to use it etc etc.. how to install php on it. Those tut's of yours would really come in handy, they covered everything I regret that I didn't download them then. *sigh*

Creative Insanity
10-25-2005, 05:29 PM
ranjan posted a few days ago 2 packages that install everything you need for a development server Matt.
phpdev ('http://www.firepages.com.au/') and xampp ('http://www.apachefriends.org/en/xampp.html'), these will install all you need from one package. Although I have never used them, they sound like just what you need.

10-25-2005, 05:52 PM
Omg I love you. :P THANKS A BUNCH

Creative Insanity
10-25-2005, 07:44 PM
Omg I love you
Doesn't everyone? LOL

10-26-2005, 02:49 PM
K I installed it, now only to actually learn php. lol

10-26-2005, 02:50 PM
is everything working ok??

10-26-2005, 04:42 PM
Well, I have an apache server, and I can open mySQL admin.. so yeah I think so... I need to configure dreamweaver though, I don't know how to do that aswell.. I wish I actually knew someone that knew php, and could teach me... a lesson that would actually intrest me.

Creative Insanity
10-26-2005, 06:15 PM
To test your setup Matt place a text file in your local webroot directory.
That would be C:\Program Files\Apache Group\Apache\htdocs
and save it as info.php
In side the file add this line:
<? phpinfo() ?>
Now from a web browser go: http://localhost/info.php ('http://localhost/info.php')
If all is well you will get a ton of info about what you have installed an avalible to you through php.

Now how to use all that with DW.

1. In htdocs create a folder for a website you want to create.
2. Also create an image directory inside that folder.
3. Load up DW and click on the files tab and then click on the dropdown under the files tab and select Manage Sites.
4. On the next window that shows click the New button and select site.
5. Click the advanced Tab (it is easier with this option).
6. Now fill in all the fields and leave all checks as radios at default.
7. You only need to fill out the options for Local Info and Testing Server.
8. For the testing server option select php/mysql.

Once all that is done DW will show your folder in the files panel and from there you can right click on the folder and create either new folder and files.

For the database (just to play around) you can use the test database that mysql sets up. What ever you do DO NOT PLAY WITH OR DELETE THE MYSQL DATABASE. This is the database that MySQL uses to see who and who has not got access and what access they have.
In that database when you get better at this, you can setup access to databases you create for who and who has not got access to the database or databases and how much access they have. If you delete this database you are going to have to reinstall MySQL.

10-26-2005, 08:58 PM
Ta Ci, really appriciate it.

10-26-2005, 09:29 PM
Ok, I think something went wrong along the way, I have an apache server, I configer DW, and I stored a file on there.. then when i try to view it it gives me a 404 error, anyone knows why this is? i searched the apache map, and i can't fine a folder htpdocs or something along that way, i used xampp.. could this be it? Or am i doing something wrong.

Creative Insanity
10-27-2005, 12:32 AM
Click the start button.. there should be an apache program group there, (it may be under xampp, not sure as never used it), but there should be a folder option there to configure apache and from there a text file that lets you edit the httpd.conf file.
Do a search in that file (don't change anything unless you are sure you know what you are doing), for DocumentRoot. This is where all your htdoc files are and the web root path for your server files.
You can also try doing a http://localhost ('http://localhost') and see if apache throughs up a page just to test that the server did install correctly.

10-27-2005, 04:28 PM
If i go to http://localhost ('http://localhost') it directs me to the xampp page... from where i can acces all the other programs in it, I'll try doing what you suggested. Thanks in advance,


Creative Insanity
10-27-2005, 06:50 PM
Which is why I am not keen on those all in one packs myself.
Tell you what Matt. I hope you have a microphone.
Go to skype ('http://www.skype.com/helloagain.html') and download and install that. Then download php ('http://nz2.php.net/get/php-5.0.5-Win32.zip/from/au.php.net/mirror'), mysql ('http://dev.mysql.com/get/Downloads/MySQL-5.0/mysql-5.0.15-win32.zip/from/http://mysql.mirror.netmonic.com/') and apache ('http://apache.inspire.net.nz/httpd/binaries/win32/apache_2.0.55-win32-x86-no_ssl.exe') and then contact me on skype and I will talk you through it.
I am creativeinz on skype.

10-27-2005, 09:44 PM
k i've added you, and im going to uninstall and reinstall everything again..

I won't contact you untill you have time.. so tell me when you have got some spare time.

10-28-2005, 03:48 PM
hahaha, i just saw what was wrong, I COPIED THE WRONG FILE, I'm so stupid.. hahah I crack myself up.

I still got problems with the C:/webroot though, it won't load when i type http://localhost ('http://localhost')
I did what you asked ( i even double checked, so yeah i dont know what i've done wrong).