PHP 502 Bad Gateway Hatası

Başlatan harunbas141, 09 Ocak 2017 - 16:47:07

« önceki - sonraki »

0 Üyeler ve 1 Ziyaretçi konuyu incelemekte.

harunbas141

Kendime bir blog oluşturmaya çalışıyorum.İletişim sayfasını yaparken biraz tıkandım. Yol gösterecek kişiler varsa lütfen yardım edin. Kod çözümü istemiyorum. Bir yerlerde mantık hatası yapıyorum.


<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta name="author" content="Harun Baş">
        <meta name="keywords" content="Kişisel Blog sitesi">
        <meta name="viewport" content="width=device-width, initial-scale=1">
       
        <link rel="stylesheet" href="css/style.css">
        <link rel="stylesheet" href="http://www.w3schools.com/lib/w3.css">
        <link rel="stylesheet" href="http://www.w3schools.com/lib/w3-theme-teal.css">
        <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
    </head>
   
    <body>
        <div class="w3-container">
            <div class="w3-panel w3-leftbar w3-rightbar w3-xxlarge w3-serif w3-center">
            <p><i>"Make it as simple as possible,but not simpler."</i></p>
            </div>
        </div>
        <div class="w3-container">
            <ul class="w3-navbar w3-black w3-navitem w3-border w3-round-xxlarge">
                <li><a class="w3-hover-none w3-text-white" href="indexx.html">Anasayfa</a></li>
                <li><a class="w3-hover-none w3-text-grey w3-hover-text-white" href="benkimim.html">Ben Kimim</a></li>
                <li><a class="w3-hover-none w3-text-grey w3-hover-text-white" href="yazilarim.html">Yazılarım</a></li>
                <li><a class="w3-hover-none w3-text-grey w3-hover-text-white" href="iletisim.html">İletişim</a></li>
                <li class="w3-right"><input type="text" name="search" placeholder="Search...">
            </ul>
        </div>
       
        <form method="post"
              action="iletisim.php"
              class="w3-container w3-card-4 w3-light-grey w3-text-black w3-margin">
           
            <h2 class="w3-center">İletişime Geç</h2>

            <div class="w3-row w3-section">
            <div class="w3-col" style="width:50px"><i class="w3-xxlarge fa fa-user"></i></div>
            <div class="w3-rest">
                <input class="w3-input w3-border" name="Name" type="text" placeholder="Adınız" value="">
                </div>
            </div>

            <div class="w3-row w3-section">
                <div class="w3-col" style="width:50px"><i class="w3-xxlarge fa fa-user"></i></div>
                <div class="w3-rest">
                <input class="w3-input w3-border" name="soyad" type="text" placeholder="Soyadınız"></div>
            </div>

                <div class="w3-row w3-section">
                <div class="w3-col" style="width:50px"><i class="w3-xxlarge fa fa-envelope-o"></i></div>
                <div class="w3-rest">
                <input class="w3-input w3-border" name="email" type="text" placeholder="Email"></div>
                </div>


            <div class="w3-row w3-section">
                <div class="w3-col" style="width:50px"><i class="w3-xxlarge fa fa-pencil"></i></div>
                <div class="w3-rest">
                <input class="w3-input w3-border" name="message" type="text" placeholder="Mesajınız">
                </div>
                </div>

            <button class="w3-btn-block w3-section w3-green w3-ripple w3-padding">Gönder</button>
        </form>
    </body>   
</html>


yukarıdaki kod iletisim.html sayfası.


<!DOCTYPE html>
<html>
    <head>

    </head>
    <body>
        <?php
            
//Define variables and set to empty values
            
$nameErr $surnameErr $emailErr =$websiteErr $messasgeErr "";
            
