Jump to content

Archived

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

FuG5333

Problem with syntax

Recommended Posts

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:

[code]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";

    }[/code]

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

Share this post


Link to post
Share on other sites
instead of just putting your query inside the if statement, you'll need to see if any rows are returned:

[code]
<?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();
}
?>
[/code]

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.