2016-03-29 12 views
-2

Soru: Bir veritabanında (MySQL) bir kullanıcıyı kaydeden bir kayıt formu oluşturmaya çalışıyorum.
kod kayıt gerekiyordu: - kullanıcı adı - Parola - soyadı - - İlk isim epostaBir veritabanında (MySQL) kullanıcı kaydı yapan bir kayıt formu yapmaya çalışıyorum (MySQL)

Ve böyle hatalar alıyorum: Burada

Notice: Undefined index: fname in C:\xampp\htdocs\Railways\reg.php on line 89 

Notice: Undefined index: lname in C:\xampp\htdocs\Railways\reg.php on line 90 

Notice: Undefined index: uname1 in C:\xampp\htdocs\Railways\reg.php on line 91 

Notice: Undefined index: pswrd1 in C:\xampp\htdocs\Railways\reg.php on line 92 

Notice: Undefined index: email in C:\xampp\htdocs\Railways\reg.php on line 93 

Fatal error: Call to a member function query() on null in C:\xampp\htdocs\Railways\reg.php on line 98 

kodudur: burada
<?php 
    global $conn; 
    include_once('connect.php'); 
     $first=$_POST['fname']; 
     $last=$_POST['lname']; 
     $usernam=$_POST['uname1']; 
     $passwrd=$_POST['pswrd1']; 
     $email=$_POST['email']; 
    $sql=" INSERT INTO users(username,password,firstname,lastname,email) VALUES ('".$usernam."','".$passwrd."','".$first."','".$last."','".$email."')"; 
    if($conn->query($sql)) 
    { 
     echo "<h1 style='text-align:center'> Registered Succesfully </h1>"; 
    } 
    else 
    { 
     echo "<h1 style='text-align:center' id='text'>Error</h1>"; 
     echo $conn->connect_error; 
    } 
?> 

Ve

HTML:

<form action="reg.php" method="POST"> 
    <label id="text"> Firstname: <br> <br> <input id="input" type="text" name="fname" placeholder="Firstname" id="t3"> </label> 
    <br> <br> <br> 
    <label id="text"> Lastname: <br> <br> <input id="input" type="text" name="lname" placeholder="Lastname" id="t4"> </label> 
    <br> <br> <br> 

    <label id="text"> Username: <br> <br> <input id="input" type="text" name="uname1" placeholder="Username" id="t1"> </label> 
    <br> <br> <br> 

    <label id="text"> Password: <br> <br> <input id="input" type="text" name="pswrd1" placeholder="Password" id="t2"> </label> 
    <br> <br> <br> 

    <label id="text"> Email: <br> <br> <input id="input" type="text" name="email" placeholder="Email" id="t1"> </label> 
    <br> <br> <br> 

    <input style="background-color:red;padding:7px;margin-left:40px;"type="submit" value="Register" name="submit" id="s1"> 

    </td></tr> 
    </table> 
    </div> 
</form> 

connect.php kodu

<?php 

      $conn_error="could not connect"; 
      $host="localhost"; 
      $user="root"; 
      $pass=""; 
      $db="railways"; 
     $sql =mysqli_connect($host,$user,$pass,$db) or die($conn_error); 
     echo'conneced'; 

?>

+0

hisse kodu; – itzmukeshy7

+0

Ayrıca bkz. Hazırlamış olduğunuz ifadeler – Strawberry

cevap

1

sonrası bu sayfayı açarsanız doğrudan $_POST değişken boş ve sizin nedenidir aksi takdirde sorgusu çalıştırmak sonra ayarlanır gönderirseniz bir çek ekle hata olsun $_POST dizininiz boş.

<?php 


include_once('connect.php'); 
global $conn; 
if(isset($_POST['submit'])) // this check 
{ 
    $first=$_POST['fname']; 
    $last=$_POST['lname']; 
    $usernam=$_POST['uname1']; 
    $passwrd=$_POST['pswrd1']; 
    $email=$_POST['email']; 


$sql=" INSERT INTO users(username,password,firstname,lastname,email) VALUES ('".$usernam."','".$passwrd."','".$first."','".$last."','".$email."')"; 

if($conn->query($sql)) 
    { 
    echo "<h1 style='text-align:center'> Registered Succesfully </h1>"; 

    } 
else 
    { 
    echo "<h1 style='text-align:center' id='text'>Error</h1>"; 
    echo $conn->connect_error; 
    } 
} 
?> 
+0

Tamam.My hataları giderildi.Ama yine de bu hatayı alıyorum: Önemli hata: C: \ xampp \ htdocs \ Railways \ reg.php satırında bir üye işlev sorgusuna() null çağrı 99 –

+0

Bu hata nedeniyle, veritabanına kayıt detayları ekleyemiyorum –

+0

Şimdi ans denemeyi deneyin ... dosyadan sonra global $ conn move @ sai-sreenath içerdiği –

0

Sen $_POST ayarlı değilse şey bu değerleri tanımlamak gerekir. Böyle

şey: connect.php` `arasında

$first=isset($_POST['fname']) ? $_POST['fname'] : "" ; 
$last=isset($_POST['lname']) ? $_POST['lname'] : ""; 
$usernam=isset($_POST['uname1']) ? $_POST['unmae1'] : ""; 
$passwrd=isset($_POST['pswrd1']) ? $_POST['pswrd1'] : ""; 
$email=isset($_POST['email']) ? $_POST['email'] : ""; 

if(isset($_POST['submit'])){ 
    $sql=" INSERT INTO users(username,password,firstname,lastname,email) VALUES ('".$usernam."','".$passwrd."','".$first."','".$last."','".$email."')"; 

if($conn->query($sql)){ 
    echo "<h1 style='text-align:center'> Registered Succesfully </h1>"; 
} 
else{ 
    echo "<h1 style='text-align:center' id='text'>Error</h1>"; 
    echo $conn->connect_error;} 
} 
+1

:) hataların giderilmesine yardımcı olur ama açık reg diye düşünüyorum kayıt için .php o alway db içinde boş satır ekleyin :) –

+0

Oh .. Onu özledim! – user3284463

İlgili konular