aktuell arbeite ich an einer live check avaibility. Die Error und die entsprechenden Meldungen funktionieren soweit so gut, wenn ich aber in den validation Zweig und zur dementsprechenden preg_match abfrage komme, gibt mir json einen parse error. Liegt es eventuell an dem preg match oder an meiner Abfrage? Die Abfragen werden alle über PHP gesteuert und zuletzt wird ein json object an das ajax übergeben. Ganzer PHP code:
PHP-Code:
<?php
class Registration
{
public $userReg = '!/[~`!#$%\^&*+=\-\[\]\\\';,/{}|\\":<>\?]/';
public $mailReg = "/^([a-zA-Z0-9-_]*)[.]{0,1}([a-zA-Z0-9-_]*)[@]([a-zA-Z0-9-_]*[.]{1}[a-zA-Z]{2,3})$/";
public function Connection()
{
static $connection = null;
if ($connection == null) {
$connection = new PDO('mysql:host=localhost;dbname=planer', 'root', 'root');
}
return $connection;
}
public function getQuery($col, $data)
{
/*
* $col = tabellen spalte
* $data = referenzenwert
*/
$result = $this->Connection()->prepare("SELECT * FROM users WHERE $col = ?");
$result->execute(array($data));
$statement = $result->fetchColumn();
return $this->inputCheck($statement, $data);
}
public function inputCheck($statement, $data)
{
if (!strlen($data) < 3) {
if ($statement > 0) {
return json_encode(array("dataExists" => true));
} else {
return $this->stringValidation($data);
}
} else {
return json_encode(array("inputLength" => true));
}
}
public function stringValidation($data)
{
if ($data === $_POST['username']) {
if (!preg_match($this->userReg, $data)) {
return json_encode(array("state" => true));
}
}
/*
if ($data == $_POST['username']) {
if (!preg_match($this->userReg, $data)) {
return json_encode(array("state" => true));
} else {
return json_encode(array("notValidate" => true));
}
} else if ($data == $_POST['mail']) {
if (!preg_match($this->mailReg, $data)) {
return json_encode(array("state" => true));
} else {
return json_encode(array("notValidate" => true));
}
}*/
//return false;
}
public function returnState()
{
return json_encode(array("state" => true));
}
}
$obj = new Registration();
$response = array();
if (!empty($_POST['username'])) {
header("Content-Type: application/json");
echo json_encode($obj->getQuery("username", $_POST['username']));
}
if (!empty($_POST['mail'])) {
header("Content-Type: application/json");
$obj->getQuery("mail", $_POST['mail']);
}
Komischerweise gibt es einen Formatierungs-Error wenn ich den PHP Tag benutze. Deswegen poste ich mal einen Link zum Code (https://1337.cat/53).
Einen Kommentar schreiben: