我正在尝试更新我的学生记录,但它没有更新,也没有错误。 [英] I'm trying to update my student records but it's not updating and there's no error.

查看:87
本文介绍了我正在尝试更新我的学生记录,但它没有更新,也没有错误。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

它始终显示我的查询无效。 数据库错误:无法更新记录。我已经尝试打印我的查询并显示此



UPDATE学生设置first_name ='Alex',last_name ='Rawr' ,year ='4',course ='IT',subject ='sdd',WHERE id ='1'id已给出。有关此的任何提示。



its always show that my query is not working. "Database Error: Unable to update record. i already try to print my query and show this

"UPDATE students set first_name = 'Alex', last_name = 'Rawr', year = '4', course = 'IT', subjects = 'sdd', WHERE id ='1' " the id is given. any tips about this.

$action = isset( $_POST['action'] ) ? $_POST['action'] : "";

if($action == "update"){

    $query = "UPDATE students

    set 

     first_name = '".$mysqli->real_escape_string($_POST['first_name'])."',

     last_name = '".$mysqli->real_escape_string($_POST['last_name'])."',

     year = '".$mysqli->real_escape_string($_POST['year'])."',

     course = '".$mysqli->real_escape_string($_POST['course'])."',

     subjects = '".$mysqli->real_escape_string($_POST['subjects'])."',

     WHERE id ='".$mysqli->real_escape_string($_REQUEST['id'])."' ";

        if($mysqli->query($query) ) {

        //if updating the record was successful

        echo "User was updated.";

        }else{

        //if unable to update new record

        echo "Database Error: Unable to update record.";

        }

}


$row = $result->fetch_assoc();

//assign the result to certain variable so our html form will be filled up with values
    $id         = $row['id'];
    $first_name = $row['first_name'];
    $last_name  = $row['last_name'];
    $year       = $row['year'];
    $course     = $row['course'];
    $subjects   = $row['subjects'];







<!--we have our html form here where new user information will be entered-->

<form action='#' method='post' border='0'>

<table>

<tr>

<td>Firstname</td>

<td><input type='text' name='first_name' value='<?php echo $first_name;  ?>' /></td>

</tr>

<tr>

<td>Lastname</td>

<td><input type='text' name='last_name' value='<?php echo $last_name;  ?>' /></td>

</tr>

<tr>

<td>Year</td>

<td><input type='text' name='year'  value='<?php echo $year;  ?>' /></td>

</tr>

<tr>

<td>Course</td>

<td><input type='text' name='course'  value='<?php echo $course;  ?>' /></td>

<tr>

<tr>

<td>Subjects</td>

<td><input type='text' name='subjects'  value='<?php echo $subjects;  ?>' /></td>

<tr>

<td></td>

<td>

<!-- so that we could identify what record is to be updated -->

<input type='hidden' name='id' value='<?php echo $id ?>' />

<!-- we will set the action to update -->

<input type='hidden' name='action' value='update' />

<input type='submit' value='Edit' />

<a href='displayRecords.php'>Back to display page</a>

</td>

</tr>

推荐答案

action = isset(
action = isset(


_POST [' action'])?
_POST['action'] ) ?


_POST [' action']: ;

if(
_POST['action'] : ""; if(


这篇关于我正在尝试更新我的学生记录,但它没有更新,也没有错误。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