Jump to content

What's wrong


dudejma

Recommended Posts

Please excuse this if it is something that I should know, I'm VERY new to PHP.

 

This is the error I get:

Parse error: syntax error, unexpected T_VARIABLE, expecting '(' in /home/virtu857/public_html/aandwtechsupport.co.cc/admin.php on line 113

 

Code:

<?php

$link = mysql_connect("localhost", "virtu857_newuser", "JMAJMA6497");
mysql_select_db("virtu857_newusers", $link);

$result = mysql_query("SELECT * FROM Users", $link);
$num_rows = mysql_num_rows($result);

echo "There are $num_rows new users.\n";

if $num_rows = "0";
echo "";

else
echo "Please register them.";

?>

 

Line 113:

if $num_rows = "0";

 

Thanks!

Link to comment
https://forums.phpfreaks.com/topic/207525-whats-wrong/
Share on other sites

If statements should have brackets.

 

if ($num_rows = "0")
{
    echo "";
}
else
{
    echo "Please register them.";
}

 

Two other problems, seeing as your first echo is not needed, you can remove it. Also, you use $num_rows = "0" which I believe should be $num_rows == "0"

 

Use this..

if ($num_rows != "0") // the != means IS NOT
{
    echo "Please register them.";
}

Link to comment
https://forums.phpfreaks.com/topic/207525-whats-wrong/#findComment-1084950
Share on other sites

mysql_num_rows should only be used when counting a retrieved result set that is going to be used for something besides the count. It's slow, and calling it with a wildcard SELECT * is even worse. COUNT() is a much better way to do it when all you need is the number of records. Also, I don't see any way for the query to determine which users are new and which aren't. Are there separate tables for new and um, well, 'not-so-new' users?

 

This is about 200 times faster than using mysql_num_rows() with a wildcard.

<?php
$link = mysql_connect("localhost", "virtu857_newuser", "JMAJMA6497");
mysql_select_db("virtu857_newusers", $link);

$query = "SELECT COUNT(`your_index_field_name`) as count FROM Users";
$result = mysql_query($query, $link);
$array = mysql_fetch_assoc($result);
if( $array['count'] > 0 ) {
echo "There are $result new users. Please register them.";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/207525-whats-wrong/#findComment-1084979
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.