1

I need to update students information. when i click edit button from students view page it display/retrieve user info correctly.but after that editing when i click update/save it show pharse error. here is my database.

Database info`s

This is edit.php

<?php
session_start();
if(isset($_SESSION['admin'])){
    echo "";
}
else
{
    header("location:logout.php");
}
require('dbcon.php');

$hjd=$_GET['s_id'];
  /* getting link id from index page*/
$que     = "SELECT  * FROM stu_info WHERE s_id='".$_GET['s_id']."'";         /*selecting id from database*/
$resu    = mysqli_query($conl, $que) or die ( mysqli_error());
$rlk = mysqli_fetch_assoc($resu);
?>

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>
            Edit Profile
        </title>

        <link rel="stylesheet" href="css/bootstrap.css" />
        <script src="js/jquery.min.js">
        </script>
        <!-- Include all compiled plugins (below), or include individual files as needed -->
        <script src="js/bootstrap.min.js">
        </script>
        <script src="date_picker/datetimepicker_css.js">
        </script>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>

        <form class="form-horizontal" method="GET"  action="edit_action.php">
        <input type="hidden" name="new" value="1" />
        <input type="text" name="chk" value="<?php echo $rlk['s_id']; ?>" hidden="" />
            <fieldset>

                <!-- Form Name -->
                <legend>
                    Add Student
                </legend>

                <!-- Text input-->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="f_name">
                        First Name
                    </label>
                    <div class="col-md-4">
                        <input id="f_name" name="f_name" type="text" value="<?php echo $rlk['f_name'];?> " class="form-control input-md" required="">
                        <span class="help-block">
                            Student Name
                        </span>
                    </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="l_name">
                        Last Name
                    </label>
                    <div class="col-md-4">
                        <input id="l_name" name="l_name" type="text" value="<?php echo $rlk['l_name'];?>" class="form-control input-md" required="">
                        <span class="help-block">
                            Maybe Father Name
                        </span>
                    </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="roll_no">
                        Roll No
                    </label>
                    <div class="col-md-4">
                        <input id="roll_no" name="roll_no" type="number" value="<?php echo $rlk['Roll_no'];?>" value="3215" class="form-control input-md" required="">
                        <span class="help-block">
                            Student Roll Number
                        </span>
                    </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="dob">
                        Date Of Birth
                    </label>
                    <div class="col-md-4">
                        <input id="demo1" name="dob" type="text" value="<?php echo $rlk['dob'];?>" class="form-control input-md" required="" onclick="javascript:NewCssCal ('demo1','yyyyMMdd','','','','','')"  style="cursor:pointer"/>
                        <span class="help-block">
                            Date Of Birth
                        </span>
                    </div>
                </div>

                <!-- Select Basic -->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="cls">
                        Select Class
                    </label>
                    <div class="col-md-4">
                        <select id="cls" name="cls" class="form-control">
                            <option value="1">
                                class 1
                            </option>
                            <option value="2">
                                class 2
                            </option>
                            <option value="3">
                                class 3
                            </option>
                            <option value="4">
                                class 4
                            </option>
                            <option value="5">
                                class 5
                            </option>
                        </select>
                    </div>
                </div>

                <!-- Select Basic -->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="Gender">
                        Select Gender
                    </label>
                    <div class="col-md-4">
                        <select id="gender" name="gender" class="form-control">
                            <option value="male">
                                male
                            </option>
                            <option value="femala">
                                female
                            </option>
                        </select>
                    </div>
                </div>

                <!-- Select Basic -->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="reli">
                        Religion
                    </label>
                    <div class="col-md-4">
                        <select id="reli" name="reli" class="form-control">
                            <option value="Hindhu">
                                Hindhu
                            </option>
                            <option value="Christian">
                                Christian
                            </option>
                            <option value="Muslim">
                                Muslim
                            </option>
                        </select>
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-md-4 control-label" for="reli">
                        Community
                    </label>
                    <div class="col-md-4">
                        <select id="commu" name="commu" class="form-control">
                            <option value="OC">
                                OC
                            </option>
                            <option value="BC" >
                                BC
                            </option>
                            <option value="MBC">
                                MBC
                            </option>
                            <option value="SC">
                                SC
                            </option>
                            <option value="ST">
                                ST
                            </option>

                        </select>
                    </div>
                </div>

                <div class="form-group">
                    <label class="col-md-4 control-label" for="reli">
                        Blood Group
                    </label>
                    <div class="col-md-4">
                        <select id="blg" name="blg" class="form-control">
                            <option value="A Possitive">
                                A  Possitive
                            </option>
                            <option value="A Negative" >
                                A Negative
                            </option>
                            <option value="A1  Possitive">
                                A1  Possitive
                            </option>
                            <option value="A1 Negative">
                                A1-
                            </option>
                            <option value="A1B  Possitive">
                                A1B  Possitive
                            </option>
                            <option value="A1B Negative">
                                A1B Negative
                            </option>
                            <option value="A2  Possitive">
                                A2  Possitive
                            </option>
                            <option value="A2 Negative">
                                A2 Negative
                            </option>
                            <option value="A1B  Possitive">
                                A1B  Possitive
                            </option>
                            <option value="A2B\+">
                                A2B+
                            </option>
                            <option value="A2B Negative">
                                A2B Negative
                            </option>
                            <option value="AB  Possitive">
                                AB  Possitive
                            </option>
                            <option value="AB Negative">
                                AB Negative
                            </option>
                            <option value="B  Possitive">
                                B  Possitive
                            </option>
                            <option value="B Negative">
                                B Negative
                            </option>
                            <option value="O  Possitive">
                                O  Possitive
                            </option>
                            <option value="O Negative">
                                O Negative
                            </option>
                        </select>
                    </div>
                </div>
                <!-- Textarea -->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="address">
                        Address
                    </label>
                    <div class="col-md-4">
                        <textarea class="form-control" id="address" required="" value="<?php echo $rlk['address'];?>"  name="address">
                            default Address
                        </textarea>
                    </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="loc">
                        Location
                    </label>
                    <div class="col-md-4">
                        <input id="loc" name="loc" type="text" required="" value="<?php echo $rlk['loc'];?>" class="form-control input-md" required="">
                        <span class="help-block">
                            currently living in
                        </span>
                    </div>
                </div>

                <!-- Text input-->
                <div class="form-group">
                    <label class="col-md-4 control-label" for="mobile">
                        Mobile
                    </label>
                    <div class="col-md-4">
                        <input id="phone" name="phone" type="number" value="<?php echo $rlk['phone'];?>" class="form-control input-md" required="">
                        <span class="help-block">
                            Mobile Number
                        </span>
                    </div>
                </div>

                <button type="submit" class="btn btn-primary" name="btn-save" id="btn-save">
                    <span class="glyphicon glyphicon-plus">
                    </span> Save this Record
                </button>
            </fieldset>
        </form>
    </body>
</html>

Kindly correct error please Thanks in Advance

This Is Edit Action.php file which is save/update database :

 <?php
    $status = "";
require('dbcon.php');
    if(isset($_GET['new']) && $_GET['new']==1)
    {
        /*Detecting Input Start */
        $s_id   =$_GET['chk'];
        $f_name = $_GET['f_name'];
        $l_name = $_GET['l_name'];
        $dob    = $_GET['dob'];
        $rln    = $_GET['roll_no'];
        $cls    = $_GET['cls'];
        $gender = $_GET['gender'];
        $address= $_GET['address'];
        $reli   = $_GET['reli'];
        $commu  = $_GET['commu'];
        $loc    = $_GET['loc'];
        $phone  = $_GET['phone'];
        $blg    = $_GET['blg'];
        /*Detection Input End */

    $update=UPDATE `school`.`stu_info` SET `Roll_no` = "$rln", `f_name` = "$f_name", `l_name` = "$l_name", `dob` = "$dob", `std` = "$cls", `gender` = "$gender", `address` = "$address", `loc` = "$loc", `phone` = "$phone", `blg` = "$blg", `commu` = "$commu" WHERE `stu_info`.`s_id` = "$s_id";
        $df=mysqli_query($conl,$update);

        if(!df){
    echo "error";
        }
    else {
    echo "success";
    }   
        }
    ?>

Kindly Help me By Findout Error Thanks In Advance

///I Updated My Recent Code Still Not work Show error

  • I think you can get idea from this answer.Try this [enter link description here](http://stackoverflow.com/questions/8893551/update-query-php-mysql) – Priyantha Jan 25 '17 at 10:37
  • I think you can get answer from this. [enter link description here](http://stackoverflow.com/questions/8893551/update-query-php-mysql) – Priyantha Jan 25 '17 at 10:40

2 Answers2

0

Line 25 should be

$update = "UPDATE `school` . `stu_info` SET `Roll_no` = '$rln', `f_name` = '$f_name', `l_name` = '$l_name', `dob` = '$dob', `std` = '$cls', `gender` = '$gender', `address` = '$address', `loc` = '$loc', `phone` = '$phone', `blg` = '$blg', `commu` = '$commu' WHERE `stu_info` . `s_id` = '$s_id''";

and you are missing a } at the end.

But please do not create the queries like this.

This issue is explained here mysql extension deprecated

Community
  • 1
  • 1
cornelb
  • 6,046
  • 3
  • 19
  • 30
0

Your code is very unsafe. E. g. reading directly from $_GET array is not recommended. Please consider using PDO with execute to increase security

else {
    $update= 'UPDATE `school`.`stu_info` SET `Roll_no` = "$rln", `f_name` = "$f_name", `l_name` = "$l_name", `dob` = "$dob", `std` = "$cls", `gender` = "$gender", `address` = "$address", `loc` = "$loc", `phone` = "$phone", `blg` = "$blg", `commu` = "$commu" WHERE `stu_info`.`s_id` = "$s_id"';
    $df=mysqli_query($conl,$update);
} // missing !
Community
  • 1
  • 1
HubertS
  • 828
  • 6
  • 10