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
https://forums.phpfreaks.com/topic/6657-problem-with-syntax/
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
https://forums.phpfreaks.com/topic/6657-problem-with-syntax/#findComment-24187
Share on other sites

Archived

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

×
×
  • 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.