9 Replies - 791 Views - Last Post: 06 November 2012 - 12:08 PM

#1 ersaurabh101  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 25
  • Joined: 18-March 09

Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:09 AM

This is my html code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Submit  Form with out refreshing page Tutorial</title>

<!-- Meta Tags -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!-- CSS -->
<link rel="stylesheet" href="css/structure.css" type="text/css" />
<link rel="stylesheet" href="css/form.css" type="text/css" />

<!-- Javascript -->
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/
libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript">
$(function() {

$(".submit").click(function() {


    var name = $("#name").val();
	var username = $("#username").val();
	
	     
	
    var dataString = 'name='+ name + '&ph=' + username;
	
	
	
	if(name=='' || username=='')
	{
	$('.success').fadeOut(200).hide();

    $('.error').fadeOut(200).show();
	
	}
	
	
	else
	{
	$.ajax({
	type: "POST",
    url: "http://funiks.com/invoice/phonebook/submit_new_contact_ajax.php",
    data: dataString,
    success: function(){
	$('.success').fadeIn(200).show();
    $('.error').fadeOut(200).hide();
		
   }
});




	}
		

    return false;
	});



});
</script>
<style type="text/css">
body{
background:url(http://s3.amazonaws.com/twitter_production/profile_background_images/6250979/bgtwitter.jpg) no-repeat;
}
.error{
	
	color:#d12f19;
	font-size:12px;
	
		
	}
	.success{
	
	color:#006600;
	font-size:12px;
	
		
	}
</style>






</head>

<body id="public">
	<div style="height:30px"></div>

<div id="container">

<div style="height:30px"></div>

<form autocomplete="off"
	enctype="multipart/form-data" method="post"  name="form">

<div class="info" style="padding-left:20px">
	<h2>Submit Form Values with jQuery and Ajax</h2>
	<div>More tutorials <a href="http://9lessons.blogspot.com" style="color:#0066CC; font-weight:bold">http://9lessons.blogspot.com</a> </div>
</div>

<ul>
		
	
<li id="foli1" 		class="   ">
	<label class="desc" id="title1" for="Field1">
		Full Name			</label>
	<div>
		<input id="name" 			name="name" 			type="text" 			class="field text medium" 			value="" 			maxlength="255" 			tabindex="1" 						/>
		</div>
	</li>
	





<li id="foli3" 		class="   ">
	<label class="desc" id="title3" for="Field3">
		User-ID			</label>
	<div>
		<input id="username" 			name="username" 			type="text" 			class="field text medium" 			value="" 			maxlength="255" 			tabindex="3" 						/>
		</div>
	</li>





	
</ul>
<div class="buttons">
				<input  type="submit" value="Submit" style=" background:#0060a1; color:#FFFFFF; font-size:14px; border:1px solid #0060a1; margin-left:12px" class="submit"/><span class="error" style="display:none"> Please Enter Valid Data</span><span  class="success" style="display:none"> Registration Successfully.......... Click To <a href="http://9lessons.blogspot.com" style="color:#0066CC; font-weight:bold">http://9lessons.blogspot.com</a></span>
	  </div>
</form>
<div style="height:20px"></div>
</div><!--container-->
</body>
</html>




and this is my php code::

<?php
mysql_connect("localhost", "funiks_phonebook", "phonebook") or die("Connection Failed");
mysql_select_db("funiks_phonebook")or die("Connection Failed");

$nm = $_POST['name'];
$phno = $_POST['ph'];
//$query = "UPDATE test SET password = '$password' WHERE name = '$user'";



$query = "INSERT INTO phonebook (contactname, phno) VALUES('$nm','$phno')";
if(mysql_query($query)){
echo "updated";}
else{
echo "fail";}
?>



why is it posting a blank record on submit, please help me !

Is This A Good Question/Topic? 0
  • +

Replies To: Form on submit is posting blank entry in table

#2 modi123_1  Icon User is online

  • Suitor #2
  • member icon



Reputation: 8374
  • View blog
  • Posts: 31,122
  • Joined: 12-June 08

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:13 AM

11	$query = "INSERT INTO phonebook (contactname, phno) VALUES('$nm','$phno')";

Are you ever telling the query object what $nm or $phno are?
Was This Post Helpful? 0
  • +
  • -

#3 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 439
  • Joined: 28-July 09

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:18 AM

View Postmodi123_1, on 06 November 2012 - 06:13 PM, said:

11	$query = "INSERT INTO phonebook (contactname, phno) VALUES('$nm','$phno')";

Are you ever telling the query object what $nm or $phno are?


Those values are declared at line 5 and 6.

Could you please var_dump both $nm and $phno just after they are declared, please?
Was This Post Helpful? 0
  • +
  • -

#4 ersaurabh101  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 25
  • Joined: 18-March 09

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:19 AM

View Postmodi123_1, on 06 November 2012 - 11:13 AM, said:

11	$query = "INSERT INTO phonebook (contactname, phno) VALUES('$nm','$phno')";

Are you ever telling the query object what $nm or $phno are?



yes , in my php i am saying this-
$nm = $_POST['name'];
$phno = $_POST['ph'];

and in my js, i am saying this-
var dataString = 'name='+ name + '&ph=' + username;
Was This Post Helpful? 0
  • +
  • -

#5 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3392
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:27 AM

View Postersaurabh101, on 06 November 2012 - 07:09 PM, said:

why is it posting a blank record on submit, please help me !

Iím not entirely sure, but posting AJAX and a form at the same time could be a problem. try what happens if you change the submit button to a click button.
Was This Post Helpful? 0
  • +
  • -

#6 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 439
  • Joined: 28-July 09

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:31 AM

View PostDormilich, on 06 November 2012 - 06:27 PM, said:

View Postersaurabh101, on 06 November 2012 - 07:09 PM, said:

why is it posting a blank record on submit, please help me !

Iím not entirely sure, but posting AJAX and a form at the same time could be a problem. try what happens if you change the submit button to a click button.


This should not pose any issues with an AJAX submission, at least it has never done so with myself.
Was This Post Helpful? 0
  • +
  • -

#7 ersaurabh101  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 25
  • Joined: 18-March 09

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:36 AM

please help me :(
Was This Post Helpful? -1
  • +
  • -

#8 Kruithne  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 99
  • View blog
  • Posts: 439
  • Joined: 28-July 09

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 11:42 AM

View Postersaurabh101, on 06 November 2012 - 06:36 PM, said:

please help me :(


I already asked for you to give me some data and you've yet too.

Quote

Could you please var_dump both $nm and $phno just after they are declared, please?

Was This Post Helpful? 0
  • +
  • -

#9 ersaurabh101  Icon User is offline

  • New D.I.C Head

Reputation: -3
  • View blog
  • Posts: 25
  • Joined: 18-March 09

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 12:07 PM

i did not understand ur quesry, this is my 2nd day in js,ajax
Was This Post Helpful? 0
  • +
  • -

#10 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3392
  • View blog
  • Posts: 9,586
  • Joined: 08-June 10

Re: Form on submit is posting blank entry in table

Posted 06 November 2012 - 12:08 PM

thatís not a problem since var_dump() is a PHP debugging function.
Was This Post Helpful? 1
  • +
  • -

Page 1 of 1