atomsmasher atomsmasher - 2 months ago 6
MySQL Question

mysql database no longer receiving data after addition of .htaccess file?

So I have some data that is sent to a database, and it worked well at one point, nothing changed at all except the addition of an .htaccess file, when I inspect the page to see whats happening I see:

Invalid query:

my php file that points to my database with my credentials is :


$dbc = mysql_connect('localhost', 'my_user', 'my_password');
mysql_select_db('mydatabase', $dbc);


and the file that sends the data:


function mysql_insert($table, $inserts) {
$values = array_map('mysql_real_escape_string', array_values($inserts));
$keys = array_keys($inserts);

return mysql_query('INSERT INTO `'.$table.'` (`'.implode('`,`', $keys).'`) VALUES (\''.implode('\',\'', $values).'\')');

// get the table name
$tab = $_POST['table'];

// decode the data object from json
$trials = json_decode($_POST['json']);

// get the optional data (decode as array)
$opt_data = json_decode($_POST['opt_data'], true);
$opt_data_names = array_keys($opt_data);


// for each element in the trials array, insert the row into the mysql table
$to_insert = (array)($trials[$i]);
// add any optional, static parameters that got passed in (like subject id or condition)
$to_insert[$opt_data_names[$j]] = $opt_data[$opt_data_names[$j]];
$result = mysql_insert($tab, $to_insert);

// confirm the results
if (!$result) {
die('Invalid query: ' . mysql_error());
} else {
print "successful insert!";


and in my
file I see:

PHP Warning: array_keys() [<a href='function.array-keys'>function.array-keys</a>]: The first argument should be an array in /path/to/savedata.php on line 33

after some searching I found this post:

so I tried adding that to the .htaccess file and then i inspected it and it looks like my host went ahead and altered it:

# File modified on Wed Sep 14 16:28:37 2016 by server
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
# php_value session.cookie_domain http://mydomain

Not sure what else to do ??


The problem seems to be that adding the .htaccess file triggered some change in the php configuration to set magic quotes on, which is what resulted in the \"\\\"rt\\\",\\\"responses format. After switching to php 5.6, which no longer supports magic quotes, the data saves correctly and there is no longer a problem