Jump to content

Is something limiting mysql_query INSERT INTO ~ I need help


gorgon2k

Recommended Posts

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);

?>

 

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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>'

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 />');

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.