Wszystko już jest na dobrej drodze, problem mam jeszcze z zapytaniem do bazy
<?php
$avatar;
if ($_POST['name'] != null){
$userName = $_POST['name'];
}
if ($_POST['city'] != null ) {
$userCity = $_POST['city'];
}
if ($_POST['desc'] != null){
$userDesc = $_POST['desc'];
}
if ($_POST['login'] != '' && $_POST['pass'] != '' && $_POST['mail'] != '') {
if (strlen($_POST['login']) > 3
&& strlen($_POST['login']) < 10
&& strlen($_POST['pass']) > 5
&& strlen($_POST['pass']) < 16
) { if (preg_match('/^[a-zA-Z0-9\.\-_]+\@[a-zA-Z0-9\.\-_]+\.[a-z]{2,4}$/D', $_POST['mail']) && preg_match('/^[a-zA-Z0-9\.\-_]/', $_POST['login']) ) {
$userLogin = $_POST['login'];
$userPass = $_POST['pass'];
$userMail = $_POST['mail'];
$len = 20;
if($_FILES['filename']['name'] != ''){
$avatar = fileReceive();
}
reg();
}
else
{
header("Location: ../reg.php?reg=badchars"); }
}
else
{
header("Location: ../reg.php?reg=shortpole"); }
}
else
{
header("Location: ../reg.php?reg=emptyf"); }
function reg(){
global $userID, $userMail, $userPass, $userLogin, $userDesc, $userCity, $userName, $avatar; try {
$host = 'localhost';
$baza = 'user';
$uzytkownik = 'adamek';
$haslo = 'aaaaa5';
$conn = new PDO("mysql:host=$host;dbname=$baza", $uzytkownik, $haslo);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare("SELECT Nazwa AND mail FROM Users WHERE Nazwa = '$userLogin' OR mail = '$userMail'");
$stmt->execute();
$row = $stmt->fetch();
if($row['Nazwa'] == 0 && $row['mail'] == 0){
$stmt = $conn->exec("INSERT INTO Users ( ID , Nazwa , Haslo , mail , name , city , image , desci , activate , admin ) VALUES ('$userID','$userLogin', '$userPass', '$userMail', '$userName', '$userCity, $avatar', '$userDesc', 0 , 0 ");
#$sendMail();
}
else{
header("Location: ../reg.php?reg=userexists"); }
}
catch(PDOException $e)
{
}
}
function fileReceive(){
$max_size = 1024*1024;
if ($_FILES['filename']['size'] > $max_size) {
echo 'Błąd! Plik jest za duży!'; }
else {
echo 'Odebrano plik. Początkowa nazwa: '.$_FILES['filename']['name']; if (isset($_FILES['filename']['type'])) { echo 'Typ: '.$_FILES['filename']['type'].'<br/>'; }
$strExt = substr( $_FILES['filename']['name'], strrpos( $_FILES['filename']['name'], '.' ) + 1
); echo "Rozszerzenie: ". $strExt; $len = 20;
$randstring = substr(sha1
(rand(1
,10000
)),0
,$len).".jpg"; echo $_FILES['filename']['name'];
if ($strExt == 'jpg' || 'JPG' || 'jpeg' || 'JPEG'){
$_SERVER['DOCUMENT_ROOT'].'/avatars/'.$_FILES['filename']['name']);
}
else{
}
} else {
echo 'Błąd przy przesyłaniu danych!'; }
rename('../avatars/'.$_FILES['filename']['name'], "../avatars/". $randstring); return $randstring;
}
function sendMail(){
$addressee = 'ajjambor912@gmail.com';
@$email = $_POST['email'];
@$content = 'Name '.$_POST['username'].' Phone: '.$_POST['userphone'].' Content: '.$_POST['message'];
$header = "From: ".$_POST['email']." \nContent-Type:".
' text/plain;charset="iso-8859-2"'.
"\nContent-Transfer-Encoding: 8bit";
if (mail($addressee, 'Message from NAhandyman: ', $content , $header))
header('Location:index.php?send=true'); else
header('Location:index.php?send=false'); }
?>
Tutaj jest błąd
$stmt = $conn->exec("INSERT INTO Users ( ID , Nazwa , Haslo , mail , name , city , image , desci , activate , admin ) VALUES ('$userID','$userLogin', '$userPass', '$userMail', '$userName', '$userCity, $avatar', '$userDesc', 0 , 0 ");
Skąd wiem? Bo jak wykomentuje to skrypt leci do kolejnej lini i mam wyświetla się ok, z echa. Jeśli skasuje komentarz to przechodzi do instrukcji catch i z echa wyświetla się duppp.