Ok, So I have this Dynamic drop down that ends with the user selecting the final destination.
Once that destination is selected, I have multiple text areas that pop out displaying editable info for that destination like tags, description, hotels etc...
I am having trouble getting these editable text areas to save back to the database with the new information that was edited by the user.
I watched some tutorials using the form=post method but I just cant get it to work.
Here is an example of my javascript which grabs arrays from my ajax.php file and displays them in my html section with the #descbo...
//grabs from ajax.php and generates description for that specific destination
jQuery(".wrap").on('change', '#destination', function() {
var data = 'destinationid=' +jQuery('#destination :selected').val();
jQuery.post("<?php echo plugins_url(); ?>/Destination_Drop_Down_Menu/ajax.php", data, function(data) {
if(data.errorcode ==0){
jQuery('#descbo1').html(data.chtml);
}else{
jQuery('#descbo1').html(data.chtml);
}
}, "json");
});
Here is an example of how my ajax.php file works which generates the arrays based on the the previous examples and then displays the text area boxes.
// Gets the description info from the last destination select drop down menu
$destination_id = isset($_POST['destinationid']) ? $_POST['destinationid'] : 0;
if ($destination_id <> 0) {
$errorcoded1 = 0;
$strmsg = "";
$sqlD1="SELECT * from destination WHERE IDDestination= ". $destination_id . " ORDER BY name;";
$resultD1=mysql_query($sqlD1);
$contD1=mysql_num_rows($resultD1);
if(mysql_num_rows($resultD1)){
$chtmlD1 = '<div name="description" id="description">';
while($row = mysql_fetch_array($resultD1)){
$chtmlD1 .='<textarea name="Description" cols="130" rows="10">' . $row['description'] . '</textarea>';
}
$chtmlD1 .= '</div>';
echo json_encode(array("errorcode"=>$errorcodeD1,"chtml"=>$chtmlD1));
} else {
$errorcodeD1 = 1;
$strmsg = '<font style="color:#F00;">No Description available</font>';
echo json_encode(array("errorcode"=>$errorcodeD1,"chtml"=>$strmsg));
}
}
And here is my html section with the Form method=post. And my php function that supposed to save the information but instead it just re lodes the page without saving anything.
<form action="" method="POST">
<table cellpadding="5" cellspacing="2" border="0">
<h1 align="center">General Information</h1>
<tr>
<td>description:</td>
<td><div class="wrap" id="descbo1"></div></td>
</tr>
<tr>
<td>page title:</td>
<td><div class="wrap" id="descbo2"></div></td>
</tr>
<tr>
<td>Meta Keywords:</td>
<td><div class="wrap" id="descbo3"></div></td>
</tr><tr>
<td>Meta Description:</td>
<td><div class="wrap" id="descbo4"></div></td>
</tr>
<tr>
<td>
<input type="hidden" name="addedit" value="" />
<input type="submit" value="submit" name="submit" style="background:#e5f9bb; cursor:pointer; cursor:hand;" />
</td>
</tr>
</table>
</form>
</body>
</html>
<?php
//see if the form has been completed
if (isset($_POST['submit'])){
$ID = $_POST['IDDestination'];
$description = $_POST['description'];
if($ID&&$description){
$exists = mysql_query("SELECT * FROM destination WHERE IDDestination='$ID'") or die("the Query could not be done ");
if(mysql_num_rows($exists) !=0 ){
//update the description
mysql_query("UPDATE destination SET description='$description' WHERE IDDestination='$ID'") or die ("Update could not be applied.");
echo "successful";
}
}
}
?>
I have no idea what I am doing wrong.Also a beginner
Any help would be much appreciated.