brandensmith1 Posted February 5, 2008 Share Posted February 5, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/89487-solved-javascript-form-post-to-get-a-php-value/ Share on other sites More sharing options...
brandensmith1 Posted February 5, 2008 Author Share Posted February 5, 2008 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'] Quote Link to comment https://forums.phpfreaks.com/topic/89487-solved-javascript-form-post-to-get-a-php-value/#findComment-458487 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.