get data from database onto a form
I managed to send data from the form using php & jquery/ajax. But now I need to be able to load that data back onto the form. Is it somehow possible to use the code I have for sending the data to retrieve the data?
here's the jquery
- // JavaScript Document
$(function(){
$('.save').click(function(){
var sections = $('#sections').attr('value');
var fontColor = $('#fontColor').attr('value');
var bgcolor = $('#bgcolor').attr('value');
var font = $('#font').attr('value');
var fontSize = $('#fontSize').attr('value');
var lineHeight = $('#lineHeight').attr('value');
var letterSpacing = $('#letterSpacing').attr('value');
var fontStyle = $('#fontStyle').attr('value');
var configName = $('#configName').attr('value');
//Datastring to pass through
var dataString = {sections:sections, fontColor:fontColor, bgcolor:bgcolor, font:font, fontSize:fontSize, lineHeight:lineHeight, letterSpacing:letterSpacing, fontStyle:fontStyle, configName:configName};
// Check if config name is empty
if(configName == "")
{
$('#errorMessage').append("<img src='images/error.png' id='errorImage' height='48' width='48' /><h2>Podaj nazwe konfiguracji</h2>").fadeIn("slow").delay(1000).fadeOut(2000,(function(){$(this).empty()}));
}
else {
$.ajax({
type: "POST",
url: "update.php",
data: dataString,
datatype: "xml",
success: function(){$('#successMessage').fadeIn("slow").delay(1000).fadeOut(2000);},
error: function (){$('#errorMessage').append("<img src='images/error.png' id='errorImage' height='48' width='48' /><h2>Wystapil Blad!</h2>").fadeIn("slow").delay(1000).fadeOut(2000);}
});
}
return false;
});
});
here's the php
- <?php
function report($err){
$date = date("d/m/Y G:i:s");
$fp = fopen('log.txt', 'a+');
fwrite($fp, "[" . $date . "]" . "$err\r\n");
fclose($fp);
}
$sections = $_REQUEST['sections'];
$fontColor = $_REQUEST['fontColor'];
$bgcolor = $_REQUEST['bgcolor'];
$font = $_REQUEST['font'];
$fontSize = $_REQUEST['fontSize'];
$lineHeight = $_REQUEST['lineHeight'];
$letterSpacing = $_REQUEST['letterSpacing'];
$fontStyle = $_REQUEST['fontStyle'];
$configName = $_REQUEST['configName'];
$connect = @mysql_connect("localhost", "root", "pass");
if($connect == false) {
$err = " Unable to connect to db: " . mysql_error();
report($err);
header("HTTP/1.1 401 Unauthorized");
exit;
}
mysql_select_db("ipsum") or die ("doesnt exist: " . mysql_error());
$update = "INSERT INTO con (Sections, Fontcolor, BackgroundColor, Font, FontSize, LineHeight, LetterSpacing, FontStyle, Name) VALUES ('".$sections."', '".$fontColor."', '".$bgcolor."', '".$font."', '".$fontSize."', '".$lineHeight."', '".$letterSpacing."', '".$fontStyle."', '".$configName."')";
$query = @mysql_query($update);
if($query == false) {
$err = " Unable to update: " . mysql_error();
report($err);
header("HTTP/1.1 303 See Other");
exit;
}
mysql_close($connect);
?>