Jump to content

Combining Pages


mikebyrne

Recommended Posts

I'm trying to combine my start & signup page into the one file but It keeps causeing Apachi to crash. Is there a way to do this??

 

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sign UP</title>
</head>

<body>
<td><form name="form1" method="post" action="signup_ac.php">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Name:</td>
      <td><input type="text" name="name" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address:</td>
      <td><input type="text" name="address" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address1:</td>
      <td><input type="text" name="address1" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address2:</td>
      <td><input type="text" name="address2" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address3:</td>
      <td><input type="text" name="address3" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address4:</td>
      <td><input type="text" name="address4" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">County:</td>
      <td><input type="text" name="county" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Zip:</td>
      <td><input type="text" name="zip" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Telephone:</td>
      <td><input type="text" name="telephone" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Username:</td>
      <td><input type="text" name="username" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Password:</td>
      <td><input type="password" name="password" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td><input type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html> 

<?php
include('config.php');

// table name
$tbl_name=temp_users;

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

// values sent from form
$name=$_POST['name'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$county=$_POST['county'];
$zip=$_POST['zip'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$confirm_code', '$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')";
$result=mysql_query($sql)or die(mysql_error());

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: postmaster@localhost <postmaster@localhost>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://localhost/confirm.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);

}

// if not found
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}

?>

Link to comment
Share on other sites

If i understand you correctly are you trying to make it so that only one page is used?

If so this is how i would do it:

 


switch($_GET['do'])
{
  default:
    echo '
    <form action="?do=register" method="post">
    Username: <input type="text" name="username" /><br />
    Password: <input type="password" name="password" /><br />
    <input type="submit" value="Register" />
    </form>
    ';
  break;

  case 'register':
    $username = mysql_escape_string(htmlspecialchars($_POST['username']));
    $password = mysql_escape_string(htmlspecialchars(MD5($_POST['password'])));

    $sql = mysql_query(sprintf("INSERT INTO `users` ( `username`, `password` ) VALUES ( '%s', '%s' )", $username, $password)) or die('Error: ' . mysql_error());

    if($sql)
    {
      echo 'Registered successfully';
    }
    else
    {
      echo 'Failed';
    }
  break;
}

Link to comment
Share on other sites

So the top HTML is one page, and the signup_ac.php is another page, but is the PHP part of the code you posted?

 

And all works fine as two seperate files?

 

Yes the HTML is from one page where the info was passed to the 2nd page signup_ac.php. All was working fine as two seperate pages. I was just wondering if I could combine them onto one page?

Link to comment
Share on other sites

If all worked well, then all you should have to do is change the Form Action to itself, and put some PHP code at the top to see if the page has been submitted.

 

<?php
if(!isset($_POST['submit'])) {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Sign UP</title>
</head>

<body>
<td><form name="form1" method="post" action=<?php $_SERVER['PHP_SELF']; ?>>
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">Name:</td>
      <td><input type="text" name="name" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address:</td>
      <td><input type="text" name="address" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address1:</td>
      <td><input type="text" name="address1" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address2:</td>
      <td><input type="text" name="address2" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address3:</td>
      <td><input type="text" name="address3" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Address4:</td>
      <td><input type="text" name="address4" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">County:</td>
      <td><input type="text" name="county" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Zip:</td>
      <td><input type="text" name="zip" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Telephone:</td>
      <td><input type="text" name="telephone" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Email:</td>
      <td><input type="text" name="email" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Username:</td>
      <td><input type="text" name="username" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Password:</td>
      <td><input type="password" name="password" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right"> </td>
      <td><input type="submit" value="Insert record"></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html> 

<?php
}
else {
include('config.php');

// table name
$tbl_name=temp_users;

// Random confirmation code
$confirm_code=md5(uniqid(rand()));

// values sent from form
$name=$_POST['name'];
$address=$_POST['address'];
$address1=$_POST['address1'];
$address2=$_POST['address2'];
$address3=$_POST['address3'];
$address4=$_POST['address4'];
$county=$_POST['county'];
$zip=$_POST['zip'];
$telephone=$_POST['telephone'];
$email=$_POST['email'];
$username=$_POST['username'];
$password=$_POST['password'];


// Insert data into database
$sql="INSERT INTO $tbl_name(confirm_code, name, address, address1, address2, address3, address4, county, zip, telephone, email, username, password)VALUES('$confirm_code', '$name', '$address', '$address1', '$address2','$address3', '$address4','$county' ,'$zip', '$telephone', '$email', '$username', '$password')";
$result=mysql_query($sql)or die(mysql_error());

// if suceesfully inserted data into database, send confirmation link to email
if($result){

// ---------------- SEND MAIL FORM ----------------

// send e-mail to ...
$to=$email;

// Your subject
$subject="Your confirmation link here";

// From
$header="from: postmaster@localhost <postmaster@localhost>";

// Your message
$message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://localhost/confirm.php?passkey=$confirm_code";

// send email
$sentmail = mail($to,$subject,$message,$header);

}

// if not found
else {
echo "Not found your email in our database";
}

// if your email succesfully sent
if($sentmail){
echo "Your Confirmation link Has Been Sent To Your Email Address.";
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
}
?>

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.