mysql errors

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

mysql errors

Post by nite4000 »

hey all

i have this code that i am trying to fix but i am getting errors

here is the code

Code: Select all


<?php
session_start();
require_once('../inc/db.php');
$dbc = db_connect();
require_once('../inc/check_login.php');
include('../inc/functions.php');
include('vars.php');
include('header.php');


$res = mysql_query("select * from members where id='" . $_SESSION['admin_id'] . "'");
  $con = mysql_fetch_array($res, MYSQL_ASSOC);
  @mysql_free_result($res);


if (mysql_num_rows($res) != 0) {
}
$usrid = $memb['id'];
$credits = mysql_result($res, 0, "credits");
$credits = round($credits, 2);

echo("<p class=big><a href=$self_url" . "accounts/index.php title=\"Back to main page\"><font face=$fontface size=2><b>User account #$usrid</b></font></a><font face=$fontface size=2> : : Allocate credits</p>");
echo("<p>You have <b><font color=red>$credits</font></b> credit(s)");
echo(" on your account.<br>You can allocate ");
if ($credits > 1) {echo("them");} else {echo("it");}
echo(" to the following site(s):<br>
<table border=0 cellpadding=2>
<form action=$self_url" . "accounts/index.php method=post>
<input type=hidden name=fform value=allocate><tr style=\"background-color: $cellbg1\">
<td align=left><font size=2>URL</td><td align=left><font size=2>Site credits</td>
<td align=left><font size=2>Allocate</td></tr>");
$res = mysql_query("select id, url, credits from site where usrid='{$memb['id']}' order by id asc");
  $con1 = mysql_fetch_array($res, MYSQL_ASSOC);
  @mysql_free_result($res);
for ($i = 1; $i < mysql_num_rows($res); $i++) {


    $id = $con1['id'];
    $url = mysql_result($res, $i, "url");
    $scred = mysql_result($res, $i, "credits");
    $scred = round($scred, 2);
    $name = "_" . $id;
    echo("<tr style=\"background-color: $cellbg2\"><td>
    <font size=2>$url</td><td><font size=2>$scred</td>
    <td><input type=text size=5 name=$name value=0 class=webforms></td></tr>");
}
echo("<tr>
<td colspan=3 align=right>
<input type=submit value=\"Allocate\" class=\"formbutton\"></td></tr></form>
<tr><form action=$self_url" . "accounts/ method=post>
<input type=hidden name=fform value=nope><td align=right colspan=3>
<input type=submit value=\"Cancel\" class=\"formbutton\"></td></tr></form></table></p>");
mysql_close;
exit;

?>
<?php
include('footer.php');
?>

here is the errors i get

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myscript/public_html/xtremepro/accounts/allocate.php on line 12

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/myscript/public_html/xtremepro/accounts/allocate.php on line 16

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/myscript/public_html/xtremepro/accounts/allocate.php on line 19

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/myscript/public_html/xtremepro/accounts/allocate.php on line 33

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/myscript/public_html/xtremepro/accounts/allocate.php on line 35


any help i can get would be great
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: mysql errors

Post by califdon »

You have freed the result $res before you try to use it. Just remove the line: @mysql_free_result($res);
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: mysql errors

Post by nite4000 »

that didnt help still have errors
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: mysql errors

Post by califdon »

nite4000 wrote:that didnt help still have errors
Without knowing what those errors are, I have no idea.
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: mysql errors

Post by nite4000 »

same as the ones i posted it removed like 1 error but rest is still there
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: mysql errors

Post by califdon »

nite4000 wrote:same as the ones i posted it removed like 1 error but rest is still there
OK. The message "...supplied argument is not a valid MySQL result resource..." means that the MySQL function you are trying to use (fetch_array, num_rows, etc.) are referencing a result that doesn't exist. That is usually because the mysql_query function earlier failed. To see why it failed, you should temporarily add the or die(...) clause to your mysql_query function:

Code: Select all

$res = mysql_query("select id, url, credits from site where usrid='{$memb['id']}' order by id asc") or die(mysql_error());
That will display an error message if the mysql_query function fails. After you have resolved the problem, you should remove the "or die(...)" because it could reveal information about your server if a hacker ran your program.
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: mysql errors

Post by nite4000 »

ok i resolved all errors thanks for help but here is another problem related to this.

there should be some site info showing from the db but its not could this line here

for ($i = 0; $i > mysql_num_rows($res); $i++) {

have anything to do with it its the orginal line even though its different from the top of what i posted
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: mysql errors

Post by califdon »

nite4000 wrote:ok i resolved all errors thanks for help but here is another problem related to this.

there should be some site info showing from the db but its not could this line here

for ($i = 0; $i > mysql_num_rows($res); $i++) {

have anything to do with it its the orginal line even though its different from the top of what i posted
Did you remove the mysql_free_result($res) line from BOTH places? You see, if you free a result, that means you can't use it after that. There's really no reason to ever do that, since PHP automatically frees results when the script ends.
nite4000
Forum Contributor
Posts: 209
Joined: Sun Apr 12, 2009 11:31 am

Re: mysql errors

Post by nite4000 »

yes i did remove it and in fact the orginal code is working now since fixing the errors

i did a var_export of the select id,url,credits query and this is the error i got

Warning: var_export() expects parameter 2 to be boolean, resource given in /home/myscript/public_html/xtremepro/accounts/allocate.php on line 32

so its not getting the info but i dont see anything stopping it.

i am going to repost all code to let you see what i currently have

Code: Select all


<?php
session_start();
require_once('../inc/db.php');
$dbc = db_connect();
require_once('../inc/check_login.php');
include('../inc/functions.php');
include('vars.php');
include('header.php');


$res = mysql_query("select * from members where id='" . $_SESSION['admin_id'] . "'",$dbc);
  $con = mysql_fetch_array($res, MYSQL_ASSOC);


if (mysql_num_rows($res) > 0) {
}
$usrid = $memb['id'];
$credits = $memb['credits'];
$credits = round($credits, 2);

echo("<p class=big><a href=$self_url" . "accounts/index.php title=\"Back to main page\"><font face=$fontface size=2><b>User account #$usrid</b></font></a><font face=$fontface size=2> : : Allocate credits</p>");
echo("<p>You have <b><font color=red>$credits</font></b> credit(s)");
echo(" on your account.<br>You can allocate ");
if ($credits > 1) {echo("them");} else {echo("it");}
echo(" to the following site(s):<br>
<table border=0 cellpadding=2>
<form action=$self_url" . "accounts/index.php method=post>
<input type=hidden name=fform value=allocate><tr style=\"background-color: $cellbg1\">
<td align=left><font size=2>URL</td><td align=left><font size=2>Site credits</td>
<td align=left><font size=2>Allocate</td></tr>");
$res = mysql_query("select id, url, credits from site where usrid='{$memb['id']}' order by id asc",$dbc);
var_export("select id, url, credits from site where usrid='{$memb['id']}' order by id asc",$dbc);
  
for ($i = 0; $i > mysql_num_rows($res); $i++) {


    $id = mysql_result($res, $i, "id");
    $url = mysql_result($res, $i, "url");
    $scred = mysql_result($res, $i, "credits");
    $scred = round($scred, 2);
    $name = "_" . $id;
    echo("<tr style=\"background-color: $cellbg2\"><td>
    <font size=2>$url</td><td><font size=2>$scred</td>
    <td><input type=text size=5 name=$name value=0 class=webforms></td></tr>");
}
echo("<tr>
<td colspan=3 align=right>
<input type=submit value=\"Allocate\" class=\"formbutton\"></td></tr></form>
<tr><form action=$self_url" . "accounts/ method=post>
<input type=hidden name=fform value=nope><td align=right colspan=3>
<input type=submit value=\"Cancel\" class=\"formbutton\"></td></tr></form></table></p>");
mysql_close;
exit;

?>
<?php
include('footer.php');
?>
 

thanks
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: mysql errors

Post by califdon »

  1. You are only posting part of the code, since you are not posting any of the includes, so I can't tell, for example, where you are getting values for the $memb array.
  2. I have never used the var_export() function. When I looked it up in the manual, I am puzzled what you are trying to do with it. The error message is complaining that you are sending it the wrong parameters. var_export is not a database function, you cannot send it a query and a database connection, like you would mysql_query(). It is a special function for outputting arrays and such.
  3. I will be away from home most of the rest of today, so I won't be able to help you more today.
Post Reply