I have the following code and the SELECT is working correctly to pull in the form data, however, the UPDATE statement is not working. Any suggestions on what could be corrected to make it work would be greatly appreciated.
<?php
include 'includes/config.php';
require_once('includes/auth.php');
if ( isset( $_GET['aj'] ) && $_GET['aj'] == '1' ) {
if ( isset( $_GET['ax']) && $_GET['ax'] == 'education_details' ) {
$sql =
<<<SQL
SELECT *
FROM education
WHERE id = '{$_GET['rid']}'
ORDER BY date_completed DESC
SQL;
$sql_result = mysql_query($sql) or die("Get education detail error: " . mysql_error());
while ( $row = mysql_fetch_assoc($sql_result) ) {
$education_info = array(
'member_id' => $row['member_id'],
'name' => $row['name'],
'degree' => $row['degree'],
);
}
echo json_encode($education_info);
}
exit;
}
if ( isset($_POST['aj']) && $_POST['aj'] == '1' ) {
if (isset( $_POST['ax']) && $_POST['ax'] == 'save' ) {
$sql=
<<<SQL
UPDATE education
SET name = '{$education_info['name']}',
degree = '{$education_info['degree']}'
WHERE id = '{$education_info['rid']}'
SQL;
}
// echo json_encode($education_info);
exit;
}
?>
<html>
<head>
<link type="text/css" href="css/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery-ui-1.7.2.custom.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#accordion').accordion({
header: "h3",
collapsible: true,
active: false
});
$('#dialog').dialog({
autoOpen: false,
open: true,
modal: true,
width: 525,
buttons: {
"Cancel": function() {
$(this).dialog("close");
}
}
});
$('#dialog_link').click(function() {
$('#dialog').dialog('open');
});
education_details.initialize();
});
var education_details = {
url : '<?= $_SERVER['PHP_SELF']; ?>',
initialize : function() {
$('#dialog_edit').dialog({
autoOpen: false,
open: true,
modal: true,
width: 525,
buttons: {
"Save" : function() {
$.post("educationie.php", {"aj":"1", "ax":"save" , "rid":$(this).attr("id")}, function(data) {
alert(data);
}, "json");
// $(this).dialog('close');
},
'Cancel': function() {
$(this).dialog('close');
}
}
});
$('.edit_open').click(education_details.open);
},
open : function() {
$('#dialog_edit').dialog('open');
$.get(education_details.url, {"aj":"1","ax":"education_details","rid":$(this).attr("id")}, education_details.education_details_success, "json");
},
education_details_success : function(data) {
$("#dialog_edit input[name=name]").val(data.name);
$("#dialog_edit input[name=degree]").val(data.degree);
}
};
</script>
</head>
<body>
<?php
if ( $_POST['ax'] == "new" ) {
// echo "DID IT GO HERE"; exit;
$sql=<<<SQL
INSERT INTO education (member_id, name, degree)
VALUES (
'{$_SESSION['SESS_MEMBER_ID']}',
'{$_POST['name']}',
'{$_POST['degree']}'
)
SQL;
if(mysql_query( $sql ) or die ( "Insert failed." . mysql_error()) );
// echo $sql; exit;
// header( "Location: education.php");
}
?>
<button id="dialog_link" class="ui-button ui-state-default ui-corner-all">Add New</button>
<br>
<div id="dialog" title="Add New" style="display:none;">
<form action="<?= $_SERVER["PHP_SELF"];?>" method="post">
<input type="hidden" name="ax" value="new">
Institution<br><input type="text" name="name" /><br>
Degree(s) Earned<br><input type="text" name="degree" /><br>
<input type="submit" name="SUBMIT" value="submit" class="ui-button ui-state-default ui-corner-all"/>
</div>
<div id='dialog_edit' title='Edit' style="display:none;">
<form action="<?= $_SERVER["PHP_SELF"];?>" method="post">
Institution<br><input type="text" name="name" /><br>
Degree(s) Earned<br><input type="text" name="degree" /><br>
</form>
</div>
<div id="accordion">
<?
$sql = mysql_query(" SELECT *
FROM education
WHERE member_id = '" . $_SESSION['SESS_MEMBER_ID'] . "'
ORDER BY date_completed DESC");
while($row = mysql_fetch_array($sql)){
echo "<h3><a href=#>" . $row['name'] ."</a></h3>";
echo "<div>
<table>
<tbody>
<tr>
<td valign='top'>
<a id=\"" . $row['id'] . "\" class=\"edit_open\" href=\"javascript:void(0)\">Edit</a>
<br> Degree(s): ". $row['degree'] .
"</td>
<td style='padding-left:85px;'>
</td>
</tr>
</tbody>
</table>
</div>";
}
mysql_close($con);
?>
</div>
</body>
</html>