dudejma Posted July 12, 2010 Share Posted July 12, 2010 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 More sharing options...
TeddyKiller Posted July 12, 2010 Share Posted July 12, 2010 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 More sharing options...
dudejma Posted July 12, 2010 Author Share Posted July 12, 2010 Thanks you so much! I'm such a newbie! I'm trying to learn it, but it's just so confusing! LOL! Thanks! Link to comment https://forums.phpfreaks.com/topic/207525-whats-wrong/#findComment-1084951 Share on other sites More sharing options...
TeddyKiller Posted July 12, 2010 Share Posted July 12, 2010 Thanks you so much! I'm such a newbie! I'm trying to learn it, but it's just so confusing! LOL! Thanks! NP. Seeing as it's simple stuff you are having issues with, ... so far anywho, feel free to just PM me. Link to comment https://forums.phpfreaks.com/topic/207525-whats-wrong/#findComment-1084952 Share on other sites More sharing options...
Pikachu2000 Posted July 12, 2010 Share Posted July 12, 2010 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 More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.