tcnjdeluca Posted January 4, 2012 Share Posted January 4, 2012 So I am using smarty, php, mysql and jQuery to create a simple form that autosaves. I am pretty decent at MySQL, php and smarty. I am terrible at java and jQuery. Here is the template/ajax I'm using <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>ClassChatter.com</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" type="text/css" name="style1" href="style1.css"> {include file='tiny.tpl'} {literal} <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script> <script language="javascript" type="text/javascript"> <!-- Copyright 2000 by William and Will Bontrager. counter = 0; function count() { counter++; if(counter > 1) { if(counter > 2) { return false; } alert('Sometimes the servers are a bit slow. ' + 'One click is sufficient.\n\nI\'m sure the ' + 'server will respond in a few seconds.\n\n' + 'Thank you for your patience.'); return false; } return true; } // --> </script> {/literal} </head> <body> {literal} <script type="text/javascript"> $(document).ready(function(){ autosave(); }); function autosave() { var t = setTimeout("autosave()", 20000); var title = $("#txt_title").val(); var mainpost = $("#txt_mainpost").val(); if (title.length > 0 || mainpost.length > 0) { $.ajax( { type: "POST", url: "autosave.php", data: "article_id=" + {/literal}{$primid}{literal} + "&title=" + title + "&mainpost=" + mainpost, cache: false, success: function(message) { $("#timestamp").empty().append(message); } }); } } </script> {/literal} <div id="banner"><img src="../images/Classchatter2.jpg"></div> <div id="studentbar"> </div> <div id="navcontainer"> <ul id="navlist"> <li id="active">{if $formaction == 'tpostper.php' OR $formaction == 'tpostper.php?tblog=1'}<a href="tblog.php{if isset($teacherblog)}?tblog=1{/if}">{else} <a href="wblogsmarty.php">{/if}Return to Blog</a></li> </ul> </div> <div id="content"> {if $formaction == 'tpostper.php' OR $formaction == 'tpostper.php?tblog=1'} <div id="pubbox2">Would you like to upload and manage images for use in blog posts? Upgrade to <a href="http://www.classchatterlive.com" target="_blank">ClassChatterLive</a> for access to our full featured personal image gallery. Upload, organize, and edit images to use as instructional aides anywhere in the world.</div>{/if}<br> <h2>{$groupmess}</h2> <div id="formholder"> <form action="save.php" method="post" name="blogpost" onSubmit="return count()"> <h2>Title of Post:<BR> </h2> <input name="title" type="text" id="txt_title" value="{$editvar[0].Title}" size="65" maxlength="200"> <BR><BR> <h2> Body of Post:</h2> <textarea name="mainpost" id="txt_mainpost" cols="70" rows="14">{$editvar[0].comment|escape:'htmlall'} </textarea> <input name="grouppost" type="hidden" value="{$group}"> {if isset($edit)} <input name="eprimid" type="hidden" value="{$edit}"> {/if} {if !isset($edit)} <BR> <input name="article_id" type="hidden" value="{$primid}"> <input name="submit" type="submit" id="Save Post" value="Add Post"> {else} <input name="esubmit" type="submit" id="Edit Post" value="Edit Post"> {/if} <input name="tbloge" type="hidden" value="{$teacherblog}"> </form><BR> </div> </div> <a href="">Link</a> {$primid} {include file='google.tpl'} </body> </html> and my autosave.php is <?php ini_set('display_errors',1); error_reporting(E_ALL); include_once("protected/config2.php"); session_start(); // start session, duh. $title = mysql_real_escape_string($_POST['title']); $mainpost = mysql_real_escape_string($_POST['mainpost']); $id = mysql_real_escape_string($_POST['article_id']); //save contents to database $update = "UPDATE classjournal SET Title = '$title', comment = '$mainpost' WHERE primid = '$id'"; $insertsql = $db->query($update); //get timestamp $result = mysql_query("SELECT timestamp FROM 'classjournal' WHERE primid = $id"); $timestamp = mysql_result($result, 0); //output timestamp echo 'Last Saved: ', $timestamp; ?> What am I missing?? Quote Link to comment https://forums.phpfreaks.com/topic/254314-almost-have-an-autosave-function-working-wjquery/ Share on other sites More sharing options...
requinix Posted January 4, 2012 Share Posted January 4, 2012 Maybe a description of the problem you're having? Quote Link to comment https://forums.phpfreaks.com/topic/254314-almost-have-an-autosave-function-working-wjquery/#findComment-1304114 Share on other sites More sharing options...
tcnjdeluca Posted January 4, 2012 Author Share Posted January 4, 2012 Well -- I make a blank database entry on the main form page. Then nothing. It does not autosave or update the entry I made. I know that the script is running every 20 seconds, what I do not know if it is hitting the autosave.php and if it is passing the appropriate variables. Quote Link to comment https://forums.phpfreaks.com/topic/254314-almost-have-an-autosave-function-working-wjquery/#findComment-1304262 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.