Code not working

I cannot insert my data from website to database. anyone help!!!

You should add your actual code (not a picture) to your post; it makes it much easier for people to help you. You can use four spaces before each line, or start and end your code with three backticks “```”, to format it nicely.

The most obvious problem is that your SQL statement is incorrect. An insert statement would look like this:

INSERT INTO uyeler (kullaniciadi, sifre, sifre2, email) VALUES (?, ?, ?, ?);

The SET field = "value" format you’ve tried here is used for UPDATE statements.

Thanks for your help.
I update the code, but still not work.


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <form action="index.php" method="POST">
        Kullanıcı Adı <br>
        <input type="text" name="kullaniciadi"><br>
        Şifre <br>
        <input type="password" name="sifre"> <br>
        Şifre(Tekrar)<br>
        <input type="password" name="sifre2"> <br>
        Email<br>
        <input type="email" name="email"> <br>
        <input type="submit" value="GÖNDER" name="gonder">
    </form>
</body>
</html>

<?php
include "baglan.php";

if(isset($_POST["gonder"])){
    $kullaniciadi= $_POST["kullaniciadi"];
    $sifre  = $_POST["sifre"];
    $sifre2 = $_POST["sifre2"];
    $email = $_POST["email"];
if( $kullaniciadi =="" ){
    echo "Ad soyad alanı boş bırakılamaz";
} else if( $sifre == "" OR $sifre2 ==""){
    echo "Şifre alanı boş bırakılamaz!";
}else if ( $sifre != $sifre2){
    echo "Şifreler birbirine eşit değil!";
}else {
    $kayit = $pdo ->prepare ("INSERT INTO uyeler (kullaniciadi, sifre, sifre2, email) VALUES (?,?,?,?)");
    $kayit = bind_param($kullaniciadi,$sifre,$sifre2,$email);
    $kayit = execute ();
}

}
   



?>

Edit: HTML tags is hidden.

Is actually valid for a MySql/Maria insert query. However, there are one or two problems with the OP’s usage. One of which went away (an extra comma) with the change to the traditional format.

Why are you inserting the sifre2 (password 2) confirmation value into the table? Does your table even have a column named sifre2? This would be producing an sql error about an unknown column. Do you have any error handling for all the database statements that can fail - connection, query, prepare, and execute? The simplest way of adding error handling, without typing out logic at each statement, is to use exceptions for errors and in most cases let php catch and handle the exception. The PDO connection always uses an exception for errors. You need to set the pdo error mode to exceptions when you make the connection so that all the rest of the statements will use exceptions too. You should also be setting emulated prepared queries to false and set the default fetch mode to assoc when you make the connection.

That’s not the correct syntax for the PDO extension, and would be producing php errors. The original syntax you had, of supplying an array of values to the ->execute([…]) call was correct, though the quotes around the php variables are unnecessary typing. Why did you change this part of the code?

Do you have php’s error_reporting set to E_ALL and display_errors set to ON, in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects?

1 Like

Thanks for your help. After couple try inserted data with the code. There were no problem with the database statements, probably the errors’ produced PDO extension issues. After update it’s done with the code below:

Document Kullanıcı Adı

Şifre

Şifre(Tekrar)

Email

<?php error_reporting(E_ERROR | E_WARNING | E_PARSE); include "baglan.php"; if(isset($_POST["gonder"])){ $kullaniciadi= $_POST["kullaniciadi"]; $sifre = $_POST["sifre"]; $sifre2 = $_POST["sifre2"]; $email = $_POST["email"]; if( $kullaniciadi =="" ){ echo "Ad soyad alanı boş bırakılamaz"; } else if( $sifre == "" OR $sifre2 ==""){ echo "Şifre alanı boş bırakılamaz!"; }else if ( $sifre != $sifre2){ echo "Şifreler birbirine eşit değil!"; }else { $sorgu = $pdo ->prepare ("INSERT INTO uyeler (kullaniciadi, sifre, sifre2, email) VALUES (?,?,?,?)"); $kayit = $sorgu->execute([$kullaniciadi, $sifre, $sifre2, $email]); if($kayit){ echo "Kayıt başarılı"; } } } ?>

Php’s error_reporting will be useful property for the projects, but, I need to learn how to use exactly.

Sponsor our Newsletter | Privacy Policy | Terms of Service