使用php将数据插入mysql数据库时出现的问题

使用php将数据插入mysql数据库时出现的问题,php,mysql,Php,Mysql,我已经使用php和jquery创建了注册表表单。我需要将输入详细信息存储到sql数据库 我创建了config.php并包含在index.php和submit.php文件中 输入详细信息后,显示输入成功,但仍然没有存储在数据库中,请问config.php代码中的错误是什么,有人可以帮助我吗 这是我的config.php: <?php $mysql_hostname = "localhost"; $mysql_user = "root"; $mysql_password = "

我已经使用php和jquery创建了注册表表单。我需要将输入详细信息存储到sql数据库

我创建了config.php并包含在index.php和submit.php文件中

输入详细信息后,显示输入成功,但仍然没有存储在数据库中,请问config.php代码中的错误是什么,有人可以帮助我吗

这是我的config.php:

    <?php
    $mysql_hostname = "localhost";
$mysql_user = "root";
$mysql_password = "";
$mysql_database = "crop";
$prefix = "";
$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) die('Could not connect: ' . mysql_error());
mysql_select_db($mysql_database, $bd) or die('Could not connect: ' . mysql_error());
    ?>
这是code_exec.php:

 <?php
    session_start();
    include('config.php');
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $email=$_POST['email'];
    $pass=$_POST['pass'];
    $sex_select=$_POST['sex_select'];
    $month=$_POST['month'];
    $day=$_POST['day'];
    $year=$_POST['year'];

    $result = mysql_query("INSERT INTO crop(fname, lname, email, pass,`sex_select`, month,day,year)  
VALUES ('$fname', '$lname', '$email', '$pass','$sex_select', '$month','$day','$year')");

if (!$result) {
    die('Invalid query: ' . mysql_error());
}
    ?>
这是我的工作

代码\u exec:

<?php
include 'functions.php';
include 'config.php';
session_start();
$fname=$_POST['fname'];
$lname=$_POST['lname'];
$email=$_POST['email'];
$pass=$_POST['pass'];
$sex_select=$_POST['sex_select'];
$month=$_POST['month'];
$day=$_POST['day'];
$year=$_POST['year'];

$result = mysql_query("INSERT INTO crop(fname, lname, email, pass,`sex_select`, month,day,year)  
VALUES ('$fname', '$lname', '$email', '$pass','$sex_select', '$month','$day','$year')");

if (!$result) {
 die(msg(0,"wrong query"));
}
?>
在functions.php中添加消息:

function msg($status,$txt)
{
return '{"status":'.$status.',"txt":"'.$txt.'"}';
}  
如果这不起作用,请检查脚本将返回什么错误,可能是您没有选择正确的数据库或表名


警告:此代码不应用于生产,您应该开始使用更安全的mysqli或PDO函数,并且应该使用准备好的语句、密码哈希等。

我猜在submit.php中进行验证后?尝试此链接可能会帮助您。。。从你的问题我有一种感觉,你没有写这个代码:把这个问题投给地狱。他之前被彻底检查过,甚至懒得回答问题。学习很好,但从基本的登录/表单代码开始,而不是调用10个php脚本。在您了解何时以及如何包含不同的脚本之前。顺便说一句,删除了错误报告0。在firefox中,您可以使用firebug、chrome开发工具、IE开发工具。我猜db未被选中,如果您的db与表名相同,请尝试更改查询以插入到crop.crop…第一个crop是数据库名,第二个裁剪是表名。@halfer注释不错。我补充了警告。他应该修改的东西很少,所以我没有时间对代码进行所有修改,以确保代码的安全性。
function msg($status,$txt)
{
return '{"status":'.$status.',"txt":"'.$txt.'"}';
}