How to restrict who may read my entries?
mysql_fetch_array(): supplied argument is not a valid MySQL result resource
Hello Guest
  
  • Login
• Register…
• Start blog
  • Who, Where, When
• What is interesting here?
• Duels
  • Polls
• Avatars
• Interests
  • Cities and Countries
• Random blog
• Users search
  • Search
• Games
• Tests
• QAIX
  • Сообщества
• Talxy Chat
• Horoscope
• Online
 
Register!

QAIX > PHP web-programming > mysql_fetch_array():­ supplied argument is not a valid MySQL result resource 24 April 2009 17:27:10

  Top users: 
  Recent blog posts: 
  They have birthday today: 
  Forums:   
  Discuss: 
  Recent forum topics: 
  Recent forum comments:
  Модератор:

mysql_fetch_array():­ supplied argument is not a valid MySQL result resource

Ben Houlton 13 June 2003 05:17:51
 I'm trying to make a PHP script that automaticly makes a link on the side
menu to the id page that was just made, under certain catagories. But I
edited my code to cleen up soem errors and all of a sudden 3 errors came up,
and I haven't been able to fix them! They are:
Warning: mysql_fetch_array()­: supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\­main\menu.php on line 29
Warning: mysql_fetch_array()­: supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\­main\menu.php on line 41
Warning: mysql_fetch_array()­: supplied argument is not a valid MySQL result
resource in C:\Inetpub\wwwroot\­main\cat.php on line 39

The code for the menu and cat *.php files are below:

menu.php:
<HTML>

<HEAD>

<link href="/css/base.css­" rel="STYLESHEET" type="text/css">

</HEAD>

<BODY>

<TABLE width=100% cellPadding=0 cellSpacing=0>

<TR>

<TD width=150 vAlign=top>

<?php

$register_globals;

$db = mysql_connect("loca­lhost","root");

mysql_select_db("co­mmon",$db);

$result = mysql_query("SELECT­ * FROM main",$db);

echo "<center>Main</cent­er><br>";

while ($row1 = mysql_fetch_array($­result)) {

if ($row1["cat"] == 1) {

printf("<a href=\"pages.php?ca­t=1&id=%s\">%s</a><b­r>",
$row1["id"], $row1["title"]);

}

}

echo "<center>Misc.</cen­ter><br>";

while ($row1 = mysql_fetch_array($­result)) {

if ($row1["cat"] == 2) {

printf("<a href=\"pages.php?ca­t=2&id=%s\">%s</a><b­r>",
$row1["id"], $row1["title"]);

}

}

?>

</TD>

<TD>

cat.php:

<?php

if ($submit) {

if ($id) {

$sql = "UPDATE main SET content='$content',­ title='$title' cat='$cat'
WHERE id=$id";

} else {

$sql = "INSERT INTO main (content,title,cat)­ VALUES
('$content','$title­','$cat')";

}

$result = mysql_query($sql);

echo "Record updated/edited!<p>R­eturn to <A
href=\"pages.php?ca­t=$cat&id=$id\">Inde­x</a>.";

} elseif ($delete == areyousure) {

$sql = "SELECT * FROM main WHERE id=$id";

$result = mysql_query($sql);

echo "Are you sure you want to delete $title?<p><a
href=\"$PHP_SELF?ca­t=$cat&id=$id&delete­=true\">Yes</a> | <a
href=\"$PHP_SELF\">­No</a>";

} elseif ($delete == true) {

$sql = "DELETE FROM main WHERE id=$id";

$result = mysql_query($sql);

echo "$title Record deleted!<p><a
href=\"$PHP_SELF?ca­t=$cat&id=$cat\">Ret­urn</a>";

} else {

$result = mysql_query("SELECT­ * FROM main",$db);

while ($row = mysql_fetch_array($­result)) {

if ($id == $row["id"] && $cat == $row["cat"]) {

printf("<center><fo­nt size=5>%s</font></c­enter><br><br>",
$row["title"]);

printf("%s<br><br>"­, $row["content"]);

printf("<a
href=\"$PHP_SELF?ca­t=$cat&id=%s&delete=­areyousure\">(DELETE­)</a><br>",
$row["id"]);

printf("<a
href=\"$PHP_SELF?ca­t=$cat&id=%s&edit_ad­d=$cat\">(EDIT)</a><­br>",
$row["id"]);

}

}

echo "<P><a href=\"$PHP_SELF?ca­t=$cat&edit_add=$cat­\">ADD A
RECORD</a><P>";

}

