whats wrong?

maxyes

New Member
Messages
24
Reaction score
0
Points
0
Code:
 [COLOR=#000000] [COLOR=#0000BB]<?php

$link [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_connect[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"localhost"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"mysql_user"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#DD0000]"mysql_password"[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000BB]mysql_select_db[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"database"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$link[/COLOR][COLOR=#007700]);

[/COLOR][COLOR=#0000BB]$result [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_query[/COLOR][COLOR=#007700]([/COLOR][COLOR=#DD0000]"SELECT * FROM table1"[/COLOR][COLOR=#007700], [/COLOR][COLOR=#0000BB]$link[/COLOR][COLOR=#007700]);
[/COLOR][COLOR=#0000BB]$num_rows [/COLOR][COLOR=#007700]= [/COLOR][COLOR=#0000BB]mysql_num_rows[/COLOR][COLOR=#007700]([/COLOR][COLOR=#0000BB]$result[/COLOR][COLOR=#007700]);

echo [/COLOR][COLOR=#DD0000]"$num_rows Rows\n"[/COLOR][COLOR=#007700];

[/COLOR][COLOR=#0000BB]?>[/COLOR] [/COLOR]

is it the php version?
 

maxyes

New Member
Messages
24
Reaction score
0
Points
0
something about line 7 error. I dont quite know because my http is down.
 

Anna

I am just me
Staff member
Messages
11,750
Reaction score
581
Points
113
it's in the echo, you need to concatenate (ie add the variable to the string) the string with the variable.

echo $num_rows . " Rows\n";

that should work

for info on various ways to use echo: http://se2.php.net/echo
 
Last edited:

Scoochi2

New Member
Messages
185
Reaction score
0
Points
0
it's in the echo, you need to concatenate (ie add the variable to the string) the string with the variable.

echo $num_rows . " Rows\n";
No you don't. You only need to do that for single quotes. Double quotes is perfectly fine.


maxyes, can you post the exact error that you see? Copy-paste it straight here. (when you can)
 
Last edited:

maxyes

New Member
Messages
24
Reaction score
0
Points
0
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/topclans/public_html/index.php on line 7
Rows
I think its to do with the databse mayby
 

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
check to make sure that the query is properly executing without any hidden errors.
PHP:
if ($result) {
  echo "good";
} else {
  echo "bad " . mysql_error();
}

Also, you don't need the $link if you've only got one open mysql connection. Just thought you might find that handy.

http://www.php.net/mysql_query said:
link_identifier

The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.
 
Last edited:

xPlozion

New Member
Messages
868
Reaction score
1
Points
0
try this and see what you get:
PHP:
<?php
mysql_connect("localhost", "mysql_user", "mysql_password");
mysql_select_db("database");

$result = mysql_query("SELECT * FROM table1");
if ($result) {
  $num_rows = mysql_num_rows($result);
  echo "$num_rows Rows\n";
} else {
  echo "bad " . mysql_error();
} 

?>
 

scopey

New Member
Messages
62
Reaction score
0
Points
0
It's a good idea when you're testing a script to put 'or die(mysql_error())' next to all your 'mysql_query()' statements. It'll just stop and print the error it's getting.

Anyway... Make sure you have your database name right. It'll be named 'maxyes_database' or something similar.
 
Last edited:
Top