Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Messages - dsm

Pages: [1]
1
MySQL database / Problem with mysql_fetch_assoc
« on: August 11, 2004, 10:48:24 AM »
I am trying to query the database to see if the username that someone requests is already taken by another user. My code looks like this:

   else if ($_POST) { // if someone has submited a POST form, this will be true
    $link = mysql_connect("localhost","businessinme","bua645");
    mysql_select_db("business");
   
   $query = "SELECT COUNT (*) as numUsers FROM users WHERE
   username='".$_POST['username'];
   $res = mysql_query($query);
   if (!$res) {
    die("MySQL error happened with query: $query error: ".mysql_error());
}
   $row = mysql_fetch_assoc($res);
   if ($row['numUsers'] > 0) {
    print 'The username you specified has already been registered by another member.<br />'
      .'Please hit the back button and choose a different username.!';
   mysql_close($link);
      exit;
}
}

When I try to run this bit I keep getting the following error message:

MySQL error happened with query: SELECT COUNT (*) as numUsers FROM users WHERE username='dsm error: You have an error in your SQL syntax near '(*) as numUsers FROM users WHERE username='dsm' at line 1

Could someone let me know where I'm going wrong. Thanks

Pages: [1]