2016-07-26 5 views
-2

学生レコードを保存して編集して削除するアプリケーションを作っていますが、変数は定義されていますが、サーバーは未定義の変数エラー($ name、$ school_name、$ roll_no、$ result variable lines)を発行していますチェックするためにエコーと、すべての変数が正常に動作するように見える...親切に私にあなたが送信する前にあるフォームを、レンダリングするための変数を設定しようとしているため、実際に、理にかなってサーバが未定義の変数エラーを発行していますか?

<form action = 'edit.php?edit_form=<?php echo $edit_id; ?>' method = 'post'> 
     <table align = "center" width = "500" border = "5"> 
      <tr> 
       <td colspan = "5"> <h1 align = "center">Update Record</h1> </td> 
      </tr> 
      <tr> 
       <td align = "right">Student Name:</td> 
       <td> <input type = "text" name = "name" value = "<?php echo $name; ?>"> </td> 
      </tr> 
      <tr> 
       <td align = "right">School Name:</td> 
       <td> <input type = "text" name = "school" value = "<?php echo $school_name; ?>"> </td> 
      </tr> 
      <tr> 
       <td align = "right">Roll No:</td> 
       <td> <input type = "text" name = "roll_no" value = "<?php echo $roll_no; ?>"> </td> 
      </tr> 
      <tr> 
       <td align = "right">Result:</td> 
       <td> <input type = "text" name = "result" value = "<?php echo $result; ?>"> </td> 
      </tr> 
      <tr> 
       <td colspan = "5" align = "center"> <input type = "submit" name = "update" value = "Update Now"> </td> 
      </tr> 
     </table> 

    </form> 
+1

*変数が定義されて何*:

FOWを作る事が、あなたはデータベースからこのデータを選択する必要があり、のようなものを動作しますか?あなたが得ている正確なメッセージは何ですか? – tadman

+0

どこに定義されていますか? – Vuldo

+0

コードの一部に変数を埋め込むことはできますか? – pilec

答えて

0

を助けるので、投稿がありませんデータは要求に含まれます。

// mysql_connect is deprecated, use mysqli_connect instead 
$link = mysqli_connect("localhost", "root", "password"); 
mysqli_select_db($link, "school"); 

if (!isset($_GET['edit_form']) || !is_numeric($_GET['edit_form'])) { 
    // first validate user input from GET request 
    die('please provide us valid student id'); 
} 

// after successful updating showing confirmation message 
if (isset($_GET['show_message'])) { 
    echo "Data has been updated"; 
} 

$edit_id = $_GET['edit_form']; 

//using prepare statement for avoiding SQL injection 
$statement = $link->prepare('SELECT student_name, school_name, roll_no, result FROM students WHERE id = ?'); 


// i because student id should be integer 
$statement->bind_param('i', $edit_id); 

$statement->execute(); 
$statement->store_result(); 

// fill every needy variable from query 
$statement->bind_result($name, $school_name, $roll_no, $result); 
$statement->fetch(); 

if (isset($_POST['update'])) { 
    $name = $_POST['name']; 
    $school_name = $_POST['school']; 
    $roll_no = $_POST['roll_no']; 
    $result = $_POST['result']; 
    $query = "update students set student_name = ?, school_name = ?, roll_no = ?, result = ? where ID=?"; 

    // once again preparate query for avoiding SQL injection 
    $statement = $link->prepare($query); 

    // s for string variable, ssisi - 1st variable is string, 2nd variable is string, 3rd variable is integer ... 
    $statement->bind_param('ssisi', $name, $school_name, $roll_no, $result, $edit_id); 

    if ($statement->execute()) { 
     header("location: index.php?edit_form=$edit_id&show_message=1"); 
    } 
} ?> 
関連する問題