heshan Posted October 6, 2012 Share Posted October 6, 2012 I want something like this to be done as a validation. In my form there 3 fields. Admission Number, Year and Term. If an user enters an admission number which is not exist in my database table a proper validation should display as "Invalid admission number". How this can be done? I have already validated marks added. <?php $con=mysql_connect("localhost","root",""); mysql_select_db("student_management",$con); $admission_no=$_POST["admission_no"]; $term=$_POST["term"]; $year=$_POST["year"]; //validate $query="SELECT COUNT(*) FROM mark INNER JOIN exam ON mark.exam_id=exam.exam_id WHERE mark.admission_no='$admission_no' AND exam.exam_name='$term' AND exam.year='$year'"; $result=mysql_query($query); $row=mysql_fetch_array($result); if($row[0]==0) { header("location:addStudentMarkForm.php?admission_no=".$admission_no."&term=".$term."&year=".$year); exit(); }else{ ?> <?php echo "For this admission number ".$admission_no." tream".$term." marks has been already Added."; echo "<BR><BR><BR>"; echo "<a href='addStudentMark.php'>Go to Add student mark page.</a>"; exit(); } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 6, 2012 Share Posted October 6, 2012 What are you stuck on? You've already done 1, what's the problem? Quote Link to comment Share on other sites More sharing options...
heshan Posted October 6, 2012 Author Share Posted October 6, 2012 I have tried this one..But nothing happens. <?php if ($_POST){ $admission_no=$_POST["admission_no"]; if (!$admission_no){ $msg = "An invalid number"; } } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 6, 2012 Share Posted October 6, 2012 Do you have error reporting on? You'll want to use isset, and sanitize your data. Use print_r to see what was POSTed Quote Link to comment Share on other sites More sharing options...
heshan Posted October 6, 2012 Author Share Posted October 6, 2012 I have used this one..But it didn't work either..No output. <?php if (isset($_POST)){ $admission_no=$_POST["admission_no"]; if (!$admission_no){ $msg = "Invalid id"; print_r($admission_no); } ?> Quote Link to comment Share on other sites More sharing options...
Jessica Posted October 6, 2012 Share Posted October 6, 2012 If there's no admission number, why would printing it to the screen do any good? Do you understand what your code does? Did you lookup what print_r does? Quote Link to comment Share on other sites More sharing options...
heshan Posted October 7, 2012 Author Share Posted October 7, 2012 Actually not..i have very little understanding..Could you please help me?? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.