Jump to content

[SOLVED] Javascript Form Post to get a Php value


brandensmith1

Recommended Posts

Okay, what I'm working on is a video page for my website that gets the video information from a mysql database. I want to make it so I can delete posts from the page, which worked until I decided to implement a javascript confirm() verification. But what has been driving me crazy is why for some reason it will work ONCE and only ONCE then never work again (atleast not working again within 15-20 minutes) when I have no kind of time limit for updating the database.

 

Right now my script looks like this

 

<?php
//open database blah blah blah
for($i = 0; $i <= $nums; $i++)
{
//if they selected edit include the edit info

//Heres where it checks if the hidden form was set
else if(isset($_POST['deleteer']))
{
	include 'edicomm.php';
}

//if they pressed cancel clear sessions
}
?>
<html>
<head>
<script language="javascript">
function confirmation(yarbar) 
{
	var answer = confirm("Delete this Post?");
	if (answer)
	{
		document.pageform.deleteer.value = yarbar;
		document.pageform.submit();
	}
}
</script>
</head>
<body>
//blah blah blah script
//then start the loop to print the video's comments

//if edit isn't selected and the person viewing the page is the creator of the post
<?php
{
//echo the comments
echo "
<form method=\"post\" name=\"pageform\" action=\"{$_SERVER['PHP_SELF']}>
<div align=\"right\" class=\"buttons\">
<input type=\"button\" onclick=\"confirmation(".$row['num_of_coms'].")\" name=\"deleted\" value=\"delete\"> 
<input type=\"submit\" name=\"edit".$row['num_of_coms']."\" value=\"edit\">
<input type=\"hidden\" name=\"deleteer\" value=\"\"></div>
</form>";
}
?>

 

What the last part does is create a delete button, edit button, and an empty hidden form object. ".$row['num_of_coms']." returns the number of that comment in the list of comments from my database. I think the problem is in the very last page when it actually deletes the data from the database "edicomm.php" (which doesn't really make sense because the script works flawlessly without the javascript)

 

The final file it goes to "edicomm.php" looks like this...

<?php
....
if($_POST['deleteer'] == $row['num_of_coms'])
//then delete the comment
?>

 

Anyone have any ideas why it works once but not again or am I taking the completely wrong approach to do this?

Link to comment
Share on other sites

Nevermind, I figured out a way to do it. I just did a GET instead of POST, changing the function to

function confirmation(yarbar) 
{
	var answer = confirm("Delete this Post?");
	if (answer)
	{
		window.location = location.href+"?yes=<?php echo "".$_SESSION['curvid']."&jingledoodle=".$_SESSION['curcompg'].""; ?>&deleteer="+yarbar;
	}
}

where $_SESSION['curvid'] is the current video, and $_SESSION['curcompg'] is the current page of comments, then just changed the $_POST['deleteer']'s to $_GET['deleteer']  :)

Link to comment
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.