Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP MYsql Trouble - Pls Help


lukem_95's Avatar
Member
0 0

OK well iv been playing around witht this php site iv made for a long time now… well not really, but bits of the code are from some much earlier sites of mine. Anyway, i made a page system, where i have an iframe in the middle, and a database that has a table with name and url fields, so if something in the $_GET variable page corrosponds to the 'name', it will make the iframe link to the url from the database.

This works fine, but i have an error about the mysql_fetch_array();

markupWarning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\program files\easyphp1-8\www\ethical\indexxxx - edit.php on line 19

The relevent code looks like this:

if($page == NULL){
$page = 'home';
};

require("stats/db.php");

$rPage = mysql_query("SELECT * FROM pages WHERE name = '$page'");
$row = mysql_fetch_array($rPage))
$rPage = $row['url'];  

if($rPage == NULL){
$rPage = 'html/error.html';
};

...

<iframe name="Content" allowtransparency="True" height="640" width="447" src="<? echo $rPage; ?>" frameborder="0"></iframe>

Any ideas?


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

$row = mysql_fetch_array($rPage)) erm, what? What's with the double closing brackets ;)


lukem_95's Avatar
Member
0 0

oops wrong version of code:

thay bit was-

$rPage = $row['url'];  
}```

ghost's Avatar
0 0

Hmmm, the returned info is in an array you need to get it out one by one i haven't read all the other posts just htought this might help , and if it doesnt help you maybe someone in the future :D


lukem_95's Avatar
Member
0 0

yeh i tried that, but when i did, it gave me markupResource id #4 instead of a url. It works 100% properly this way, but i ahve an error displaying.


ghost's Avatar
0 0

while($row = mysql_fetch_array($rPage)){ $rPage = $row['url']; }

the error is here:

$rPage = $row['url'];

it should be:

$rPage = $row[url];

without the quotes around url. that should work.


SySTeM's Avatar
-=[TheOutlaw]=-
20 0

chislam wrote: [quote]while($row = mysql_fetch_array($rPage)){ $rPage = $row['url']; }

the error is here:

$rPage = $row['url'];

it should be:

$rPage = $row[url];

without the quotes around url. that should work.[/quote]

Hm, you're supposed to use the quotes though…


lukem_95's Avatar
Member
0 0

ill try, ty for suggeestions.

No i get another error with that lol. :(


ghost's Avatar
0 0

hm perhaps however i don't use fetch array, i use mysql_fetch_object and refer to sql fields like $var->fieldName


lukem_95's Avatar
Member
0 0

lol then i get the same error but with msql_fetch_object() instead of mysql_fetch_array(). I had an idea tho, im gonna try it on an actual server, not my pc.


ghost's Avatar
0 0

I'm not exactly sure why that didn't work, but it looks like parts of the code are missing, so could you post the rest.

But this is what I use and it works.

$query = "SELECT * FROM shout ORDER BY -shoutid LIMIT 10"; 
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
 $id = $row['shoutid'];
}

Edit: You have

$rPage = mysql_query("SELECT * FROM pages WHERE name = '$page'");
$row = mysql_fetch_array($rPage))
$rPage = $row['url'];

Should be

$rPage = "SELECT * FROM pages WHERE name = '$page'";
$result = mysql_query($rPage) or die(mysql_error());
$row = mysql_fetch_array($result);
$rPage = $row['url']; 

Get rid of the mysql_query() and add a $result = mysql_query($rPage)