if (isset($_GET['login'])) {
$query = "SELECT * FROM `test` WHERE login=".$_GET['login'];
echo "query=$query\n";
$sql = mysqli_query($mysqli,$query) or die(mysqli_error());
echo "num_rows=".mysqli_num_rows($sql)."\n";
if (mysqli_num_rows($sql) > 0) {
$myrow = mysqli_fetch_array($sql);
$pass = $myrow['pass'];
var_export($myrow);
echo $pass->format("%d");
}else{
echo '-1';
}
}
<?php
session_start();
function logWrite($data = "\n")
{
file_put_contents("sendmail.log", strftime('%Y-%m-%d %H:%M:%S ') . $data . "\n", FILE_APPEND);
}
function logDump($var, $name = '')
{
if (!empty($name)) $name = "$name: ";
logWrite($name . var_export($var, true));
}
logWrite("\n===================\n");
logDump($_SERVER, 'SERVER');
logDump($_POST, 'POST');
if (stripos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME']) === false ) {
logWrite('invalid HTTP_REFERER');
exit;
}
/** защита от CSRF-атак, для вас наверное не актуально
* if (!isset($_SESSION['token']) || !isset($_SERVER['HTTP_X_CSRF_TOKEN'])) {
* logWrite('no token');
* exit;
* }
* if ($_SESSION['token'] !== $_SERVER['HTTP_X_CSRF_TOKEN']) {
* logWrite('invalid token');
* exit;
* }
*/
/** здесь была валидация полей - её тоже вырезал */
$eol = "\r\f";
$message = 'Телефон: ' . $_POST['user_phone'] . $eol;
$message .= 'email: ' . $_POST['form_checkbox_agree[]'] . $eol;
if (mail('aaaa@bbb.cc, 'order #...', $message)) {
$result = [
'success' => true,
'errors' => [],
];
} else {
$result = [
'success' => false,
'errors' => [
'internal' => 'Internal error'
]
];
}
logDump($result, 'result');
$json = json_encode($result);
if ($json === false) {
logWrite('json error');
exit;
}
echo $json;
year IN(...)
либо в цепочку AND (year=.. OR year=... OR year=...)
. Для этого в цикле проходитесь по $_POST['poisk_year'] и формируете условие (ну или делаете как выше написал Павел Андрейченко) $arr1 = [
1 => ['id' => 1, 'name' => 'DJ'],
2 => ['id' => 2, 'name' => 'Bass'],
3 => ['id' => 3, 'name' => 'Vocal'],
];
$arr2 = [
['name' => 'Alex', 'specId' => 1],
['name' => 'Tim', 'specId' => 2],
['name' => 'Dave', 'specId' => 2],
];
$result = [];
foreach ($arr1 as $arr1_item) {
foreach ($arr2 as $arr2_item) {
if ($arr1_item['id'] == $arr2_item['specId']) {
$result[$arr1_item['id']] = $arr1_item['id'];
}
}
}
var_export($result);
$arr1 = [
1 => ['id' => 1, 'name' => 'DJ'],
2 => ['id' => 2, 'name' => 'Bass'],
3 => ['id' => 3, 'name' => 'Vocal'],
];
$arr2 = [
['name' => 'Alex', 'specId' => 1],
['name' => 'Tim', 'specId' => 2],
['name' => 'Dave', 'specId' => 2],
];
$result = array_filter($arr1, function ($item1) use ($arr2) {
return in_array(
true,
array_map(function ($item2) use ($item1) {
return $item2['specId'] == $item1['id'];
}, $arr2)
);
});
var_export($result);
"+5"
делать "'+5"