So here it is.
In my php file i have like this?
PHP Code:
<?php
$db_host = 'localhost:8889';
$db_database = 'PHPTest';
$db_username = 'root';
$db_password = 'root';
$data = $_GET['data'];
$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection){
die("Connection error".mysql_error());
}
$db_select = mysql_select_db($db_database);
if (!$db_select){
die("Database problem".mysql_error());
}
if(isset($_GET['ac']) && $_GET['ac']=='saveData')
saveData($data);
$querry = "SELECT * FROM cars";
$result = mysql_query($querry, $connection);
if (!$result){
die("No result returned");
}
$num = mysql_num_rows($result);
if ($num != 0) {
$file= fopen("results.xml", "w");
$_xml ="<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\r\n";
$_xml .="<cars>\r\n";
while ($row = mysql_fetch_array($result)) {
if ($row["id"]) {
$_xml .="\t<car>\r\n";
$_xml .="\t<id>" . $row["id"] . "</id>\r\n";
$_xml .="\t\t<model>" . $row["model"] . "</model>\r\n";
$_xml .="\t\t<brand>" . $row["brand"] . "</brand>\r\n";
$_xml .="\t\t<year>" . $row["year"] . "</year>\r\n";
$_xml .="\t\t<color>" . $row["color"] . "</color>\r\n";
$_xml .="\t</car>\r\n";
} else {
$_xml .="\t<id title=\"Nothing Returned\">\r\n";
$_xml .="\t\t<model>none</model>\r\n";
$_xml .="\t</id>\r\n";
}
}
$_xml .="</cars>";
fwrite($file, $_xml);
fclose($file);
echo "XML has been written. <a href=\"results.xml\">View the XML.</a>";
} else {
echo "No Records found";
}
function saveData($data){
var_dump(json_decode_mycode($data, true));
$sql_insert = "INSERT INTO `cars` VALUES ('12','Renault','Logan','2000','Blue')";
$checkresult = mysql_query($sql_insert);
if ($checkresult) echo 'update query succeeded';
else echo 'update query failed';
//$result= mysql_query("UPDATE cars SET brand="Audi", year="2009", color="alb" WHERE model="S40"");
}
function json_decode_mycode($data){
$comment = false;
$model = '';
$brand = '';
$year = '';
$color = '';
for ($i=0; $i<strlen($data); $i++){
if (!$comment)
{
if ($json($i)) == 'model' $model .= $json[$i+2];
if ($json($i)) == 'brand' $brand .= $json[$i+2];
if ($json($i)) == 'year' $year .= $json[$i+2];
if ($json($i)) == 'color' $color .= $json[$i+2];
}
}if ($json[$i] == '"') $comment = !$comment;
updateDb($model, $brand, $year, $color);
}
function updateDb($model, $brand, $year, $color){
$result = mysql_query("UPDATE `cars` SET `brand` = 'C20', 'year' = '2008', 'color'='GRAY' WHERE `model`='Volvo';");
}
?>
which should ge the $data at the beginning and when it does the ac= saveData. Then in save data i decode the jason formatted data in my own way calling hte function json_decode_mycode($data). and then i do a bogus insert to check if it works. in the json_decode_mycode($data) function i call an updateDB function giving the arguments but still inserting some bogus values. And is not working. damn it.
In my js file i have like this:
Code:
bbar: [{
text: 'Gem',
handler : function(){
var records = grid.getStore().getModifiedRecords();
var data = [];
Ext.each(records, function(record) {
data.push(record.data);
});
Ext.Ajax.request({
method: 'POST',
params: {data: Ext.util.JSON.encode(data)},
url: 'update.php?data='+Ext.util.JSON.encode(data),
success: function() {
grid.getStore().commitChanges();
Ext.Msg.alert('Sending', 'OK');
Ext.Msg.alert(Ext.util.JSON.encode(data));
},
failure: function() {
Ext.Msg.alert('error', 'Not Ok');
}
})
}
}]
And i am sending the data url: 'update.php?data='+Ext.util.JSON.encode(data), like that coz it works. i already wrote it in a file and is a jason formatted data. So i get the data i suppose in my php file then everhtn else... dies
HELP HELP HELP