Jump to content

Unexpected T_else parse error ????


aabid

Recommended Posts

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

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.

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

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.