I have a form in which jQuery tracks the onChage event .change(), so when something changes, it fires an ajax request, and I pass in the column, id and values ββin the url.
Here I have a PHP code that should update the data.
My question is how do I build mySQl string dynamically. and how to undo changes / updates that have just changed to db.
Here is the PHP code I'm trying to work with.
<?php require_once('Connections/connect.php'); ?>
<?php
$id = $_GET['id'];
$collumn = $_GET['collumn'];
$val = $_GET['val'];
?>
<?php
mysql_select_db($myDB, $connection);
$sqlUpdate = 'UPDATE `plProducts`.`allPens` SET `$collumn` = '$val' WHERE `allPens`.`prodId` = '$id' LIMIT 1;';
$seeResults = mysql_query($sqlUpdate, $connection);
echo $seeResults
?>
is an example OK?
$sqlUpdate = 'UPDATE `plProducts`.`allPens` SET "{$collumn}" = "{$val}" WHERE `allPens`.`prodId` = "{$id}"LIMIT 1;';
source
share