提交表单时返回呼叫页面 [英] Return to a calling page when submitting a form
本文介绍了提交表单时返回呼叫页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在提交以下表格
I am submitting a form as below
<form action="myfile.php" name ="formSubmit" method="POST" enctype="multipart/form-data">
<label>Product Code</label>
<input type="text" name="productCode"><br>
<label>Product Image</label>
<input type="file" name="myfile1" />
<input type="submit" value="Add Product">
</form>
'myfile.php'包含以下行:
the 'myfile.php' contains the following line:
<?php
// connect to database
$dbname = mysql_connect("************", "user","password")or die('Cannot select database');
mysql_select_db("mydb")or die('Cannot select database');
// if unable to connect display error
if (!$dbname ) {
echo "Unable to establish connection to database server";
exit;
}
if (!mysql_select_db('mydb', $dbname )) {
echo "Unable to connect to database";
exit;
}
if (($_FILES["myfile1"]["type"] == "image/gif")
|| ($_FILES["myfile1"]["type"] == "image/jpeg") // only allow: .gif & .jpeg
&& ($_FILES["myfile1"]["size"] < 2000000)) // limitation of size: 2MB
{
if ($_FILES["myfile1"]["error"] > 0) // error occurs during uploading
{
echo "Return Code: " . $_FILES["myfile1"]["error"] . "<br />";
} //end if
else
{
// show the basic information of uploaded files
echo "Upload: " . $_FILES["myfile1"]["name"] . "<br />";
echo "Type: " . $_FILES["myfile1"]["type"] . "<br />";
echo "Size: " . ($_FILES["myfile1"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["myfile1"]["tmp_name"] . "<br />";
// check whether the file exists in the target folder
if (file_exists("upload/" . $_FILES["myfile1"]["name"])){
echo $_FILES["myfile1"]["name"] . " already exists. ";
} //end if
// do the uploading: moving the file from temporary folder to the target folder
else
{
move_uploaded_file($_FILES["myfile1"]["tmp_name"],
"upload/" . $_FILES["myfile1"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["myfile1"]["name"] . "<br />";
//store filename in the database together with the product code
$name = $_FILES["myfile1"]["name"];
$result = mysql_query("insert into images values ('$productCode','$name')");
echo "Product " . $productCode . " successfully added to the database." . "<br />" ;
} //end else
} //end else
} // end if
else
{
echo "Invalid file";
}
echo "finish";
header("Location: admin.php");
//header("Location: ".htmlentities($_SERVER['HTTP_REFERER']));
//header("Location: ".$_POST["formSubmit"]);
?>
我的问题是,一旦'myfile.php'中的所有内容成功执行,header命令就不起作用了。有什么想法吗?
My problem that once all the contents in 'myfile.php' are successfully executed the header command is not working. Any ideas please?
推荐答案
dbname = mysql_connect( ************, user,password)或 die('不能 选择 database');
mysql_select_db(mydb)或 die('不能 选择 database');
< span class =code-summarycomment> // if 无法 to connect display error
if (!
dbname = mysql_connect("************", "user","password")or die('Cannot select database'); mysql_select_db("mydb")or die('Cannot select database'); // if unable to connect display error if (!
dbname < span class =code-summarycomment>) {
echo 无法 to 建立 连接 数据库 server;
退出;
}
< span class =code-summarycomment>
if (!mysql_select_db('mydb',
dbname ) { echo "Unable to establish connection to database server"; exit; } if (!mysql_select_db('mydb',
dbname )) {
echo 无法 < span class =code-summarycomment> connect to database;
退出;
}
< span class =code-su mmarycomment> if ((
dbname )) { echo "Unable to connect to database"; exit; } if ((
这篇关于提交表单时返回呼叫页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文