Jump to content

HTML and PHP Error


pmi

Recommended Posts

I had this working before. I have errors in PHP and I don't think the code will run. Any suggestions would be much appreciated,

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>

<link href="test.css" rel="stylesheet" type="text/css" />
</head>

<body>

<div class="container">
  <div class="header"><!-- end .header --></div>
  <div id="h-navbar"><a href="#">Home</a> | <a href="#">About Us</a> | <a href="#">Contact Us</a></div>
  <div class="sidebar1">
    <ul class="nav">
      <li><a href="#">Inventory</a></li>
      <li><a href="#">Financing</a></li>
      <li><a href="#">Service</a></li>
      <li><a href="#">Promotions</a></li>
    </ul>

    <p>sidebar</p>
    <p>(hours & location)</p>
  <!-- end .sidebar1 --></div>
  <div class="content">
    <h1 align="center">Sign up for Deals & Special Offers!</h1>
    <?php
$displayForm = true;
if (isset($_POST['submit']))
{
$displayForm = false;
}

if (isset($_POST['username'], $_POST['email'], $_POST['age'], $_POST['password']))
{
$errors = array();

$username = $_POST['username'];
$age = $_POST['age'];
$email = $_POST['email'];
$password = $_POST['password'];

/*
if (empty($name) || empty($age) || empty($email) || empty($password))
{
$errors[] = 'All fields are required!';
}
else
*/

//allows only letters and numbers for username
if (!ctype_alnum($username))
{
 $errors[] = 'Name must contain a combination of letters and numbers only!';
 }
// age must be numeric
if (!preg_match ("/^([0-9]+)$/", $age))
{
$errors[] = 'Age must be a number!';
}
//email must be valid
if (!filter_var($email, FILTER_VALIDATE_EMAIL) == true)
{
$errors[] = 'You must enter a valid email!';
}

//password must be between 8 and 16 characters in length
//password must only contain letters and numbers
if (!preg_match("/^[a-z0-9]{8,16}$/i", $password))
{
$errors[] = 'Password invalid, must be between 8 and 16 characters!';
}
// if there are validation errors, loops and outputs errors stored in array
if (!empty($errors))
{
foreach ($errors as $error)
{
echo  $error;
}
}
//if there are no validation errors, confirms registration
else
{
echo "Thanks for registering!"
echo "Your username is: " . $username
echo "Your email address is: " . $email
echo "Your age is: " . $age,
echo "Your password is: " . $password

$file_name = fopen('registrationfile.csv', 'a+');
$record = array( $username, $email, $age, $password);
fputcsv($file_name, $record);
fclose($file_name);
}
}
if ($displayForm)
{
?>
<p>
<form action="" method="post">
<label>Username:</label> <input type="text" name="username" /><br>
<label>Email:</label> <input type="text" name="email" /><br>
<label>Age:</label> <input type="text" name="age" /><br>
<label>Password:</label> <input type="password" name="password" /><br>

<input type="submit" name="submit" value="Register" />
</form>
<p>


    <p>content</p>
    
  <!-- end .content --></div>
  <div class="footer">
    <p>Copyright 2013 - Quality Auto Group</p>    
  <!-- end .footer --></div>
<!-- end .container --></div>
</body>
</html>
 

Link to comment
Share on other sites

Please use the [code][/code] tags around your code, as it helps make both your post and your code a lot easier to read.

Not to mention, explain your problem in detail. With examples of what you want, and what you are actually getting. After all, the more information you give us, the easier it'll be for us to help you.

Link to comment
Share on other sites

Guest lenix

Try to change this lines to:

 

echo "Thanks for registering!";

echo "Your username is: $username";
echo "Your email address is: $email";
echo "Your age is: $age";
echo "Your password is: $password";
Link to comment
Share on other sites

That was one out of four questions filled. Plus an infraction by hijacking someone else's thread. You're not making it easy, nor very desirable to help you, you know.

Why should we spend our free time to try to help you, when you're not even taking the time to read our posts (or rules) properly?

 

We're here to help those who want to learn, not to waste our time or work for free.

Edited by Christian F.
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.