reyjoel reyjoel - 3 months ago 13
MySQL Question

update database with jquery and php

i try to update/edit using jquery and then save it to database with the help of php

the problem is i cant pass the new data to php or php didnt receive data from jquery

here is my form

<form method="POST" name="postForm" action="update.php">
<div id="edit">
First name:<input type="text" id="firstname" value="<?php echo $row['firstname']; ?>">
<button id="button">Edit</button>

and this is my script of jquery

modal: true,
resizable: false,
draggable: false,
autoOpen: false,
width: 400,
buttons: [
text: "Ok",
click: function() {
type: "POST",
dataType: "json",
url: "update.php",
data: { dataToUpdate: jQuery('#edit').attr('value') }
text: "Cancel",
click: function() {
jQuery(this).dialog( "close" );

// Link to open the dialog
jQuery("#button").click(function(event) {

and this is my PHP

$id = $_GET['id']; // i dont know if i should put it or not to identify the info i want to edit
$firstname = $_POST['firstname'];

$sql = "UPDATE info SET
firstname='$firstname' WHERE id=$id";

$result = mysql_query($sql);

echo json_encode($result);


You have missed the name attribute in your form's input tag that's why PHP didn't receive the variable...

<input type="text" id="firstname" name="firstname" value="<?php echo $row['firstname']; ?>">

Or make sure you are passing the value properly using JQuery.