Jump to content


Photo

Problem with syntax


  • Please log in to reply
1 reply to this topic

#1 FuG5333

FuG5333
  • Members
  • Pip
  • Newbie
  • 7 posts
  • LocationGreenville, SC

Posted 05 April 2006 - 01:56 PM

I have a signup list. Everything works except I want to be able to only allow people to signup once. If not then display a messge saying so. Here's what I have so far:

function addname1()
    {
    $first_name = $_SESSION['first_name'];
    $username = $_SESSION['username'];

    connect();
    if (mysql_query(SELECT * FROM calendar WHERE $username = $_SESSION['username'])) { echo "You're already signed up!; exit(); }
    $sql = "INSERT INTO calendar (first_name, username, caldate)
                        VALUES('$first_name', '$username', now())";
    $query = mysql_query($sql);
    if ( !$query )
        {
        echo "didn't work...";
        exit();
        }
    echo "$first_name added for day";

    }

I can signup but just want to limit the times you can signup to one time. Ideas?

#2 obsidian

obsidian
  • Staff Alumni
  • Advanced Member
  • 3,202 posts
  • LocationSeattle, WA

Posted 05 April 2006 - 02:09 PM

instead of just putting your query inside the if statement, you'll need to see if any rows are returned:

<?php
// change this:
if (mysql_query(SELECT * FROM calendar WHERE $username = $_SESSION['username'])) { echo "You're already signed up!; exit(); }

// to this:
$sql = mysql_query("SELECT * FROM calendar WHERE username = '$_SESSION[username]'");
if (mysql_num_rows($sql) > 0) {
  echo "You're already signed up!";
  exit();
}
?>

You can't win, you can't lose, you can't break even... you can't even get out of the game.

<?php
while (count($life->getQuestions()) > 0)
{   $life->study(); } ?>
  LINKS: PHP: Manual MySQL: Manual PostgreSQL: Manual (X)HTML: Validate It! CSS: A List Apart | IE bug fixes | Zen Garden | Validate It! JavaScript: Reference Cards RegEx: Everything RegEx




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users