$_post

Adding Data to the Database with PHP Form

Following on from my last post http://www.shaungill.co.uk/2009/03/first-things-first-connecting-to-the-database/ I’ve got round to writing the form to enter data into the MySql database using a really simple form. I’ll post the code first and then make a few comments about it (the code still uses the db_config.php file I wrote last time)…

index.php

<body>

<h1>Hello World!!</h1>
<form action="post.php" method="post">
  <input type="text" name="post_string">
  <input type="submit" value="Post">
</form>
</body>
</html>

post.php

<body>
<?php
  $sql="INSERT INTO form_test (text)
  VALUES
  ('$_POST[post_string]')";

  if (!mysql_query($sql,$conn))
    {
    die('Error: ' . mysql_error());
    }
  echo "1 record added";

mysql_close($conn)
?>
Your comment of "<?php echo $_POST["post_string"]; ?>" has been entered into the database!
</body>
</html>

The index.php file is basically the worlds simplest form with one text box with a name of ‘post_string’, and the form then posts to ‘post.php’.

Post.php is where all the action takes place.

  • $sql=”INSERT INTO form_test (text) - this is building the query string which will put the data we enter from the form into the database
  • (’$_POST[post_string]‘)”; - takes the data from the form field ‘post_string’ and builds it into the query
  • if (!mysql_query($sql,$conn)) - now, I’ve been doing my homework and the exclamation mark ! is a php negation operator and basically flips a false value to a true value and vise versa. The mysql_query($sql,$conn) is trying to make a connection to the database, and if it fails will return a value of false, so with the exclamation mark it reads “If running the query fails, then…”
  • die(’Error: ‘ . mysql_error()); - “… stop the script and give the error message, otherwise…”
  • echo “1 record added”; - “… tell the nice people that 1 record has been added”
  • mysql_close($conn) - closes the database connection
  • Your comment of “<?php echo $_POST["post_string"]; ?>” has been entered into the database! - I added this line for my own peace of mind, I wanted visual confirmation that the text that I had written in the form was actually in the $_POST['post_string'] array.

Thats me done for the night now, next time I’ll have a go at pulling the data out of the database and display it on the page.

formphp

Tags: , , , ,

Thursday, March 5th, 2009 Data Entry No Comments
submityourbitch public invasion Aiden Aspen college rules un glory hole Charmane Star NEXTDOORPASS Sexy big tits pornstar lesbian dildo drilling pussy pounded assparade magical feet MALEDIGITAL natural beautiful tits tranny land sexy blonde petite assparade CODYCUMMINGS outinpublic Bareblacking hazehim amazing blowjob rubs a huge cock Redhead BBW trannyland dildo drills her pussy NEXTDOORPASS outinpublic.com hazehim college rules public invasion publicinvasion Vince Ferelli Ice La Fox collegerules.com fucking ass and pussy public invasion tugjobs Brooke Banner tugjobs Blonde round ass outinpublic itsgonnahurt.com lesbian lover licks VISCONTITRIPLETS Beautiful hand job Big Mouthfuls Bang Bros bait Bus Licking Dick And Ass Medical Femdom Lesbiansportvideos Gia Malone hazehim huge tits hazehim.com submit your bitch outinpublic un glory hole submit your bitch public invasion un glory hole camel toe fat juicy ass. hazehim collegerules submityourbitch VINTAGEGAYLOOPS Confession Of Married Man publicinvasion Aiden Aspen publicinvasion SpecialExercises milfsoup collegerules porn star fucked hard evanrivers GynoOrgasmVideos BIGGEST ASS CRAVING public invasion bang pas mouth with cock Special Exercises Roxy Love Nude sport videos MedicalFemdom BIGGEST ASS CRAVING Charmane Star sexy tit fuck ungloryhole itsgonnahurt fuck team five its gonna hurt busty adventures Monsters Of Cock Kat drills NEXTDOORMALE collegerules.com Blonde gets fucked hard outinpublic.com bangbus publicinvasion Hot tight pussy outinpublic fat mature redhead itsgonnahurt collegerules.com ungloryhole Lesbian sport videos publicinvasion submityourbitch.com tranny land Big Mouthfuls TOMMYDXXX publicinvasion collegerules.com great ass CIndia Summers Lacey lounging public invasion Milf cravers outinpublic NEXTDOORHOOKUPS Amy Reid trannyland.com NEXTDOORBUDDIES SpecialExamination hazehim.com submityourbitch GAy Cumshots Extrem Nudesportvideos facial fest smacked those asses submityourbitch.com Special Examination Summer Bailey public invasion milfsoup publicinvasion tug jobs itsgonnahurt milf lessons publicnude facialfest outinpublic.com summer time milf publicinvasion college rules outinpublic.com Gyno Orgasm Videos Stephanie Cane