highaspen Posted March 20, 2006 Share Posted March 20, 2006 I'm attempting to run a simple record count with the code below. It returns the die on the $rs--------------------<?phpinclude ("../global_vars.php");$valid_user = $_POST['userid'];#connect to MySQL$conn=@mysql_connect("$dbserver", "$dbuser","$dbpass")or die("Could not connect");#select the specified database$rs = @mysql_select_db("$dbtable", $conn)or die("Could not select database");#create the query$sql="SELECT COUNT(*) FROM from members WHERE owner='$valid_user' ";#execute the query$rs=mysql_query($sql,$conn)or die("Could not execute query");$rs = mysql_fetch_array($rs);?>------------------------------any ideas? I appreciate any insight... rather new at this. thanks. Quote Link to comment https://forums.phpfreaks.com/topic/5374-simple-count/ Share on other sites More sharing options...
kenrbnsn Posted March 20, 2006 Share Posted March 20, 2006 Always (at least while debugging your code) print out the mysql_error() on a die() clause.[code]<?php$conn=@mysql_connect($dbserver, $dbuser, $dbpass) or die('Could not connect. Error: ' . mysql_error());#select the specified database$rs = @mysql_select_db($dbtable, $conn) or die('Could not select database. Error: '. mysql_error());?>[/code]Also, you don't need the double quotes around the variable names.Ken Quote Link to comment https://forums.phpfreaks.com/topic/5374-simple-count/#findComment-19163 Share on other sites More sharing options...
highaspen Posted March 20, 2006 Author Share Posted March 20, 2006 Thanks here is the mqsql error I get.Could not execute query. Error: You have an error in your SQL syntax near 'from members WHERE owner=demo ' at line 1 Quote Link to comment https://forums.phpfreaks.com/topic/5374-simple-count/#findComment-19170 Share on other sites More sharing options...
High_-_Tek Posted March 21, 2006 Share Posted March 21, 2006 Fix:[code]$sql="SELECT COUNT(*) FROM members WHERE owner='$valid_user'";[/code]And make sure $valid_user is set :S Quote Link to comment https://forums.phpfreaks.com/topic/5374-simple-count/#findComment-19185 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.