PHP Code Syntax Error

Associate
Joined
29 May 2005
Posts
144
sorry about the nasty code, im just new to php and in the learning.

this is simply ament to add the inputs to a database. I know more validation needs done, but this is me learning, ill add more later ;)

the page is displaying the form, however not presenting me with any echo messages before or after i click the submit button. must be something wrong in the code somewhere, but i cant find or work out exactly what it is. It could possibly be a problem with my { }'s, as I get confuzing after a while ;)

can anyone see anything wrong? please dont say it all, it has took me all night to work out thus far. hehe

thanks again - mofish ;)

Code:
<?
//grrrrrrrr work!

if (isset($_GET['register'])){
	  $name = $_POST['name'];
  	  $password = $_POST['password'];
  	  $location = $_POST['location'];
  	  $email = $_POST['email'];
  	  $query = "insert into `user_details` (`name`, `password`, `location`, `email`) values ('$name', '$password', '$location', '$email')";

		if (trim($name) == ''){
            echo 'you must input a username';
		} 
		elseif (trim($password) == '') {
			echo 'you must input a password';
		} 
		elseif (trim($location) == '') {
			echo 'you must input a location';
		} 
		elseif (trim($email) == '') {
			echo 'you must input a email';
											
					if (mysql_query($query)){
						echo 'added to database succesfully';
					} else {
						echo 'error adding to database';
					}
		 
		 } else {
			echo 'they are not valid';
		 }
}
else
{
	
	?>
	
     <form action="index.php" method="post">
     <table width="260" style="border: 1px dotted; background-color:#FFFFCC">
	 <tr>
   		 <td width="106">Nick Name</td>
   		 <td width="144"><input type="text" name="name"></td>
 	 </tr>
 	 <tr>
   		 <td width="106">Password</td>
   		 <td width="144"><input type="password" name="password"></td>
 	 </tr>
 	 <tr>
   		 <td width="106">Location</td>
   		 <td width="144"><select name="location" style="width:144px">
   		  					 <option>United Kingdom</option>
   		   					 <option>USA</option>
   						 </select>
   		 </td>
 	 </tr>
	  <tr>
   		 <td width="106">Email</td>
   		 <td width="144"><input type="text" name="email"></td>
 	 </tr>
  	
	 <tr>
   	     <td colspan="2"><input name="submit" type="submit"></td>
 	 </tr>
	 
   </table>
  </form>
  <?
}
?>
 
okay i changed what you suggested, but its still not working correctly. It's still displaying the form fine, but when I fill it in and click submit it just clears the fields and displays no echo (messages) at all. i was hoping it would say that I added it successfully :) PS i checked the database, and nothing has been added. :(
 
changed as suggested, but its still doing the same thing, hehe. I checked variable names and they seem to be fine. as for the curly brackets, im confuzed as it is, im not sure about them, ive tryed following them but get lost, when i start to nest if's inside if's :)

signed up on your uploader aswell by the way. if you click 'account settings' there is a bit
Max Storange should that be Max Storage just thought id point it out, incase no-one has. :)
 
you were right! i changed that and I now see my echo error messages :) WOOHOO! unfortunately its not the one i wanted to see 'error adding to database' hehe.
 
Back
Top Bottom