davelearning Posted January 13, 2011 Share Posted January 13, 2011 Hi all, I am trying to update a database when a form is submitted, however nothing happens when I click submit! The success message is not shown and the database is not updated. Here is my code <?php include('includes/functions.php'); include('includes/config.php'); $u_id = $_GET['u_id']; $p_id = $_GET['p_id']; $p_title = $_GET['title']; $a_id = $_GET['a_id']; session_start(); $query = mysql_query("SELECT * FROM images WHERE u_id = '$u_id' AND p_id = '$p_id'"); while($row = mysql_fetch_assoc($query)) { $i_link = $row['i_link']; $_SESSION['i_title'] = $row['i_title']; } $i_title = $_SESSION['i_title']; ?> <script type="text/javascript" src="jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $('#addCaption').hide(); $('a#addCaptionb').click(function(){ $('#addCaption').show('fast'); }); $('a#captionCancel').click(function(){ $('#addCaption').hide('fast');}) $("form#caption").submit(function() { var i_title = $('#i_title').attr('value'); var i_title = $('#p_id').attr('value'); $.ajax({ type: "POST", url: "includes/captionupdate.php", data: "i_title="+ i_title +"& p_id="+ p_id, success: function(){ $('form#caption').hide(function(){ $('div.success').fadeIn();}); } }); return false; }); }); </script> </head> <body> <div id="topbar"><a href="#" onClick="showSlidingDiv(); return false;"><img id="myimage" onclick="changeimage()" border="0" src="images/menubuttonoff.gif" /></a> Welcome back <?php echo $_SESSION['username'];?></div> <?php include('includes/menu.php');?> <div id="maincontainer"> <div id="leftbar"></div> <div id="mainbox"> Picture Title<br /><br /> <div id="picturebox"> <img src="<?php echo $i_link;?>" class="max" /> </div> <div id="addCaption"> <form name="caption" method="post"> <input name="i_title" id="i_title" type="text" maxlength="128" value="<?php echo $i_title;?>" /> <input name="p_id" type="hidden" id="p_id" value="<?php echo $p_id;?>"/> <button class="button positive"> <img src="../images/icons/tick.png" alt=""> Add Client </button> </form> </div> <br /> <a href="#" id="addCaptionb">Add Caption</a> <div class="success" style="display:none;">Submit</div> <a href="#" id="captionCancel">Close</a> </div> </div> and captionupdate.php <?php include('config.php'); $p_id = $_POST['p_id']; $i_title = $_POST['i_title']; mysql_query("UPDATE images SET i_title = '$i_title' WHERE p_id = '$p_id'"); I am new to jquery and this is the 1st thing I have attempted myself, so I apologise if the error is massively clear! I have checked all my filepaths and database info etc, all correct. Many Thanks Link to comment https://forums.phpfreaks.com/topic/224253-phpjqueryajax-form-submit-help/ Share on other sites More sharing options...
davelearning Posted January 13, 2011 Author Share Posted January 13, 2011 Got it! My form was set as a class, not an id! Link to comment https://forums.phpfreaks.com/topic/224253-phpjqueryajax-form-submit-help/#findComment-1158732 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.