Jump to content

No database insert is happening?


wright67uk

Recommended Posts

Hello, ive got the right output from the code below, only my mysql query doesnt seem to be working as it should.

Im not too great with mysql so please any help or suggestions would be great.

I have tried the code but when I check my database nothing has been inserted. !?!

 

<?php 
  include('db.php');
  include('func.php');
?><html><head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Chained Select Boxes using PHP, MySQL and jQuery</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#wait_1').hide();
$('#drop_1').change(function(){
  $('#wait_1').show();
  $('#result_1').hide();
      $.get("func.php", {
	func: "drop_1",
	drop_var: $('#drop_1').val()
      }, function(response){
        $('#result_1').fadeOut();
        setTimeout("finishAjax('result_1', '"+escape(response)+"')", 400);
      });
    	return false;
});
});

function finishAjax(id, response) {
  $('#wait_1').hide();
  $('#'+id).html(unescape(response));
  $('#'+id).fadeIn();
}
</script>
</head>
<body>
<p>
<form action="" method="post">
Name: 		<input type="text" name="Name" /><br />
Phone:	                <input type="text" name="Phone" /><br />
Email: 		<input type="text" name="Email" /><br />
Postcode: 	<input type="text" name="Postcode" /><br />
Web Address: <input type="text" name="Website" /><br /><br />
<select name="drop_1" id="drop_1"> 
<option value="" selected="selected" disabled="disabled">Select a Category</option>  
<?php getTierOne(); ?>
</select> 
<span id="wait_1" style="display: none;">
<img alt="Please Wait" src="ajax-loader.gif"/>
</span>
<span id="result_1" style="display: none;"></span> <br />

</form>
</p>
<p>
<?php if(isset($_POST['submit'])){
$drop = $_POST['drop_1'];
$tier_two = $_POST['Subtype'];
echo "You selected ";
echo $drop." & ".$tier_two;
}
$Name = $_POST["Name"];
$Phone = $_POST["Phone"];
$Email = $_POST["Email"];
$Postcode = $_POST["Postcode"];
$Website = $_POST["Website"];
echo "<br>";
echo $Name;
echo "<br>";
echo $Website; 
mysql_query ("INSERT INTO business (Name,  Type, Subtype, Phone, Email, Postcode, Web Address)
		  VALUES ('$Name', '$drop', '$tier_two' , '$Phone', '$Email', '$Postcode', '$Website')");
?>

Im not sure it makes a difference but, I am adding data into each column of my database with the exception of the 1st column named 'ID' which is set to auto_increment.

Link to comment
Share on other sites

Its alot easier to use SET instead of VALUES, because you can see which field is what.

 

mysql_query ("INSERT INTO `business` SET `Name`='{$Name}' ,  `Type`='{$drop}', `Subtype`='{$tier_two}', `Phone`='{$Phone}', `Email`='{$Email}', `Postcode`='{$Postcode}', `Web Address`='{$Website}' ")or die(mysql_error());

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.