Using variable as value in post to php/mysql

I get a random row from a mysql-server using php. I then display some information and would like to let the users give feedback on that specific row. However, I can’t seem to transfer the ID correctly to the update.php. (No updating is happening on the server). Can somebody spot out my error?Mysql-php getting a …

via PHP Website Development » Search Results » ajax:

Using variable as value in post to php/mysql

I get a random row from a mysql-server using php. I then display some information and would like to let the users give feedback on that specific row. However, I can’t seem to transfer the ID correctly to the update.php. (No updating is happening on the server). Can somebody spot out my error?
Mysql-php getting a (ugly) random row:
$con = mysql_connect($host,$user,$pass);
$dbs = mysql_select_db($databaseName, $con);
mysql_query(“SET CHARACTER SET utf8″);
mysql_query(“SET NAMES utf8″);
$result = mysql_query(“SELECT id, username, message, ttime, field1, field2 FROM field WHERE done = 0 ORDER BY RAND() LIMIT 1″);
$array = mysql_fetch_row($result);

echo json_encode($array);Then index.php:

content

Then in the update.php:

$id = $_POST[‘id’];
$sql = “UPDATE field SET field1 = field1 +1 WHERE id = ‘$id’”;
$result = mysql_query($sql);
?>
………………………….

Put a global _id in a script tag, then :
$.ajax(
url: ‘api.php’,
data: “”,
dataType: ‘json’,
success: function(data)

var id = data[0];
_id = id;
//…and

………………………….

$.post(“update.php”, id: “id” )is sending the Stringid to the server as the id. You’ll want to replace it with the actual variable that holds the id number based on which row the user selected, for example
$.post(“update.php”, id: rowIDNum )If you provide some information on how the user is selecting a row, I can provide more details on how to determine the value to put in rowIDNum.

For more info: Using variable as value in post to php/mysql

PHP Website Development » Search Results » ajax

Using variable as value in post to php/mysql

Share this post:

Related Posts

Leave a Comment