Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/370.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
数据库连接通过。php_Php_Javascript_Mysql_Html - Fatal编程技术网

数据库连接通过。php

数据库连接通过。php,php,javascript,mysql,html,Php,Javascript,Mysql,Html,我有一个网站包含一个html表单内的调查 在调查的最后有一个提交类型按钮,它“调用”一个.php文件,在该文件中数据被插入数据库。这一切都很好,但我需要做的是在填写调查的第一页后调用另一个php文件,以检查数据库中是否已经存在包含该信息的元组 但既然我已经有了一个提交类型的按钮,我就不能使用它了,对吗? 那么我该如何解决这个问题呢?有什么想法吗?您必须提供一些您尝试过的代码 你可以用 在将其放入数据库之前,您可以查看数据库中是否存在这些标记。。您可以使用简单的php实现这一点 $name = $

我有一个网站包含一个html表单内的调查

在调查的最后有一个提交类型按钮,它“调用”一个.php文件,在该文件中数据被插入数据库。这一切都很好,但我需要做的是在填写调查的第一页后调用另一个php文件,以检查数据库中是否已经存在包含该信息的元组

但既然我已经有了一个提交类型的按钮,我就不能使用它了,对吗?
那么我该如何解决这个问题呢?有什么想法吗?

您必须提供一些您尝试过的代码

你可以用


在将其放入数据库之前,您可以查看数据库中是否存在这些标记。。您可以使用简单的php实现这一点

$name = $_POST['name']; // save the name from the form to the var.
$last_name = $_POST['lastname']; // save the last name from the form to the var.
$sql = mysql_query("SELECT * FROM `data` WHERE `name` = '".$name."' AND `last_name` = '".$last_name."' "); // look in the database if there is alreddy a record with that name.
if(mysql_num_rows($sql) > 0){ // if its bigger than 0 it exists
  // give an error back to the user that they alreddy exist
}
else{ // if not exists
  // user your code that puts it to the database
}

你能不能更详细一点,并尽可能展示你迄今为止所做的尝试?很难为你所知甚少的问题提供解决方案。你不应该在调查开始前检查,这样用户就不必填写两次吗?好的,检查下面我试图详细说明的注释:)第一页是“开始”,也就是说,用户填写自己的信息。我已经有了一个.php文件,它可以从数据库中的元组中提取所有相关信息。我需要做的是找到一种方法,在用户尝试继续下一步按钮时“调用”该文件。例如,使用一个具有操作“submit.php”的submit按钮最后,我还有一个check.php,我想调用它。我首先尝试对html输入类型使用onclick javascript,并在javascript方法中调用.php文件,但由于javascript是客户端和php服务器端的,所以这当然不起作用。n我在考虑ajax,但认为如果有更简单的方法,就没有必要使用那种看起来过于苛刻的性能?我在想,如果一个普通的html“输入”类型按钮有一些类似表单提交类型的操作,你也可以使用jQuery的插件来验证字段,这比调用新页面更方便用户。。有了这个插件,用户可以在输入或按下next时看到他做错了什么。
$name = $_POST['name']; // save the name from the form to the var.
$last_name = $_POST['lastname']; // save the last name from the form to the var.
$sql = mysql_query("SELECT * FROM `data` WHERE `name` = '".$name."' AND `last_name` = '".$last_name."' "); // look in the database if there is alreddy a record with that name.
if(mysql_num_rows($sql) > 0){ // if its bigger than 0 it exists
  // give an error back to the user that they alreddy exist
}
else{ // if not exists
  // user your code that puts it to the database
}