aabid Posted March 12, 2011 Share Posted March 12, 2011 Hi I was just writing an script on which i got an error and i can't find why and where i made it wrong. here is the code <?php include(dbinfo.inc); if(isset($_POST[submit])) { foreach($_POST as $field=>$value) { if(empty($value)) { echo "All fields are required, Please enter all the details in the form"; exit(); } } // Transfering POST variables into local variables $username = $_POST[username]; $password = $_POST[password]; $enroll = $_POST[enroll]; $email = $_POST[email]; $actype = $_POST[actype]; $firstname = $_POST[firstname]; $lastname = $_POST[lastname]; $connect = mysql_connect($host,$account,$password) or die("Couldn't connect to the database"); mysql_select_db($dbname, $connect); //Check if username already exist $sql = "Select * from memberinfo where username='$username'"; $result = mysql_query($sql, $connect); if(mysql_num_rows($result) > 0) { echo "username already exist"; } else { $sql = "INSERT INTO memberinfo (enroll, username, password, type, first_name, last_name) VALUES ($enroll, '$username', $password, '$firstname', '$lastname', '$actype')"; mysql_query($sql, $connect) or die("coudn't connnect to DB"); } } echo "<html> <head> <title>Register Form</title> </head> <body>"; include(form.inc); echo "</body></html>"; ?> the error is Parse error: syntax error, unexpected T_ELSE in C:\xampp\htdocs\vits\register.php on line 30 please help me on this.... Link to comment https://forums.phpfreaks.com/topic/230424-unexpected-t_else-parse-error/ Share on other sites More sharing options...
Pikachu2000 Posted March 12, 2011 Share Posted March 12, 2011 It doesn't generate that parse error for me, but there are a lot of 'undefined constant' warnings generated resulting from array indices not being quoted, and filenames in include()s not being quoted. Link to comment https://forums.phpfreaks.com/topic/230424-unexpected-t_else-parse-error/#findComment-1186622 Share on other sites More sharing options...
kenrbnsn Posted March 12, 2011 Share Posted March 12, 2011 I don't get any syntax errors with your posted code, but I do see a logic error: You do: <?php $username = $_POST[username]; $password = $_POST[password]; $enroll = $_POST[enroll]; $email = $_POST[email]; $actype = $_POST[actype]; $firstname = $_POST[firstname]; $lastname = $_POST[lastname]; $connect = mysql_connect($host,$account,$password) or die("Couldn't connect to the database"); ?> Which says to me that you're using the $password that's been sent in the form. I don't think you want to do that. Move the mysql_connect to above that block of code. Ken Link to comment https://forums.phpfreaks.com/topic/230424-unexpected-t_else-parse-error/#findComment-1186624 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.