Jump to content


Photo

simple count


  • Please log in to reply
3 replies to this topic

#1 highaspen

highaspen
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 March 2006 - 10:50 PM

I'm attempting to run a simple record count with the code below. It returns the die on the $rs
--------------------

<?php

include ("../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.

#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 20 March 2006 - 11:03 PM

Always (at least while debugging your code) print out the mysql_error() on a die() clause.
<?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());
?>

Also, you don't need the double quotes around the variable names.

Ken

#3 highaspen

highaspen
  • Members
  • PipPip
  • Member
  • 23 posts

Posted 20 March 2006 - 11:18 PM

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




#4 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 21 March 2006 - 12:51 AM

Fix:

$sql="SELECT COUNT(*) FROM members WHERE owner='$valid_user'";

And make sure $valid_user is set :S




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users