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? Link to comment https://forums.phpfreaks.com/topic/6657-problem-with-syntax/ 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] Link to comment https://forums.phpfreaks.com/topic/6657-problem-with-syntax/#findComment-24187 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.