Jump to content

Script doesnt work * solved


Drezard

Recommended Posts

Hello, I am using this script for a house selling website. I want the account to expire after a month. Thats why I want $expire to be the date the account expires. When i try to create an account, the account expirery date is always 09992007 in the database. It never works. Here is the code:

[CODE]
<html>
<head>
<?php
include('header.php');
?>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
if (!isset($_POST['submit'])) { // if the form has not been submitted before
?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
    Name(s): <input type="text" name="name"> <br>
    Email: <input type="text" name="email1">
    @<input type="text" name="email2">
  Daytime Phone Number:<input type="text" name="daytime"> <br>
    Nighttime Phone Number:<input type="text" name="nighttime"> <br>
Mobile Number:<input type="text" name="mobile"> <hr>
    Street Number:<input type="text" name="streetnum">
    Street Name: <input type="text" name="streetname"> <br>
    Suburb: <input type="text" name="suburb">
    State: <input type="text" name="state">
    Postcode: <input type="text" name="postcode"> <br>
    Asking Price: <input type="text" name="askprice">
    Bedrooms: <input type="text" name="bedrooms">
    Bathrooms: <input type="text" name="bathrooms"> <hr>                                   
    <input type="submit" name="submit">
</form>

          <?php
}
else {

include('connect.php');
$date = date(dmY);

    if ($date = 01122006) {
$expire = date(dmY) -100000 + 1;
}
else {
$expire = date(dmY) +10000;
}
// Start a connection to the MySQL Database
  $name = empty($_POST['name']) ? die ("Please Enter Your Name") : mysql_escape_string($_POST['name']);
$email1 = empty($_POST['email1']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email1']);
    $email2 = empty($_POST['email2']) ? die ("Please Enter Your Email Address") : mysql_escape_string($_POST['email2']);
    $daytime = empty($_POST['daytime']) ? die ("Please Enter Your Daytime Phone Number") : mysql_escape_string($_POST['daytime']);
    $nighttime = empty($_POST['nighttime']) ? die ("Please Enter Your Nighttime Phone Number") : mysql_escape_string($_POST['nighttime']);
    $mobile = empty($_POST['mobile']) ? die ("Please Enter Your Mobile Number") : mysql_escape_string($_POST['mobile']);
$streetnum = empty($_POST['streetnum']) ? die ("Please Enter Your Streetnumber") : mysql_escape_string($_POST['streetnum']);
$streetname = empty($_POST['streetname']) ? die ("Please Enter Your Streetname") : mysql_escape_string($_POST['streetname']);
$suburb = empty($_POST['suburb']) ? die ("Please Enter Your Suburb") : mysql_escape_string($_POST['suburb']);
$state = empty($_POST['state']) ? die ("Please Enter Your State") : mysql_escape_string($_POST['state']);
$postcode = empty($_POST['postcode']) ? die ("Please Enter Your Postcode") : mysql_escape_string($_POST['postcode']);
$askprice = empty($_POST['askprice']) ? die ("Please Enter Your Asking Price") : mysql_escape_string($_POST['askprice']);
$bedrooms = empty($_POST['bedrooms']) ? die ("Please Enter How Many Bedrooms Your House Has") : mysql_escape_string($_POST['bedrooms']);      
$bathrooms = empty($_POST['bathrooms']) ? die ("Please Enter How Many Bathrooms Your House Has") : mysql_escape_string($_POST['bathrooms']);
$joindate = date(dmY);

/* The above code is to check whether the user has or has not filled in all of the form. This means the user is forced to fill out the whole
form instead of just half of it. This also puts all of the information from the form into Variables so we can use them later. This code also
emptys all of the posts, so that it frees up memory so we can do other things faster. */
if(!empty($_POST)){
    // This code checks to see if the form has been emptied.
      $query = "INSERT INTO  users (name, email1, email2, daytime, nighttime, mobile, streetnum, streetname, suburb, state, postcode, askprice, bedrooms, bathrooms, joindate, expiredate) VALUES ('$name', '$email1', '$email2', '$daytime', '$nighttime', '$mobile', '$streetnum', '$streetname', '$suburb', '$state', '$postcode', '$askprice', '$bedrooms', '$bathrooms', '$joindate', '$expire')";
/* This is the query, this is what we are asking the MySQL database to do. This specific query asks the database to add the Variables we took
out of that form into the database. So we can later use those variables in different scripts. We can also use them to store user information such
as: how much money a user has. */ 
    $result = mysql_query($query) or die ("User already exists");   
/* This code above executes the query. */
    echo "Account Created";  // This is the message the user gets if the process completed and their account was sucess fully added.
mysql_close($connection);

}
}


?>
</body>
</html>
[/CODE]
Link to comment
Share on other sites

When you want to do arithmatic on dates, you need to do it on the timestamp value (number of seconds since 1-1-1970), not the string value, which is what you're doing. Also, the comparison operator for "equal to" is "==" not "=". So change this code:
[code]<?php
$date = date(dmY);

    if ($date = 01122006) {
$expire = date(dmY) -100000 + 1;
}
else {
$expire = date(dmY) +10000;
}
?>[/code]
to
[code]<?php
$date = time();

    if ($date == strtotime("2006-12-01")) {
$expire = $date -100000 + 1;
}
else {
$expire = $date +10000;
}
?>[/code]

I'm not really sure what the figures of 100000 and 10000 are meant to represent in the above code.

Ken
Link to comment
Share on other sites

Now, how would i make it so if the date was in december it just added a year and took off 11 months so, If it was in December 2006 it would change the expirey date to January 2007 instead of the 13th month. Something like this:

[CODE]
    if ($date == strtotime("2006-12-01")) {
$expire = $date -100000 + 1;
}
[/CODE]

Except for the whole of december.

- Cheers, Daniel
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.