JohnOP Posted July 2, 2011 Share Posted July 2, 2011 I have just set up a new register page on my site where i use jquery and php i have the jquery calling the php script so it doesn't need to refresh to process the form <script type="text/javascript" src="http://ajax.microsoft.com/ajax/jquery.validate/1.7/jquery.validate.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("#myform").validate({ debug: false, rules: { youtube: "required", password: "required", username: "required", email: { required: true, email: true } }, messages: { youtube: "<br> Enter your Youtube channel.", password: "<br> Choose your password.", username: "<br> Please choose your Username.", email: "<br> You must enter a valid Email.", }, submitHandler: function(form) { // do other stuff for a valid form $.post('process.php', $("#myform").serialize(), function(data) { $('#results').html(data); }); } }); }); </script> Now i am trying to do this on my sub4sub page so when a user clicks to sub someone the page wont refresh but will still process. <?php while($row = mysql_fetch_assoc($sql)){ ?> <center> <div class="subs"> <img src="images/sub.jpeg" height="64" style="border: none;"><br> <?php echo mysql_real_escape_string($row['subchannel']); ?><br> <center> <form action="sub4sub.php?id=<?php echo mysql_real_escape_string($row['id']); ?>" method="POST"> <input id="button" type="submit" name="sub" value="Sub" style="background: white; border: none;"> </form> </center> </div> </center> <?php } ?> the problem is that i have the id passing back to sub4sub.php so i can then update the user who has that id but for the jquery to work i need to leave the action as "" and put it into the $.post('process.php', $("#myform").serialize(), function(data) { i have tried adding the php to the end of the process.php like id=<?php echo $row['id']; ?> but it won't work. i even tried making a hidden feild in the form that will send the post id to process.php and in the page source i can see that each sub has there id within the hidden feild but on clicking any of the sub buttons it only processes the last id of the query. Basically i need to pass the id from what was sub4sub.php?id=<?php echo $row['id']; ?> to sub4subprocess.php?id=<?php echo $row['id']; ?> in the jquery code. Link to comment https://forums.phpfreaks.com/topic/240946-passing-variable-problem/ Share on other sites More sharing options...
JohnOP Posted July 4, 2011 Author Share Posted July 4, 2011 Bump Link to comment https://forums.phpfreaks.com/topic/240946-passing-variable-problem/#findComment-1238364 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.