Jump to content

Archived

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

highaspen

simple count

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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


Share this post


Link to post
Share on other sites
Fix:

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

And make sure $valid_user is set :S

Share this post


Link to post
Share on other sites

×

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.