Hi everyone,
On my jokes site, my users can post comments.
Once they click on “SUBMIT button”, another page called putjokesinDB . php gets called.
below are the codes.
<?php
$con = mysql_connect(“localhost”,“myusername”,“mypassword”);
mysql_select_db(“jokesdb”, $con);
$comment=mysql_real_escape_string($_POST[‘comment’]);
$sql=“INSERT INTO comments (comment) VALUES (‘$comment’)”;
echo “Comment has been made”;
mysql_close($con);
?>
<html>
<head>
<script language=“JavaScript”>
var time = null
function move() {
window.location = ??? WHAT DO I PUT HERE ???
}
//–>
</script>
</head>
<body onload=“timer=setTimeout(‘move()’,1000)”>
<h2>Redirecting back to main</h2>
</body>
</html>
I tried to google out for answers, but can’t find any that works well.
All advice, tips and help is greatly appreciated! thanks all.
in your previous page save the $_SERVER[‘QUERY_STRING’]; into a session var
and in the next page:
<?php
session_start();
$ref = $_SESSION['ref'];
$con = mysql_connect("localhost", "myusername", "mypassword");
mysql_select_db("jokesdb", $con);
$comment = mysql_real_escape_string($_POST['comment']);
$sql = "INSERT INTO comments (comment) VALUES ('$comment')";
echo "Comment has been made";
mysql_close($con);
?>
<html>
<head>
<script language="JavaScript">
var time = null
function move() {
window.location = "<?php echo $ref ?>";
}
//-->
</script>
</head>
<body onload="timer=setTimeout('move()',1000)">
<h2>Redirecting back to main</h2>
</body>
</html>
sorry, I am such a newbie lol…
any idea how to do like what you said as above ?
by the way, this is my codes from the previous page.
//A TEXT BOX FOR USER TO LEAVE COMMENTS
echo "Post Comments";
echo"<form method='POST' action='putjokesinDB.php' NAME='comment_form' onSubmit='return commentempty();'>";
echo "<p><textarea rows='6' name='comment' cols='45' maxlength='1000'></textarea><br>";
echo "<p><input type='submit' value='Submit' name='B1'></p>";
echo "</form>";
it should be $_SERVER[‘SCRIPT_NAME’];
<?php
session_start();
$_SESSION['ref'] = $_SERVER['SCRIPT_NAME'];
//A TEXT BOX FOR USER TO LEAVE COMMENTS
echo "Post Comments";
echo"<form method='POST' action='putjokesinDB.php' NAME='comment_form' onSubmit='return commentempty();'>";
echo "<p><textarea rows='6' name='comment' cols='45' maxlength='1000'></textarea><br>";
echo "<p><input type='submit' value='Submit' name='B1'></p>";
echo "</form>";
window.location = "http://example.com/foo/bar.html";
Make sure to provide a regular html link for them to click as well, because not everyone enables javascript(this is why your usually told “click if you are not redirected within 5 seconds”).
Ernie1:
it should be $_SERVER[‘SCRIPT_NAME’];
<?php
session_start();
$_SESSION['ref'] = $_SERVER['SCRIPT_NAME'];
//A TEXT BOX FOR USER TO LEAVE COMMENTS
echo "Post Comments";
echo"<form method='POST' action='putjokesinDB.php' NAME='comment_form' onSubmit='return commentempty();'>";
echo "<p><textarea rows='6' name='comment' cols='45' maxlength='1000'></textarea><br>";
echo "<p><input type='submit' value='Submit' name='B1'></p>";
echo "</form>";
a big thanks to Ernie1.
it works!!!
but I did a little more research, and found out REQUEST_URI is the most suitable one for dynamic sites.
hello there my lovely crmalibu, good to see you.
errr… yeah…good point. but the problem is … my jokes site is dynamic…
its has like mydomain.com/comments.php?id=1218