繁体   English   中英

表单停止提交到数据库

[英]Form stopped submitting into database

好吧,它以前工作过。...现在突然停止了。 我不确定为什么。 我添加的唯一内容是删除功能。此后它不再提交。 我可以通过= D删除条目

表单的php代码

 <?php

if (isset($_POST['submit'])){   

$con = mysql_connect("localhost", "", "");
if (!$con){
die("Cannot connect:" . mysql_error()); 
}

$Firstname = $_POST['Firstname'];
$Email = $_POST['Email'];
$Prayer = $_POST['Prayer'];



//if there is no input these messages will come up//    
if($Firstname==''){
echo "<script>alert('Please enter your name!')</script>";
exit();
}
if($Email==''){
echo "<script>alert('Please enter your email!')</script>";
exit(); 
}
if($Prayer==''){
echo "<script>alert('Please enter your prayer request!')</script>";
exit(); 
}


mysql_select_db("dxh6110",$con);

//if everything is good, information will be submitted to database
$sql = "INSERT INTO ChurchPrayer (Firstname, Email, Prayer) VALUES('$_POST[Firstname]','$_POST[Email]','$_POST[Prayer]')";



if(mysql_query($sql,$con)){

echo "<script>alert('Congratulations, You have successfully submitted your prayer requests. You will hear from us very soon!')</script>";


}

mysql_close($con);
}

?>

哦,我知道我应该使用准备好的语句来防止SQL注入...但是我不确定它到底是什么还是它的外观。 当我进一步进入学校项目时,我一定会在以后添加它们。 目前担心该功能。

不知道还需要添加什么...我将添加我的delete.php

<?php session_start(); //starting the session?>
<?php
//connecting to database
$con = mysql_connect("localhost","","","dxh6110");

//defining variable
$delete_id = $_GET['del'];
//command to remove input from SQL DB
$query = "delete from ChurchPrayer where id='$delete_id'";

if(mysql_query($con,$query)){

echo "<script>window.open('view_prayers.php?deleted=User has been deleted!','_self')</script>";

}



?>

我的管理员登录有效,当管理员登录时,将他们带到一个页面,该页面将允许他们查看条目并删除对数据库所做的条目。 当前有两个,但是当我尝试添加更多请求时...。它们不会进入数据库。 单击提交时没有错误。

首先, ("localhost","xxx","xxx","xxx")并没有您的想法。

mysql_connect()需要3个参数,而不是4个参数。第四个用于其他参数。 四个参数是与mysqli_connect()一起使用的参数,但是这些不同的MySQL API不会相互混合,因此,如果要使用mysql_函数,请不要使用该连接方法。

请教:

与您在其他问题中所做的一样:

$con = mysql_connect("localhost", "xxx", "xxx");
if (!$con){
die("Cannot connect:" . mysql_error()); 
}

mysql_select_db("your_db",$con);

然后这个if(mysql_query($con,$query)){连接到第二位。

另外, $_GET['del'] ?deleted=User $_GET['del']?deleted=User检查。 这是对我而言突出的两件事。

如果您的删除链接为?deleted=XXX ,则需要为?del=XXX XXX为例。

$_GET['del']需要与您方法中?parameter中的参数匹配。

即:如果view_prayers.php是您用来删除文件的文件, view_prayers.php?del=XXX


另外,如评论中所述,此方法是不安全的。

最好将mysqli与预处理语句一起使用,或者将PDO与预处理语句一起使用

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM