Jump to content

Recommended Posts

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

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.