Page 1 of 1

wont insert data into sql database

Posted: Mon Sep 04, 2006 9:57 pm
by psychotomus
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


om im working on a clients site and this script works perfectly fine on my webserver, but on his webserver. it will not add none of the data to the database. I receive no errors. any suggestions?

Code: Select all

<?php
	if (	strlen($_POST['site_name']) > 0
		&& 	strlen($_POST['site_url']) > 0
		&& 	strlen($_POST['email']) > 0 )
	{
		$site_name = strip_tags($_POST['site_name']);
		$site_name = htmlspecialchars($site_name);
		$site_url = strip_tags($_POST['site_url']);
		$site_url = htmlspecialchars($site_url);
		$email = strip_tags($_POST['email']);
		$email = htmlspecialchars($email);
		
		require_once 'sql_config.php';

		mysql_query ("INSERT INTO Sites(site_name, site_url, email ) VALUES ('$site_name', '$site_url','$email')") or die(mysql_error());

		$result = mysql_query( "SELECT * FROM Sites WHERE site_url='$site_url'" );//
		$row=mysql_fetch_array($result);	//Store Record Of Data in $row 

		$message = "You must link our site with the following http://www.styleikon.com/?id=" . $row['id'];

		echo $message;

		$from1="From: info@styleikon.com\r\nX-Priority: 1 (Highest)";
		mail ($email,$from1, $message) or print "Could not send mail";
	}
?>

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Sep 04, 2006 10:25 pm
by psychotomus
sorry about that. =)


anyway, thats not the problem. the problem relies in here

last_click = time()

Code: Select all

$date1 = strtotime(time()); 
	$date2 = strtotime($row['last_click']); 
	
	$diff = $date1 - $date2; 
	$days = $diff/60/24;

	if ($days >= 20)
	{
is this how i tell if 20 days have passed?

Posted: Mon Sep 04, 2006 10:27 pm
by feyd

Code: Select all

$days = floor($diff/86400);

Posted: Mon Sep 04, 2006 10:38 pm
by psychotomus
still having troubles. it keeps deleting the entry. any ideas?

Code: Select all

$date1 = strtotime(time()); 
	$date2 = strtotime($row['last_click']); 
	
	$diff = $date1 - $date2; 
	$days = floor($diff/86400);

	if ($days >= 20)
	{
		$id = $row['id'];
		mysql_query("DELETE FROM Sites WHERE id = '$id'") or die("DELETE Error: ".mysql_error());
	}

Posted: Mon Sep 04, 2006 10:41 pm
by feyd
Why are you using strtotime() on time()? It's already a unix timestamp.

You may need to examine $row['last_click'] and $date2. Strtotime() may not be able to fully convert it.

var_dump() could be of help in this, if only temporarily.

Posted: Mon Sep 04, 2006 10:45 pm
by psychotomus
so basicly I only need

$diff = time() - $row['last_click'] ?

Posted: Mon Sep 04, 2006 10:54 pm
by feyd
If $row['last_click'] is a unix timestamp in the past, yes.