Jump to content

Problem with syntax


FuG5333

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?
Link to comment
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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.