我正在尝试使用php脚本

时间:2017-10-31 02:07:56

标签: php html mysql lamp

我尝试了几个代码脚本,我发现在使用php从html表单插入mysql数据库时。我使用了以下代码,我得到的只是一个空白页面。我试过的最新版本的脚本来自另一个问题。代码如下。我在ubuntu上使用灯服务器。

 <?php

define('DB_NAME', 'DBNAME');
define('DB_USER', 'root');
define('DB_PASS', 'toor');
define('DB_HOST', 'localhost');

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);

if (!$link) {
    dir('There was a problem when trying to connect to the host. Please contact Tech Support. Error: ' . mysql_error());
}

$db_selected = mysql_select_db(DB_NAME, $link);

if (!$link) {
    dir('There was a problem when trying to connect to the database. Please contact Tech Support. Error: ' . mysql_error());
}

$date = $_POST['date'];
$charge = $_POST['charge'];
$payment = $_POST['payment'];
$client_no = $_POST['client_no'];
$client_name = $_POST['client_name'];
$check_no = $_POST['check_no'];
$check = $_POST['check'];
$cash = $_POST['cash'];
$notes = $_POST['notes'];
$staff_initials = $_POST['staff_initials'];

$sql = "INSERT INTO payments (date, charge, payment, client_no, client_name, check_no, check_amonia, cash, notes, staff_initials) VALUES ('$date', '$charge', '$payment', '$client_no', '$client_name', '$check_no', '$check', '$cash', '$notes', '$staff_initials')";

if (!mysql_query($sql)) {
    die('Error: ' . mysql_error());
}

?>

当我提交html页面并登陆此页面时,它是空白的,没有任何内容发送到mysql数据库。

0 个答案:

没有答案