I want the success function to pick up the string it should receive from the PHP file.
The PHP complains "mysql_fetch_array() expects parameter 1 to be a resource, boolean given instead". I assume this is why the success function does not fire.
What am I doing wrong?
The jQuery:
var string = "something to be inserted";
$.ajax({
url: '...',
type: 'post',
dataType: 'json',
data: {toBeInserted: string.toLowerCase()},
success: function(data) {
console.log(data);
// some code that is to work with data
}
});
The PHP:
include 'serverStuff.php';
// A separate file with $con defined in it. Assume this works.
mysql_query("SET NAMES 'utf8'", $con);
// inserts the $_POST['toBeInserted'] into the database just fine
// assume the following are defined:
// (string) $user_name, (string) $now, (string) $statement
$sql=("SELECT * FROM table WHERE user_name=$user_name AND date=$now AND statement = $statement");
$result=mysql_query($sql, $con);
if ($row = mysql_fetch_array($result)) {
$new_id = (int) $row['id'];
}
mysql_close($con);
echo json_encode($new_id.'_'.$now);