Skip to content

Instantly share code, notes, and snippets.

@tieorange
Created May 16, 2013 11:50
Show Gist options
  • Save tieorange/5591200 to your computer and use it in GitHub Desktop.
Save tieorange/5591200 to your computer and use it in GitHub Desktop.
diflog
<?php
/*
1.correct add to MySqlBase
2.Security, anti-injection
*/
//DB
mysql_connect('localhost', 'diflog', '2ghqercds8') or die("couldn't connect to db1: " . mysql_error());
mysql_select_db("db") or die("couldn't select db2: " . mysql_error());
$fieldsString = "sport cinema concerts tourism clothes eat alcohol clubs";
$fields = explode(" ", $fieldsString);
echo($fields."\n");
echo($fields[2]."\n");
$sign_query = "INSERT INTO tbl_users
SET timestamp = NOW(),
vk = '{$_REQUEST['vk']}',
phone = '{$_REQUEST['tel']}',
";
end($fields); // move the internal pointer to the end of the array
$lastElementKey = key($array); // fetches the key of the element pointed to by the internal pointer
foreach($fields as &$f)
{
if($f != $lastElementKey)//for don't putting ',' to the last insert
$sign_query .= "$f = ".($_REQUEST[$f] ? 1 : 0).",\n";
else $sign_query .= "$f = ".($_REQUEST[$f] ? 1 : 0);
}
echo $sign_query."\n";
mysql_query($sign_query) or die("couldn't connect to db3: " . mysql_error());
mysql_close();
print_r($_REQUEST);
die();
if ($_REQUEST['tel'] == null)
{
echo "no_phone";
}
else
if ($_REQUEST['vk'] == null)
{
echo "no_vk";
}
else
{
sleep(1);
$interests = "";
$a_interests = $_REQUEST['interests'];
if ($a_interests) foreach ($a_interests as $e)
$interests .= "$e, ";
$f = fopen("nums.txt", "a+");
fputs($f, date("Y F j, H:m:s"). "\t" . $_REQUEST['tel'] . " " . $_REQUEST['vk'] . " " . $interests . "\n");
fclose($f);
$linecount = 0;
$handle = fopen("nums.txt", "r");
while(!feof($handle)){
$line = fgets($handle);
$linecount++;
}
fclose($handle);
echo $linecount;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment