Jump to content


Photo

Script doesnt work * solved


  • Please log in to reply
4 replies to this topic

#1 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 10 September 2006 - 06:04 AM

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:

<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>


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 September 2006 - 06:13 AM

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:
<?php
$date = date(dmY);
 
    if ($date = 01122006) {
	$expire = date(dmY) -100000 + 1;
	}
	else {
	$expire = date(dmY) +10000; 
	}
?>
to
<?php
$date = time();
 
    if ($date == strtotime("2006-12-01")) {
	$expire = $date -100000 + 1;
	}
	else {
	$expire = $date +10000; 
	}
?>

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

Ken

#3 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 10 September 2006 - 06:28 AM

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:

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

Except for the whole of december.

- Cheers, Daniel

#4 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 10 September 2006 - 06:38 AM

You can do that with the strtotime() function http://www.php.net/strtotime

<?php
$date = strtotime('2006-12-01');
$next_month = date('Y-m-d',strtotime('next month',$date));
echo $next_month;
?>

Ken

#5 Drezard

Drezard
  • Members
  • PipPipPip
  • Advanced Member
  • 244 posts

Posted 10 September 2006 - 08:05 AM

Thanks so much for all the help.

Daniel




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users