0

I am doing project on marks management system. In the project i have a task of updating the marks of student.Suppose if the updation is successful i should display a message that it is successful otherwise
unsuccessful should be displayed. I am doing my project using php and html. The code is as follows. update marks

user_id: <input type="text" name="userid"><br>

Branch<select name="Branch">
<option value="cse">CSE</option>
<option value="eee">EEE</option>
<option value="ece">ECE</option>
</select>

Marks<br><input type="text" name="marks" size="40"></br>

<select name="Subject">
<optgroup label="CSE">
    <optgroup label="sem 4">
        <option value="dbms">DBMS</option>
</optgroup>
<optgroup label="EEE">
</optgroup>
<optgroup label="ECE">
</optgroup>
</select>

Semester<select name="Semester">
<option value="sem 1">SEM 1</option>
<option value="sem 2">SEM 2</option>
<option value="sem 3">SEM 3</option>
<option value="sem 4">SEM 4</option>
<option value="sem 5">SEM 5</option>
<option value="sem 6">SEM 6</option>
<option value="sem 7">SEM 7</option>
</select>

<input id="button" type="submit" name="submit" value="SUBMIT">
</form>
</body>
</html>

The following one is php code

$con=mysql_connect(DB_HOST,DB_USER,DB_PASSWORD) or die("Failed to connect to MySQL: " . mysql_error());
$db=mysql_select_db(DB_NAME,$con) or die("Failed to connect to MySQL: " . mysql_error());

function updatem()
{
    session_start();
        $marks=$_POST['marks'];
        $branch=$_POST['Branch'];
        $semester=$_POST['Semester'];
        $subject=$_POST['Subject'];
        $userid=$_POST['userid'];
        if((!empty($_POST['userid']))
        &&(!empty($_POST['marks']))
        &&(!empty($_POST['Subject']))
        &&(!empty($_POST['Semester']))
        &&(!empty($_POST['Branch'])))
        {
            $query=mysql_query("UPDATE marks_list SET marks_obt=$marks 
                                WHERE username_id=$userid 
        AND branch_id=(SELECT branch_id FROM branch WHERE branch_name='$branch') AND 
        semester_id=(SELECT semester_id FROM semester WHERE semester_name='$semester') 
        AND subject_code=(select subject_code FROM subcodes WHERE 
        branch_id=(SELECT branch_id FROM branch WHERE branch_name='$branch') 
        AND 
        semester_id=(SELECT semester_id FROM semester WHERE semester_name='$semester'))") or die("insertion unsuccessful".mysql_error());

        header("Location: update_marks.html");
        }


}

if(isset($_POST['submit']))
{
    updatem();
}
?>

thanks in advance..

  • and your query is working fine. Than store the value in session. than you can display it. Thanks – arif_suhail_123 Oct 05 '14 at 06:48
  • My query is working fine, marks are getting updated.Can you suggest me an example on displaying a message that updation is successful through a variable..Thanks – balaji polakampalli Oct 05 '14 at 06:54
  • your query is horrible .. and your code is not secure at all its widely open to sql injection – NullPoiиteя Oct 05 '14 at 07:33
  • @NullPoiиteя I know but this is my miniproject and i'm at the starting stage of development , I want to deal about security issues later... but if want to help or suggest something it is heartily accepted. – balaji polakampalli Oct 05 '14 at 07:52
  • first of all .. stop using mysql_* api i mean its deprecated and no longer maintained by community – NullPoiиteя Oct 05 '14 at 08:03
  • @NullPoiиteя thanks for your advice..is it fine if i use pdo or mysqli? – balaji polakampalli Oct 05 '14 at 12:53
  • both are fine .. just use them properly and if you want to use pdo just check this answer http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/14110189#14110189 – NullPoiиteя Oct 05 '14 at 13:31

1 Answers1

1

Add this code after your update query

if(mysql_affected_rows()>0)
 {
     $_SESSION['message']='This is your message';
 }

Now in the file Where you want to display the value

Add this code

Important Note: Always start session at the top of the page.

session_start();

 echo $_SESSION['message'];
arif_suhail_123
  • 2,509
  • 2
  • 12
  • 16