I am relatively new to the SQL aspect of PHP.  I have a small background in
SQL programming, so I can get my way around that part.  The problem I am
having is that a query of mine is throwing back zero (0) rows of result.  I
am using some simple SQL syntax to check for the existance of a user in a db
(i.e.  SELECT $field FROM $table WHERE $field = '$value').  Now I am testing
the script and I am trying to add a user twice, which should in theory throw
an error and not allow the user to be added a second time.  Here is the
function that I created in which my errors are.  It may just be a simple
problem with my logic.  I have checked the manual and a lot of other PHP and
SQL resources.

I am running PHP 4.1.2 binary on windows connecting to MS SQL Server 2000.

if(user_exists($dbname,"users","user",$user) > 0) {
  echo "User name already taken, please choose another.";
else {
  $query = "INSERT INTO users VALUES
  $result = mssql_query($query) or die("Unable to add user");
  echo "User successfully added.<br>\n";
function user_exists($dbname, $table, $field, $value) {
  //connecting to db and getting table
  mssql_select_db($dbname) or die("Table unavailable");

  //checking existance of field:value combination
  $query = "SELECT $field FROM $table WHERE $field = '$value'";
  $result = @ mssql_query($query) or die("Unable to check existance of
  $rows = mssql_num_rows($result);
  echo "Query returned $rows row(s) of data.<br><br>\n";
  return $rows;

Any help that anyone can provide would be a big help.  Thanks in advance.

Joshua E Minnie/CIO
Phone: 616.276.9690
Fax: 616.342.8750
Nextel: 616.862.2847

"Don't work for recognition, but always do work worthy of recognition."

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to