prinzzchyz Posted November 28, 2012 Share Posted November 28, 2012 Hi I have a first project for my self is to create a simple WEBSite I have a scripts that it can add new person and notify if added already the problem is that even i refresh the page the content of the database increases for example if I add Firstname Joe and the last name is MOnkey it will added to the database. then if I refresh the page it will also added to the database but it is blank please can anyone help me if my codes is correct, Im planning to make a COMMENT Menu in my website Firstname: Last name: Email: Comments: then save button Code: <?php include('connect_db.php'); $fname = $_POST['fname']; $lname = $_POST['lname']; $sqlinsert = "INSERT INTO people (firstname, lastname) VALUES ('$fname', '$lname')"; if (!mysqli_query($dbcon, $sqlinsert)) { die('error inserting new record'); } // end of my nested if statement $newrecord = "1 record added to the database"; ?> <html> <head> <title>Insert Data into DB</title> </head> <body> <h1>Insert Data into DB</h1> <form method="post" action="insert-data.php"> <input type="hidden" name="submitted" value="true" /> <fieldset> <legend>New People</legend> <label>First Name:<input type="text" name="fname" /></label> <label>Last Name:<input type="text" name="lname" /></label> </fieldset> <br /> <input type="submit" value="add new person" /> </form> <?php echo $newrecord ?> </body> </html> Thanks in Advance Quote Link to comment https://forums.phpfreaks.com/topic/271284-insert-data/ Share on other sites More sharing options...
Muddy_Funster Posted November 28, 2012 Share Posted November 28, 2012 your problem is that you are not checking to see if the form has been submitted before running the insert, you also have no validation or sanitization on the form inputs. As a starting point it's not three bad though, also please use code tags when posting code - it makes everything much easier to read. Quote Link to comment https://forums.phpfreaks.com/topic/271284-insert-data/#findComment-1395844 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.