murli800 Posted July 9, 2011 Share Posted July 9, 2011 what should i do to restrict data insertion only when i add by form..now whenever i am refreshing data automatically got inserted in the database...check the if statement which i bolded -------------------------------------------------------- <?php /* * To change this template, choose Tools | Templates * and open the template in the editor. */ include("include/sessionStart.php"); include("include/dbConnect.php"); $query = "SELECT * FROM schoolmaster"; $result = mysql_query($query); $arr = mysql_fetch_assoc($result); //while($dep = mysql_fetch_array($result1,MYSQLI_ASSOC)){ //print_r($dep); //} if(!empty($_GET['submit']) and $_GET['submit']=="Add" ) { $depName = $_GET['txtDepName']; $status = $_GET['radioStatus']; echo $yes =mysql_query("INSERT INTO department(departmentName,status) VALUES( '$depName','$status' )"); } ?>\<html> <head><style> #header{ width: inherit; height:110px; background-color:#09C; margin:auto; border-bottom:2px solid #000; position:relative; border-left:2px solid #000; border-right:2px solid #000; float:left; } h1{ position:absolute; left:205px; top:0px; margin-top:0px; } h2{ position:absolute; left:205px; top:38px; margin-top:0px; } h3{ position:absolute; left:205px; top:68px; margin-top:0px; } #container1{ width:800px; margin:auto; } label{ width:190px; font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif; font-weight:bold; font-size:19px; float:left; margin:4px; } table{ position:absolute; border:none; top:0px; } td{ font-family:"Palatino Linotype", "Book Antiqua", Palatino, serif; font-weight:bold; width:138px; } </style> <script type="text/javascript" language="javascript"> function checkFill(){ var name = document.formAddDep.txtDepName.value if(name == "") { alert("Please fill department field"); document.formAddDep.txtDepName.focus(); return false; } if(!document.formAddDep.radioStatus[0].checked && !document.formAddDep.radioStatus[1].checked) { alert("Please choose the status"); return false; } } </script> </head> <body> <div id="container1"> <div id="header"> <img src="<?php echo $arr['schoolLogo']; ?>" width="200px" height="110px" /> <h1><?php echo $arr['schoolName']; ?></h1> <h2><?php echo $arr['schoolAddress']; ?></h2> <h3><?php echo $arr['schoolContact']; ?></h3> </div> <div style="margin-left:20px;"> <?php include("dropDown.php");?> </div> <div style="width: 620px; height:400px; position:relative; float: right; background-color: #FFDFFF;text-align:center;"> <form name="formAddDep" action="#" method="get"> <fieldset style="width:200px; float:right; border:2px solid #000; "> <legend>Update</legend> <label>New Department</label><input style="width:180px;" type="text" name="txtDepName" value="" tabindex="1"> <input type="hidden" name="hide" value="ok" /> <label>Status</label><br/> E<input type="radio" name="radioStatus" value="e" /> D<input type="radio" name="radioStatus" value="d" /><br/> <input type="submit" name="submit" value="Add" onClick="return checkFill()"> </fieldset> </form> <table > <tr> <td>Department Id</td> <td>Department Name</td> <td>Status</td> </tr> <?php $query2 = "SELECT * FROM department ORDER BY deptId ASC"; $result2 = mysql_query($query2);while($dep = mysql_fetch_assoc($result2)){echo "<tr/>";foreach($dep as $value) {?> <td><?php echo $value;?></td> <?php }echo "</tr>";}?> </table> <?php // if(!empty($yes)){echo "<h4>department Added</h4>"; /// echo "<a href=\"changeDisplay.php\">BACK</a>"; // } ?> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/241479-why-after-refreshing-page-data-inserting-again-and-again-in-database/ Share on other sites More sharing options...
phpjay Posted July 9, 2011 Share Posted July 9, 2011 see this links hope you will solve your problem http://www.ehow.com/how_8555961_compare-insert-records-php-mysql.html Quote Link to comment https://forums.phpfreaks.com/topic/241479-why-after-refreshing-page-data-inserting-again-and-again-in-database/#findComment-1240450 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.