I am trying to get a page to redirect after I click the button and after the database updates but it doesnt seem to work.
I have a form that completes in itself, to cut down on the number of pages used (e.g no, thanks content has been edited" page) but after the content has been edited i wish to redirect back home.
form and database update:
<div id = "errormsg"> </div>
<?php
echo "<table border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"7\" style=\"font-family:Arial;font-size:11px\">";
echo "<tr>";
echo "<td> </td>";
echo "<td> </td>";
echo "</tr>";
echo "<tr>";
echo "<td><form name=\"conf开发者_运维百科home\" method=\"post\" action=\"\" onsubmit=\"return valText()\"><textarea name=\"tag\" cols=\"20\" rows=\"3\" id=\"tag\">$row[tagbrief]</textarea></td></tr>";
echo "<tr><td><input type=\"submit\" value=\"Edit\"></form></td></tr>";
echo "<tr></tr>";
echo "</table><br/>";
$tagbrief = $_POST['tag'];
mysql_query("UPDATE quackedup SET tagbrief='$tagbrief' WHERE id='1'");
?>
JS validation for ref
<script type="text/javascript">
function valText(){
var text = document.getElementById('tag');
var div = document.getElementById('errormsg');
var lets = /^[0-9a-zA-Z\s\-\'(\)\&\,\:\.\!\?]+$/;
if((text.value == '') || (text.value == ' ')){
div.innerHTML="<b>Please enter your changes</b>";
text.focus();
return false;}
else if(text.value.match(lets)){
div.innerHTML="<b>Content updated</b>";
return true;}
else {
return false;}
}
Any help appreciated, thanks.
I'm not sure I fully follow but I would rejigger it so it was like this:
<?
if($_POST)
{
$tagbrief = mysql_real_escape_string($_POST['tag']);
mysql_query("UPDATE quackedup SET tagbrief='$tagbrief' WHERE id='1'");
header("Location: /path/to/script");
exit;
}
?>
<div id = "errormsg"> </div>
<?php
echo "<table border=\"0\" align=\"center\" cellpadding=\"2\" cellspacing=\"7\" style=\"font-family:Arial;font-size:11px\">";
echo "<tr>";
echo "<td> </td>";
echo "<td> </td>";
echo "</tr>";
echo "<tr>";
echo "<td><form name=\"confhome\" method=\"post\" action=\"\" onsubmit=\"return valText()\"><textarea name=\"tag\" cols=\"20\" rows=\"3\" id=\"tag\">$row[tagbrief]</textarea></td></tr>";
echo "<tr><td><input type=\"submit\" value=\"Edit\"></form></td></tr>";
echo "<tr></tr>";
echo "</table><br/>";
?>
Now, it only updates the field if you are actually posting the form, and the form contents are escaped for the database (to prevent SQL injection). Just change the /path/to/script to be the path/url you want to go to.
I think you just need to write
header("Location:/");
I hope this will help you
精彩评论