$5 if you can help me with this simple JQuery Submit Form

Discussion in 'jQuery' started by nickharper, Jul 23, 2009.

  1. #1
    Hi,

    I am trying to submit information from a form to a mysql database but I am having a couple of issues in the fact that it doesn't actually send it through.

    I have tested my php file by submitting directly to that and it seems to work fine.

    If you can help me get this working I will send $5 straight away.

    Here is my form:

     <form id="submit" method="post">
    		<fieldset>
    		  <legend>Enter Information</legend>
    			<label for="name">Name:</label>
                           <input id="name" class="text" name="name" size="20" type="text" />
                           <label for="email"><br />
    	      Email:</label>
                           <input id="email" class="text" name="email" size="20" type="text" />
     <input id="gamesid" name="gamesid" type="hidden" value="<?php echo $row_GameInfo['id']; ?>" />
    			<label for="url"><br />
    		    URL:</label>
                           <input id="url" class="text" name="url" size="20" type="text" />
              <label for="comment"><br />
    		    Comment:</label>
                           <textarea name="comment" cols="20" rows="5" class="text" id="comment"></textarea>
                           
     
    			<button class="button positive"> <img src="../images/icons/tick.png" alt="" /> Add Comment!!! </button>
    		</fieldset>
    	</form>
    <div class="success" style="display:none;"><p>Thanks for the comment.</p><p>This will be approved and will appear on Xbox 360 Multiplayer Games within the next couple of hours</p></div>
    Code (markup):
    Here is my Javascript File:

    $(document).ready(function(){
    	$("form#submit").submit(function() {
     	
    	var name     = $('#name').attr('value');
    	var email     = $('#email').attr('value'); 
    	var url     = $('#url').attr('value');
    	var comment     = $('#comment').attr('value'); 
    	var gamesid     = $('#gamesid').attr('value'); 
     
    		$.ajax({
    type: "POST",
    url: "addcomment.php",
    data: "name="+ name +"& email="+ email +"& url="+ url +"& comment="+ comment +"& gamesid="+ gamesid,
    success: function(){
    $('form#submit').hide();
    $('div.success').fadeIn();
    }}); 
    	return false;
    	});
    });
    Code (markup):
    Here is my PHP File:

    <?php
            // where is your config file stored?
    	include ("config.php");
     
    	// CLIENT INFORMATION
    	$name        = htmlspecialchars(trim($_POST['name']));
    	$email        = htmlspecialchars(trim($_POST['email']));
    	$url        = htmlspecialchars(trim($_POST['url']));
    	$comment        = htmlspecialchars(trim($_POST['comment']));
    	$gamesid        = htmlspecialchars(trim($_POST['gamesid']));
     
        $addClient  = "INSERT INTO comments (name,email,url,comment,gameid) VALUES ('$name','$email','$url','$comment','$gamesid')";
        mysql_query($addClient) or die(mysql_error());
     
    ?>
    PHP:
     
    nickharper, Jul 23, 2009 IP
  2. latro

    latro Peon

    Messages:
    38
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Why are you making data a string after you've already written the values to variable. Just push the values through for data. See what that does.
     
    latro, Jul 26, 2009 IP
  3. nickharper

    nickharper Active Member

    Messages:
    732
    Likes Received:
    16
    Best Answers:
    0
    Trophy Points:
    75
    #3
    Thanks, this is now sorted!
     
    nickharper, Jul 29, 2009 IP