Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am stuck on this assignment. I have an error that I cant find and I dont know

ID: 3543353 • Letter: I

Question

I am stuck on this assignment. I have an error that I cant find and I dont know where to go from here. Can someone please help me finish this??? My code is below

Create a form that submits to itself using  the action of '$PHP_SELF'.  Use a method of POST. Make the required fields the same as on the example page:


If the user does not enter a required field or has not met all the other rules of the form (password at least four characters, both password fields matching) - this means that the validation has failed, so show the whole form again and remember what the user has already filled in (hint: value=""".$_POST['fieldname']."").

Tell the user which field he/she has missed (generally this is done in order, so if the first field is username and they do not fill it in, tell them they missed that before you tell them they missed the email field).

Style the form and the results as if the form is not just an assignment, but one that you are actually placing on the web.

<?php
function printForm($strMessage){
echo "<strong>" .$strMessage."</strong>";
echo "<form method="post" action="" .$_SERVER['PHP_SELF']. "" name="form"> ";
echo " Name:<input type="text" name="name" value=" " .trim($_POST['name'])."";
echo " Email:<input type="text" name="email" value=" " .trim($_POST['email'])."";
echo " Username:<input type="text" name="uname" value=" " .trim($_POST['uname'])."";
echo " Password:<input type="text" name="pword" value=" " .trim($_POST['pword'])."";
echo " Re-enter Password:<input type="text" name="pwordRep" value=" " .trim($_POST['pwordRep'])."".;
echo  "<input type = "submit" value="send" name="submit"/> ";
echo "</form> ";
}
?>
<html>
<head>
<title> Form Submission</title>
</head>
<body>
<?php
if(isset($_POST['submit'])){
  $name=trim($_POST['name']);
  $email=trim($_POST['email']);
  $uname=trim($_POST['uname']);
  $pword=trim($_POST['pword']);
  $pwordRep=trim($_POST['pwordRep']);
  if ($name==""){
   $strMessage="Please enter your first name.";
   pringtForm($strMessage);
  }
  elseif ($email==""){
   $strMessage="Please enter your email address.";
   pringtForm($strMessage);
  }
  elseif ($uname==""){
     $strMessage="Please enter your username.";
     pringtForm($strMessage);
  }
  elseif ($pword==""){
     $strMessage="Please enter your password.";
     pringtForm($strMessage);
  }
  elseif ($pwordRep==""){
     $strMessage="Please re-enter your password.";
     pringtForm($strMessage);
  }
  else{
   $strMessage="Thank you for your submission.";
   echo $strMessage;
  }
}//close outer if
else{
  $strMessage="Please enter all the fields below.";
  printForm($strMessage);
}
?>
</body>
</html>

Explanation / Answer

<?php


function redirect_to($location = NULL)

{

if($location!=NULL)

{

header("Location:{$location}");

//echo $location;

exit;

}

}

?>


<?php

if(isset($_REQUEST["msg"]))

{

echo $_REQUEST["msg"];

}

  

if(isset($_POST['submit']))

{   

$username=$_POST['username'];

$password=$_POST['password'];

$confirmpassword=$_POST['confirmpassword'];

// if($username==""){echo "Please Enter username";}

$email=$_POST['email'];

if($username!=""&& $password!=""&&$confirmpassword!=""&&$email!="")

{

if( $password==$confirmpassword){

$query=("INSERT INTO fields VALUES(NULL,'".$username."','".$password."','".$email."')");

  

if(mysql_query($query))

echo ("<strong>'".$username."'</strong>congrats you have been signed ");

}

else

{

  

redirect_to("index.php? msg= <font style = color:red> <b>******passwords didnot match please re-enter </b></text>" );   

}

}

else

{

redirect_to("index.php? msg= <font style = color:red><b>****please fill in the necessary details****</b> " );

}

}

else {

  

?>   

<html>

function

<form action="index.php" method="POST"><table

<tr><th>USERNAME <br/><input type="text"name="username"style="text-align:center;" placeholder="enter name"></th></tr>

  

<br/>

<tr> <th> PASSWORD <br/><input type="password"name="password"placeholder="enter password"><br/></th></tr>

<tr><th> CONFIRM-PASS <br/> <input type="password"name="confirmpassword"placeholder="enter again"><br/></tr></th>

<tr><th> E-MAIL <br/><input type="email"name="email"placeholder="enter email"><br/><br/></th></tr>

<tr> <th> <input type="submit"name="submit"value="sign in"></th></tr>

</table> </form>

<strong>

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote