Win a copy of Terraform in Action this week in the Cloud forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • Al Hobbs
  • salvin francis

recod is not inserting in mysql databse

Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
insert.html file

<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<meta name="generator" content="CoffeeCup HTML Editor (">
<meta name="created" content="Sat, 24 Sep 2011 15:42:13 GMT">
<meta name="description" content="">
<meta name="keywords" content="">

<!--[if IE]>
<script src=""></script>
<div id="myDiv"><h2>CREATE ACCOUNT</h2></div>
<form name="myform" >
First name :<input type="text" name="fname" id="fname"><br /><br />
Last name :<input type="text" name="lname" id="lname"><br /><br />
age :<input type="text" name="age" id="age" /><br /><br />
Hometown :<input type="text" name="hometown" id="hometown" /><br /><br />
Job :<input type="text" name="job" id="job" /><br /><br />
<input type="button" value="Insert" onClick='ajaxfunction()' />


<script type="text/javascript" language="javascript">

var err=false;

var fname=document.getElementById('fname').value;
var age=document.getElementById('age').value;
var hometown=document.getElementById('hometown').value;
var lname=document.getElementById('lname').value;
var job=document.getElementById('job').value;
function ajaxfunction()

var ajaxreq=new XMLHttpRequest();
alert("your browser broked");



var query1="?fname=" + fname + "&lname=" + lname + "&age=" + age + "&hometown=" + hometown + "&job=" + job;
alert(query1);"POST","insert.php" + query1,true);




$dbhost = "localhost";
$dbuser = "scott";
$dbpass = "tiger";
$dbname = "test";

$link=mysql_connect($dbhost, $dbuser, $dbpass);
die("could not connect to mysql');
mysql_select_db($dbname,$link) or die("could not open" .mysql_error());

$query="INSERT INTO employees VALUES('$_POST[fname]','$_POST[lname]','$_POST[age]','$_POST[hometown]','$_POST[job]')";

mysql_query($query) or die (mysql_error() );


echo "record inserted";

my recorded is not being inserted ,sometimes it insert a blank & sometimes it doesnot inserts only.
also echo "record inserted" doesnot gets printed even if it insert blank

help me
Posts: 15385
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You are sending the data viw get, not post. You are appending the values to the querystring.

If you want post it has to be placed in send().

Read more about the basics of JavaScript since any tutorial would have pointed this out.

You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic