gorgon2k Posted July 28, 2010 Share Posted July 28, 2010 Ok so here's my code first the ajax/javascript, secondly the php. Issue i'm having is that first it wasn't entering any data into my database then eventual through much troubleshooting I figured out that if I add more then 10 variables in my INSERT INTO query it wont work. Ten or less and it works perfect. I CAN NOT figure this out?! Note, at the bottom of the php script I have the script that I would like to work, commented out, and the script that is currently working, active. You can see it only has 10 working entries. function entervehicle(){ var stk = document.getElementById("stk").value var my = document.getElementById("my").value var mak = document.getElementById("mak").value var mod = document.getElementById("mod").value var mil = document.getElementById("mil").value var pri = document.getElementById("pri").value var bst = document.getElementById("bst").value var len = document.getElementById("len").value var eng = document.getElementById("eng").value var dor = document.getElementById("dor").value var tra = document.getElementById("tra").value var gvw = document.getElementById("gvw").value var inc = document.getElementById("inc").value var exc = document.getElementById("exc").value var cfo = document.getElementById("cfo").value var titl = document.getElementById("titl").value var desc = document.getElementById("desc").value var vin = document.getElementById("vin").value var pic1 = document.getElementById("pic1").value var pic2 = document.getElementById("pic2").value var pic3 = document.getElementById("pic3").value var pic4 = document.getElementById("pic4").value var pic5 = document.getElementById("pic5").value var pic6 = document.getElementById("pic6").value var pic7 = document.getElementById("pic7").value var pic8 = document.getElementById("pic8").value var pic9 = document.getElementById("pic9").value var linksubmit ="../php/entervehicle.php?stk=" + stk +"&my=" + my +"&mak=" + mak +"&mod=" + mod +"&mil=" + mil +"&pri=" + pri +"&bst=" + bst +"&len=" + len +"&eng=" + eng +"&dor=" + dor +"&tra=" + tra +"&gvw=" + gvw +"&inc=" + inc +"&exc=" + exc +"&cfo=" + cfo +"&titl=" + titl +"&desc=" + desc +"&vin=" + vin +"&pic1=" + pic1 +"&pic2=" + pic2 +"&pic3=" + pic3 +"&pic4=" + pic4 +"&pic5=" + pic5 +"&pic6=" + pic6 +"&pic7=" + pic7 +"&pic8=" + pic8 +"&pic9=" + pic9 alert(linksubmit); var entrequest = getHTTPObject(); if(entrequest) { entrequest.open("GET",linksubmit,true); entrequest.onreadystatechange = function(){ entveh(entrequest); }; entrequest.send(null); } } function entveh(entrequest){ if(entrequest.readyState == 4){ if(entrequest.status == 200){ var myPHP = entrequest.responseText; document.getElementById("adminmain").innerHTML = myPHP; } } } <?php $stk = $_GET['stk']; $my = $_GET['my']; $mak = $_GET['mak']; $mod = $_GET['mod']; $mil = $_GET['mil']; $pri = $_GET['pri']; $bst = $_GET['bst']; $len = $_GET['len']; $eng = $_GET['eng']; $dor = $_GET['dor']; $tra = $_GET['tra']; $gvw = $_GET['gvw']; $inc = $_GET['inc']; $exc = $_GET['exc']; $cfo = $_GET['cfo']; $titl = $_GET['titl']; $desc = $_GET['desc']; $vin = $_GET['vin']; $pic1 = $_GET['pic1']; $pic2 = $_GET['pic2']; $pic3 = $_GET['pic3']; $pic4 = $_GET['pic4']; $pic5 = $_GET['pic5']; $pic6 = $_GET['pic6']; $pic7 = $_GET['pic7']; $pic8 = $_GET['pic8']; $pic9 = $_GET['pic9']; require("database.php"); $tresult = mysql_query("INSERT INTO automobile_stat (stock_number,model_year, make, model, miles, price, body_style, length, description, trans) VALUES ('$stk', '$my', '$mak', '$mod', '$mil', '$pri', '$bst', '$len', '$desc', '$tra')"); /*$tresult = mysql_query("INSERT INTO automobile_stat (stock_number, model_year, make, model, miles, price, body_style, length, description, engine, doors, trans, gvw, int_color, ext_color, car_fax_owner, title_desc, main_picture_src, vin) VALUES ('$stk', '$my', '$mak', '$mod', '$mil', '$pri', '$mpri', '$bst', '$len', '$desc', '$eng', '$dor', 'tra', '$gvw', '$inc', '$exc', '$cfo', '$titl', 'img', '$vin')");*/ /*$tresult=mysql_query("SELECT * FROM automobile_stat" ); $countrows = mysql_num_rows($tresult); while($row = mysql_fetch_array($tresult)){ echo $row[stock_number]; }*/ mysql_close($linkID); ?> Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/ Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2010 Share Posted July 28, 2010 There are different length limits for the URL string depending which browser you're using, so using $_GET may be the problem in this case. Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092113 Share on other sites More sharing options...
gorgon2k Posted July 28, 2010 Author Share Posted July 28, 2010 Yeah, that was going to be my next test, I knew there was a limit. I'll try and have it echo and return every variable and see what I get, i'll keep posted, thanks. Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092114 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2010 Share Posted July 28, 2010 What have you done to debug where your data is what you expect and where it is not? What does the following show (you may need to temporarily submit the data using an actual GET method form) - echo '<pre>',print_r($_GET,true),'</pre>'; Also, form your query string in a variable ($query) and echo it so that you can see what it actually contains. I suspect the problem is actually that you are not escaping any of the data being put into your query and some ' or " is breaking the query syntax. You need to use mysql_real_escape_string() on each value being put into the query. And your code does not have any error checking or error reporting logic in it to even tell you if the query failed due to an error or what the error is. Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092116 Share on other sites More sharing options...
gorgon2k Posted July 28, 2010 Author Share Posted July 28, 2010 Ok, so I tested all of the variables coming through and infact they are. Next, i'll try the method PFMaBiSmAd suggest and i'll report back Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092119 Share on other sites More sharing options...
gorgon2k Posted July 28, 2010 Author Share Posted July 28, 2010 Array ( [stk] => dsf [my] => sd [mak] => fds [mod] => fds [mil] => fds [pri] => fdsdfs [bst] => Cab Chasis [len] => sd [eng] => s [dor] => fds [tra] => sd [gvw] => sd [inc] => s [exc] => fds [cfo] => fdsfds [titl] => fds [desc] => fsd [vin] => fds [pic1] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic2] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic3] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic4] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic5] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic6] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic7] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic8] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg [pic9] => 30-flat-panel-tft-lcd-cinema-hd-monitor.jpg ) this is the return i get when I use echo '<pre>',print_r($_GET,true),'</pre>' Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092121 Share on other sites More sharing options...
PFMaBiSmAd Posted July 28, 2010 Share Posted July 28, 2010 You are going to find that when you get to this step - ...your code does not have any error checking or error reporting logic in it to even tell you if the query failed due to an error or what the error is. that you have a different number of fields listed vs the amount of data values. Putting error checking/error reporting(logging) logic in an application is important for a couple of reasons - 1) It will make debugging go quicker because you will get immediate feedback both if and where a problem is occurring. There won't be this - my code does not work and I don't know why feeling, because your code will already be telling you which statement is failing and what error is occurring. 2) In a real application on a live server you need a record of problems so that you can find and fix them. You also need to output a 'user' error message to tell them that an action cannot be completed, rather than leave them with a blank or broken web page. Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092126 Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2010 Share Posted July 28, 2010 Just noticed that in your original query string, you have 19 fields specified, but are trying to insert 20 values. That won't work that way. As PFM suggested, get the query string out of the query execution sou you can echo it, and set it up to report errors. $query = "INSERT INTO automobile_stat (stock_number, model_year, make, model, miles, price, body_style, length, description, engine, doors, trans, gvw, int_color, ext_color, car_fax_owner, title_desc, main_picture_src, vin ) VALUES ('$stk', '$my', '$mak', '$mod', '$mil', '$pri', '$mpri', '$bst', '$len', '$desc', '$eng', '$dor', 'tra', '$gvw', '$inc', '$exc', '$cfo', '$titl', 'img', '$vin')"; $tresult = mysql_query($query) or die( 'Query string: ' . $query . '<br />Produced error: ' . mysql_error() . '<br />'); Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092127 Share on other sites More sharing options...
gorgon2k Posted July 28, 2010 Author Share Posted July 28, 2010 OK, I got it, it was simply the order of my table that has given me such a headache! I appreciate all of you guys time trying to help me and methodically reading my code. Thanks so much. Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092135 Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2010 Share Posted July 28, 2010 It may seem like more work, but separating the query string from the query execution all the time is worth the few extra seconds it takes to type it that way. It gives you more options when it comes to debugging. Quote Link to comment https://forums.phpfreaks.com/topic/209108-is-something-limiting-mysql_query-insert-into-~-i-need-help/#findComment-1092140 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.