/    Sign up×
Community /Pin to ProfileBookmark

Error, dont understand – Help

Hi everyone

I’m having a small problem with php i keep getting this error:

[QUOTE]

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/victoria/public_html/admin/postage-list.php on line 30

[/QUOTE]

here is line 30

[code=php]while ($row = mysql_fetch_array ($result)) [/code]

the funny thing is, is that it worked great till i move it to a differnet Hosting company.

Can someone please help me

to post a comment
PHP

8 Comments(s)

Copy linkTweet thisAlerts:
@solavarNov 08.2004 — The error is coming from the SQL above this line.

Let's have a look at your SQL statement,

eg:

$sql = "SELECT * FROM mytable";

$result = mysql_query($result);
Copy linkTweet thisAlerts:
@RedheadauthorNov 08.2004 — This is what i have

[code=php]
include ("../dbconnect.php");

$sql = "SELECT * FROM postagestamps";

$result = mysql_query($sql, $db);

while ($row = mysql_fetch_array ($result))

[/code]


and i keep getting the error if i remove the $db from the result page i still get the same error


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/victoria/public_html/admin/postage-list.php on line 30
[/QUOTE]
Copy linkTweet thisAlerts:
@solavarNov 08.2004 — Let's see if MySQL will report the cause of error...

[code=php]

include ("../dbconnect.php");

$sql = "SELECT * FROM postagestamps";

if(! $result = mysql_query($sql, $db))
{
echo "The error is: " .mysql_error();

// What is $db
echo "<br /> The value of '$db' is: $db";
}
else
{

while ($row = mysql_fetch_array ($result))
{
echo "...works ok";
}
}

[/code]


The problem may be coming from the included file. $db is probably empty, thereby nullifying the result resource.
Copy linkTweet thisAlerts:
@RedheadauthorNov 08.2004 — I also tryed this insert statement with PHP myAdmin version 2.6.0-pl2


[code=php]
$sql = "INSERT INTO postagestamps (psname, psdiscription, categorie, subcategorie, imageid) VALUES ('psname', 'psdiscription', 'categorie', 'subcategorie', 'imgfile_name')"
[/code]


and got this error


#1064 - You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '$sql = "INSERT INTO postagestamps (psname, psdiscription, categ
[/QUOTE]


so i guess thing have chaned in the new version ?
Copy linkTweet thisAlerts:
@solavarNov 08.2004 — Hi redhead,

I think your variables are missing the $prefix...

[code=php]

//You have...

$sql = "INSERT INTO postagestamps (psname, psdiscription, categorie, subcategorie, imageid) VALUES ('psname', 'psdiscription', 'categorie', 'subcategorie', 'imgfile_name')";

//...must be

$sql = "INSERT INTO postagestamps (psname, psdiscription, categorie, subcategorie, imageid) VALUES ('$psname', '$psdiscription', '$categorie', '$subcategorie', '$imgfile_name')";

[/code]


Also, make sure that you've got a SEMI-colon at the end of your SQL statement.

Good luck

solavar
Copy linkTweet thisAlerts:
@RedheadauthorNov 08.2004 — Ok here is my problem with a select statement
[code=php]
include ("../dbconnect.php");

$sql = "SELECT * FROM postagestamps";

$result = mysql_query($sql, $db);

echo "
Stamps Of Victoria Postage Stamps Page

<table width=50%>

<tr>

<td>Postage Stamp Name</td>

<td>Postage Stamp Discription</td>

<td>&nbsp;</td>

<td>&nbsp;</td>";

while ($row = mysql_fetch_array ($result))

{

echo "
<tr>
<td>$row[psname]</td>
<td>$row[psdiscription]</td>
<td><a href="edit-postagestamps.php?id=$row[id]">Edit</td>
<td><a href="delete-postagestamps.php?id=$row[id]">Remove</td>
</tr>
";
}

echo "</table>";
echo"<a href=adminlist.php>Go back to the main menu</a>";
?>
[/code]


This is what i have and i'm getting this :


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/victoria/public_html/admin/postage-list.php on line 30

[/QUOTE]


The first echo statment does show up.

with my insert statement this is what i have:
[code=php]
include ("../dbconnect.php");

$sql = "INSERT INTO postagestamps ( id , psname , psdiscription , categorie , subcategorie , imageid )
VALUES ('$psname', '$psdiscription', '$categorie', '$subcategorie', '$imgfile_name')";


$result = mysql_query($sql, $db);

echo "
The following Other Stamp was added to the other stamp page

<table border=1>
<tr>
<td>Other Stamp Name</td>
<td>$psname</td>
</tr>
<tr>
<td>Pther Stamp Discription</td>
<td>$psdiscription</td>
</tr>
</table>

";

echo "<img src=../psimages/$imgfile_name>";
echo"<p><a href=adminlist.php>Go back to the main menu</a>.</p>";
[/code]


when i run this in IE, everthing seams to be working but when i check, PHPMyAdmin nothing appears in the DB. I have checed all spelling for tables, db name, fields etc etc etc..

Like i sayid i had all this working on a different server with a different hosting company. and when i moved over to new server and new hosting comapny nothing works! ?

MAN OH MAN i'm so confused.
Copy linkTweet thisAlerts:
@solavarNov 08.2004 — Uhmm, quite a puzzle.

Okay, get MySQL to display any error when SQL is executed.

Wherever you have:

$result = mysql_query($sql, $db);

do this instead...

[code=php]

$result = mysql_query($sql, $db) or die(mysql_error());

[/code]


If MySQL is failing to INSERT the data, it will tell you why.
Copy linkTweet thisAlerts:
@yunaNov 10.2004 — I think you're missing the final semicolon:

<i>
</i>$sql = "SELECT * FROM postagestamps";
$result = mysql_query($sql, $db);


should be

<i>
</i>$sql = "SELECT * FROM postagestamps;"; <br/>
^
$result = mysql_query($sql, $db);


It's often easy to forget that BOTH the SQL server (except Oracle!) and PHP need a final semicolon.
×

Success!

Help @Redhead spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...