$name $surname $email $website =  $message "";

            if(
$_SERVER["REQUEST_METHOD"]=="POST")
            {
                if (empty(
$_POST['name']))
                {
                    
$nameErr "Name is reqired";
                }
                    else
                    {
                        
$name test_input($_POST['name']);
                        
// Check if name only contains letters and whitespaces
                        
if (!preg_match("/^[a-zA-Z ]*$"$name))
                        {
                            
$nameErr "Only letters and white space allowed";
                        }
                    }
                if (empty(
$_POST['surname']))
                {
                    
$surnameErr "Name is reqired";
                }
                else
                {
                    
$surname test_input($_POST['surname']);
                    
// Check if name only contains letters and whitespaces
                    
if (!preg_match("/^[a-zA-Z ]*$"$surname))
                    {
                        
$surnameErr "Only letters and white space allowed";
                    }
                }
                if (empty(
$_POST['email']))
                {
                    
$emailErr "Email is reqired";
                }
                    else
                    {
                        
$email test_input($_POST['email']);
                        
// check if e-mail address is well-formed
                        
if (!filter_var($emailFILTER_VALIDATE_EMAIL))
                        {
                        
$emailErr "Invalid email format";
                        }
                    }
                if(empty(
$_POST["website"]))
                {
                    
$website "";
                }
                    else
                        {
                            
$website test_input($_POST['website']);
                            
// check if URL address syntaxx is valid(this regular expression also allows dashes in the URl)
                            
if(!preg_match("/(?:(?:https?|ftp):|www)[-a-z0-9+@#%?=~_|!:,.;]*[-a-<0-9+@#%=~_|]/i",$website))
                            {
                                
$websiteErr 'Invalid URL';
                            }
                        }
                if(empty(
$_POST['message']))
                {
                    
$message "";
                }
                    else
                        {
                            
$message test_input($_POST['message']);
                        }
            }
            function 
test_input($data)
            {
                
$data trim($data);
                
$data stripslashes($data);
                
$data htmlspecialchars($data);

                return 
$data;
            }
        
?>

    <?php
        
echo $name;
        echo 
"<br>";
        echo 
$surname;
        echo 
"<br>";
        echo 
$message;
        
?>

    </body>
</html>



Yukarıdaki kod iletisim.php sayfası


Şimdi ben bunları nasıl bağlıycam? Submit dediğimde 502 gateaway hatası alıyorum. Birde yazdığım php sayfasını iletisim.html deki forma nasıl aktarıcam?

matrax_41

iletisim.html sayfasındaki formu iletisim.php'ye yönlendirmen gerekiyor.<form method="post" action="iletisim.php"  şeklinde. Ama bu işlemi bir de ajax kullanarak yapmalısın. Jquery'nin ajax methodunu kullanabilirsin. Son olarak da işlemleri yaptığın php sayfasında html etiketleri kullanma.

harunbas141

Nasıl bağlayacağımı buldum. Biraz daha ilerlettim ama anlamadğım bir hata alıyorum.Stockoverflowa baktım ama bulamadım.




$stmt->bindParam(':password', password_hash($_POST['password'],PASSWORD_BCRYPT));



Hata ise:



Strict standards: Only variables should be passed by reference



Yardımcı olursanız sevinirim.


Database'e veri gönderemiyorum.


Kod şöyle:



// register.php

<?php

require 'database.php';

$message '';

if(!empty(
$_POST['email']) && !empty($_POST['password'])):

    
//Enter the new user in the database
    
$sql "INSERT INTO users2 (email,password) VALUES (:email, :password)";
    
$stmt $conn->prepare($sql);

    
$stmt->bindParam(':email'$_POST['email']);
    
$stmt->bindParam(':password'password_hash($_POST['password'],PASSWORD_BCRYPT));

    if( 
$stmt->execute() ):
        
$message='Successfully created new user';
    else:
        
$message='Sorry there must have been an issue creating new user';
    endif;


endif;

?>

<!DOCTYPE html>

<html>

<head>
    <title>Login Below</title>
    <link rel="stylesheet" type="text/css" href="assets/css/style.css">
    <link href="https://fonts.googleapis.com/css?family=Comfortaa" rel="stylesheet">

</head>

<body>
    <div class="header">

        <a href="index.php">Your App Name</a>

    </div>

    <?php if(!empty($message)); ?>
        <p><?php $message ?></p>

    <h1>Register</h1>

    <span>or <a href="login.php">login here</a></span>

    <form action="register.php" method="POST">

        <input type="text" placeholder="Enter Your Email" name="email">

        <input type="password" placeholder="and password" name="password">

        <input type="password" placeholder="confirm password" name="confirm_password">

        <input type="submit">

    </form>
</body>
</html>



aşağıdakide database.php



<?php

$server 
'localhost';
$username'root';
$password '';
$database 'auth2';


try
{
    
$conn= new PDO("mysql:host=$server; dbname=$database",$username$password);
}
catch(
PDOException $e)
{
    die(
'Connection failed: ' $e->getMessage());
}

?>



matrax_41

Şifreye bind işleminden daha önce hashleme yap. Daha sonra orada oluşturduğun değişkene bind işlemi uygula.