How to display error


#1

I have been trying to follow this tutorial from mmtuts:

I can't get my first part of the tutorial to work but can manage to get the second one. I guess he did say that the second one is better but I am not sure why my first method does work? Here is my code overall so I hope you guys can understand what I am trying to do here... I will put my second code in quotation but it might be incomplete...

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>
<form action="includes/signup2.php" method="POST">
	<?php
       if(isset($_GET['firstname'])) {
          $first = $_GET['firstname'];
          echo '<input type="text" name="firstname" placeholder="firstname" value="'.$first.'">';
       }
       else {
       	  echo '<input type="text" name="firstname"   placeholder="firstname">';
       }
       if(isset($_GET['lastname'])) {
          $last = $_GET['lastname'];
          echo ' <input type="text" name="lastname" placeholder="lastname" value="'.$last.'">';
       }
       else {
       	  echo '<input type="text" name="lastname" placeholder="lastname">';
       }
       if(isset($_GET['username'])) {
          $uid = $_GET['username'];
          echo ' <input type="text" name="username" placeholder="username" value="'.$uid.'">';
       }
       else {
          echo '<input type="text" name="username" placeholder="username">';
       }

	?>
   
   
  
   <input type="text" name="email" placeholder="email">
   <input type="text" name="password" placeholder="password">
   <input type="submit" name="submit" values="register">
</form>

<?php


$fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

if(strpos($fullURL, "signup=empty") == true) {
   echo "You did not fill in all fields!";
   exit();
}

elsef(strpos($fullURL, "signup=char") == true) {
   echo "You used invalid characters!";
    exit();
}

elsef(strpos($fullURL, "signup=email") == true) {
   echo "You used an invalid e-mail!!";
   exit();
}

elsef(strpos($fullURL, "signup=success") == true) {
   echo "You have been signed up!";
}


/*

if(!isset($_GET['signup'])) {
   exit();
}
else {
   $signupCheck = $_GET['signup'];

   if($signupCheck == "empty") {
      echo "You did not fill in all fields!";
      exit();
   }
   elseif($signupCheck == "char") {
      echo "You used invalid characters!";
      exit();
   }
   elseif($signupCheck == "email") {
      echo "You used an invalid e-mail!!";
      exit();
   }
   elseif($signupCheck == "success") {
      echo "You have been signed up!";
      exit();
   }
}

*/


?>
</body>
</html>

This is my other file:

?php


if(isset($_POST['submit'])) {
   include_once 'dbh.php';

   $username = $_POST['username'];
   $firstname = $_POST['firstname'];
   $lastname = $_POST['lastname'];
   $email = $_POST['email'];
   $password = $_POST['password'];

   // Throw error messages first and then success messages

   if(empty($username) || empty($firstname) || empty($lastname) || empty($email) || empty($password)) {
      header('Location: ../index6.php?signup=empty');
      exit(); // close off the script.... 
   }
   else {
      if(!preg_match("/^[a-zA-Z]*$/", $firstname) || !preg_match("/^[a-zA-Z]*$/", $Lastname)) {
      header('Location: ../index6.php?signup=char');
      exit();
      }

   else {
      if(!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      header("Location: ../index6.php?signup=email&firstname=$firstname&lastname=$lastname&username=$username");
      exit();
      }
      else {
      	header('Location: ../index6.php?signup=success');
      	exit();
      }
   

   }
}
}
else {
	header('Location: ../index6.php');
}

I get the following errors:

Parse error: syntax error, unexpected 'echo' (T_ECHO) in C:\xampp\htdocs\phplessons\index6.php on line 51

I don't think I did make any mistakes while typing but then again, I might have...


#2

You have a type here: elsef`


#3

You need to find a better tutorial. You have twice as much code as you need. Do not create variables for nothing. You already have the post variables. Just use them.


#4

I have worked out the problem... I have a typo and it should be elseif instead of elsef but now I have the following warnings:

Notice: Undefined variable: fullURL in C:\xampp\htdocs\phplessons\index6.php on line 45

Notice: Undefined variable: fullURL in C:\xampp\htdocs\phplessons\index6.php on line 50

Notice: Undefined variable: fullURL in C:\xampp\htdocs\phplessons\index6.php on line 55

Notice: Undefined variable: fullURL in C:\xampp\htdocs\phplessons\index6.php on line 60


#6

Look for typos here too - fullUrl or fullURL? Variable names are case-sensitive.


#7

I have checked the video and it is fullUrl...

cheers!


#8

So you fixed the typo and your code is now working?


#9

I haven't tried it yet because i am trying to get my login to work first


#11

Stop. Using. Mmtuts.

Seriously.

All of their stuff is old and outdated. Find some different source. Please.


#12

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.