[eluser]Unknown[/eluser]
I've got a flexigrid table loading in an iframe - it works well. I try to add a row, and that seems to work ok - I give the new row a class of "new". (code below). I type in my data and press save, which is where I get lost - I'm not a js person. I grab the row with class of "new" and pass the data to a php file. This is where I get lost- in mysql.log file I"m getting the message:
INSERT INTO `varsityconcessions` WHERE `id` IN ()
so I know something is wrong. I've gotten the insert code from the net, so obviously I'm not understanding something. Can you look and see what I'm doing wrong? Incidentally, the ajax code says it is finishing correctly, because it gives me the "thank you" message....
Here are my buttons, no problems:
Code:
buttons : [
{name: 'Add', bclass: 'add', onpress : test},
{name: 'Save', bclass: 'save', onpress : test},
{separator: true}
.....
Here is where I add the empty row:
Code:
....
$("#flex1").append("<tr class='new'><td><input type='text' size='4'/><td><input type='text' size='20'/><td><input type='text' /><td><input type='text'size='20' /><td><input type='text' size='14' /><td><input type='text' size='14' /></tr>");
$("#flex1").trigger("update");
$("#flex1").trigger("appendCache");
return false;
}
.....
And here is where I process the Save button:
Code:
if (com=='Save')
{
if($('.new',grid).length>0){
var items = $('.new',grid);
var itemlist ='';
for(i=0;i<items.length;i++){
itemlist+= items[i].id.substr(3)+",";
}
if (items.length>0) {
alert("new data to save");
}
$.ajax({
type: "POST",
dataType: "json",
url: "save.php",
data: "items="+itemlist,
success: function(data){
alert("Thank you for volunteering!");
$("#flex1").flexReload();
}
});
} else {
return false;
}
....
And finally, here is the save.php file:
Code:
<?
error_reporting(0);
function runSQL($rsql) {
$hostname = "XXX"
$username = "XXXXX";
$password = "XXXX";
$dbname = "XXXX";
$connect = mysql_connect($hostname,$username,$password) or die ("Error: could not connect to database");
$db = mysql_select_db($dbname);
$result = mysql_query($rsql) or die ('test');
return $result;
mysql_close($connect);
}
$items = rtrim($_POST['items'],",");
$sql = "INSERT INTO `varsityconcessions` WHERE `id` IN ($items)";
$total = count(explode(",",$items));
$result = runSQL($sql);
$total = mysql_affected_rows();
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT" );
header("Last-Modified: " . gmdate( "D, d M Y H:i:s" ) . "GMT" );
header("Cache-Control: no-cache, must-revalidate" );
header("Pragma: no-cache" );
header("Content-type: text/x-json");
$json = "";
$json .= "{\n";
$json .= "query: '".$sql."',\n";
$json .= "total: $total,\n";
$json .= "}\n";
echo $json;
?>