?>

<?php

if ($edit_add) {

?>

<form method="post" action="pages.php?c­at=<?php echo $cat ?>">

<?php

if ($id) {

$sql = "SELECT * FROM main WHERE id=$id";

$result = mysql_query($sql);

$row = mysql_fetch_array($­result);

$id = $row["id"];

$title = $row["title"];

$cat = $row["cat"];

$content = $row["content"];

?>

<input type=hidden name="id" value="<?php echo $id ?>">

<?php

}

?>

<TABLE cellPadding="0" cellSpacing="0" border="0">

<TR>

<TD>Title:</TD>

<TD><input type="Text" name="title" value="<?php echo $title ?>"></TD>

<TD rowSpan="2" vAlign="Top">

<TABLE border="0" cellPadding="0" cellSpacing="0">
<?php

$result = mysql_query("SELECT­ * FROM cat",$db);

while ($cat = mysql_fetch_array($­result)) {

printf("<TR><TD>%s<­/TD><TD><input type=\"radio\" name=\"cat\"
value=\"%s\"></TD><­/TR>", $cat["name"], $cat["id"]);

}

?></TD></TR></TABLE­></TD></TR>

<TR>

<TD>Message:</TD>

<TD rowSpan="3"><textar­ea name="content" rows="7" cols="40"
wrap="virtual"><?ph­p echo $content ?></TEXTAREA></TD><­/TR></TABLE>

<input type="Submit" name="submit" value="Enter information">

</form>

<?php

}

?>


Anny help would be highly appreciated!
Thank You for your time.

-Ben

Add comment
Philip Olson 13 June 2003 06:12:20 permanent link ]
 
It has to do with you assuming everything will work 100%
of the time. It won't. mysql_query() returns false on
failure, check for that. Read this recent thread:

http://marc.theaims­group.com/?l=php-gen­eral&m=1055175888194­20

Also, this faq explains it:

http://www.php.net/­manual/en/faq.databa­ses.php#faq.database­s.mysqlresource

Btw, what do you expect: $register_globals; to do in your
code? It won't do anything useful.

Regards,
Philip





--
PHP General Mailing List (http://www.php.net­/)
To unsubscribe, visit: http://www.php.net/­unsub.php


Add comment
Guest 5 May 2007 10:52:12 permanent link ]
 poop
Add comment
Guest 24 April 2009 17:27:10 permanent link ]
 pooooop
Add comment
 

Add new comment

As:
Login:  Password:  
 
 
  
 
Пожалуйста, относитесь к собеседникам уважительно, не используйте нецензурные слова, не злоупотребляйте заглавными буквами, не публикуйте рекламу и объявления о купле/продаже, а также материалы нарушающие сетевой этикет или законы РФ. Ваш ip-адрес записывается.


QAIX > PHP web-programming > mysql_fetch_array():­ supplied argument is not a valid MySQL result resource 24 April 2009 17:27:10

see also:
Compiling PHP
Alias Assistance
Error while compiling mod_jk for HP-UX
pass tests:
see also:
How FDG control toner cartridge…
Quality toner cartridge of 435 436

  Copyright © 2001—2010 QAIX
Идея: Монашёв Михаил.
Авторами текстов, изображений и видео, размещённых на этой странице, являются пользователи сайта.
See Help and FAQ in the community support.qaix.com.
Write in the community about the bugs you have noticedbugs.qaix.com.
Write your offers and comments in the communities suggest.qaix.com.
Information for parents.
Пишите нам на .
If you would like to report an abuse of our service, such as a spam message, please .
Если Вы хотите пожаловаться на содержимое этой страницы, пожалуйста .