Reputation: 335
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..
Upvotes: 0
Views: 1443
Reputation: 2509
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'];
Upvotes: 1