jamieh Posted May 13, 2008 Share Posted May 13, 2008 Hi there, I'm new to this forum so hi to everyone I've just started learning PHP, and i'm trying to create a basic for for people to signup to gaming tournaments etc. It's only REALLY basic so only consists of a few lines as we speak, but will make it a lot bigger as i get better. I'm having some problems with if commands etc, trying to use variables with mysql and so on.. Here is the little script i have here following the odd tutorial: insert.php <?php $con = mysql_connect("localhost","fuzglcom_jamie","vectra111"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fuzglcom_fuzcup", $con); $sql="INSERT INTO teams (TeamName, Website, Email, Leader) VALUES ('$_POST[teamname]','$_POST[website]','$_POST[email]','$POST_[leader]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; else { ($count > 0) { echo "Email already in database!"; } mysql_close($con) ?> config.php <?php $email = mysql_query("SELECT * FROM teams WHERE email = '[$POST_[email]'") or die (mysql_error()); $count = mysql_num_rows($email); ?> Here's the error i face: Parse error: syntax error, unexpected T_ELSE in /home1/fuzglcom/public_html/test/insert.php on line 20 Pretty simple to you coders i know i've nested something wrong or i obviously need to get the hang of IF commands and where they go etc. I may well easily be an idiot but if you could possibly help me that would be great. Many thanks, Jamie Link to comment https://forums.phpfreaks.com/topic/105480-basic-mysqlphp-form-help-please/ Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 you're missing a } before the else also, you'll want something more like this in your sql (add curly brackets for array values): ('{$_POST[teamname]}','{$_POST[website]}','{$_POST[email]}','{$POST_[leader]}')"; Link to comment https://forums.phpfreaks.com/topic/105480-basic-mysqlphp-form-help-please/#findComment-540271 Share on other sites More sharing options...
jamieh Posted May 13, 2008 Author Share Posted May 13, 2008 Thanks for the quick reply. It appears there is an unexpected "}" on line 20, so i'm assuming i've missed putting a "{" some where before that? Thanks for the other information, Jamie Link to comment https://forums.phpfreaks.com/topic/105480-basic-mysqlphp-form-help-please/#findComment-540278 Share on other sites More sharing options...
BlueSkyIS Posted May 13, 2008 Share Posted May 13, 2008 i think the bracket wasn't missing, it just had this after it: echo "1 record added"; that is the line that was messing it up. Link to comment https://forums.phpfreaks.com/topic/105480-basic-mysqlphp-form-help-please/#findComment-540280 Share on other sites More sharing options...
jamieh Posted May 13, 2008 Author Share Posted May 13, 2008 Ah i see.. so i've pretty much placed the "echo" content in the wrong place? Basically i want it so if the email is already registered in the database i'd like the registrar to be errored with a message. Thanks, Jamie Link to comment https://forums.phpfreaks.com/topic/105480-basic-mysqlphp-form-help-please/#findComment-540288 Share on other sites More sharing options...
Loldongs Posted May 13, 2008 Share Posted May 13, 2008 <?php $con = mysql_connect("localhost","fuzglcom_jamie","vectra111"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("fuzglcom_fuzcup", $con); $sql1 = sprintf("SELECT * FROM `teams` WHERE `Email` = '%s'", $_POST['email']); $result1 = mysql_query($sql1,$con); if (!$result1) { die('Error: ' . mysql_error()); } if (mysql_num_rows($result) > 0) { die("WE ALREADY HAVE THAT EMAIL ADDRESS"); } $sql="INSERT INTO teams (TeamName, Website, Email, Leader) VALUES ('$_POST[teamname]','$_POST[website]','$_POST[email]','$POST_[leader]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } echo "1 record added"; mysql_close($con) ?> Link to comment https://forums.phpfreaks.com/topic/105480-basic-mysqlphp-form-help-please/#findComment-540399 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.