FuG5333 Posted April 5, 2006 Share Posted April 5, 2006 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? Quote Link to comment Share on other sites More sharing options...
obsidian Posted April 5, 2006 Share Posted April 5, 2006 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] Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.