php - SQL INSERT query being executed twice -
i'm @ wit's end here. i've tried in different browsers , still same trigger error message notice: duplicate entry key 'primary'
however, it's still inserting database. think page simultaneously executing twice. code never reaches block stores session data. insight appreciated!
<?php if($_post[submit]) { $username = ""; $password = ""; $hostname = ""; $dbname = ""; //connection database: $db = mysqli_connect($hostname, $username, $password, $dbname, '3306') or die("unable connect mysql"); $id = !empty($_post[id]) ? "'$_post[id]'" : "null"; $fname = !empty($_post[fname]) ? "'$_post[fname]'" : "null"; $lname = !empty($_post[lname]) ? "'$_post[lname]'" : "null"; $sql = "insert table(id, fname, lname) values ($id, $fname, $lname)"; $result = $db->query($sql) or trigger_error($db->error); if ($result && $db->affected_rows > 0) { // store session data $_session['fileid']=$id; echo 'creating file '.$id.'<br/> <a href = "parttwo.php" class="button">continue</a>'; } else echo "no changes made."; } else echo '<form method="post" action="createfile.php"> <div><span class = "formlabel">file number:</span><input type="text" name="id"></div> <div><span class = "formlabel">first name:</span><input type="text" name="fname"></div> <div><span class = "formlabel">last name:</span><input type="text" name="lname"></div> <input class="submit" type="submit" name="submit" value="submit"> </form>'; ?>
instead of if($_post[submit])
use if(isset($_post[submit]))
Comments
Post a Comment