我有一个mySQL表,每个表都有一个输入ID和输入文本;有人可以帮我修复这个PHP / AJAX代码,以便我可以编辑条目的输入文本。
PHP代码:
$inputID = $_POST['inputID'];
$inputtxt = $_POST['inputtxt'];
$strSql = "UPDATE Contributions SET $inputID = '$inputID', $inputtxt='inputtxt' WHERE id = '$id'"
AJAX:
<script>
$( "#EDITsave" ).click(function() {
console.log("console")
var index = document.getElementById("editinputtext").value;
$.ajax({
type: "POST",
url: "edit.php",
data: {inputID: id, inputtxt:index},
dataType: "text",
success:function( msg ) {
alert( "Data Saved: " + msg );
}
});
});
</script>
答案 0 :(得分:0)
**
**
$inputID = $_POST['inputID'];
$inputtxt = $_POST['inputtxt'];
$id=$_POST['id'];
$mysqli = new mysqli("localhost", "my_user", "my_password", "world");
/* check connection */
if (mysqli_connect_errno()) {
echo "Connect failed: %s\n", mysqli_connect_error();
exit();
}
/* Prepare statement */
$query = "UPDATE Contributions SET inputtxt=? WHERE id = ?";
$stmt = $mysqli->prepare($query);
$stmt->bind_param($inputtxt, $inputID);
/* Execute the statement */
try{
$stmt->execute();
}catch(Exception $e){
echo $e->getMessage();
return;
}
/* close statement */
$stmt->close();
echo 'Record updated';
mysqli_close($link);