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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.