wright67uk Posted April 21, 2011 Share Posted April 21, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/234392-no-database-insert-is-happening/ Share on other sites More sharing options...
Pikachu2000 Posted April 21, 2011 Share Posted April 21, 2011 Separate the query string from the query execution, and echo it along with mysql_error() while developing. $query = "query string here"; mysql_query($query) or die( "<br>Query: $query<br>Error: " . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/234392-no-database-insert-is-happening/#findComment-1204683 Share on other sites More sharing options...
Drummin Posted April 22, 2011 Share Posted April 22, 2011 That extra space might be giving you problems. '$tier_two' , Quote Link to comment https://forums.phpfreaks.com/topic/234392-no-database-insert-is-happening/#findComment-1204777 Share on other sites More sharing options...
dreamwest Posted April 22, 2011 Share Posted April 22, 2011 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()); Quote Link to comment https://forums.phpfreaks.com/topic/234392-no-database-insert-is-happening/#findComment-1204800 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.