Jump to content

Recommended Posts

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.