-1

我正在使用以下脚本在我的网站上处理一个 php 表单,当我在表单上点击提交时,下面的脚本应该将数据保存到数据库中。我遇到的问题是它没有将任何数据保存到 mysql 数据库中,但它也没有抛出任何错误,为什么它也没有!?.

    <link href='template/css/admin.css' rel='stylesheet' type='text/css'>
    <?php
    if (isset($_POST['customerID'])) {$customerID = $_POST['customerID'];}else {$customerID = '';}
    if (isset($_POST['datecreated'])) {$datecreated = $_POST['datecreated'];}else {$datecreated = '';}
    if (isset($_POST['name'])) {$name = $_POST['name'];}else {$name = '';}
    if (isset($_POST['facebookuserurl'])) {$facebookuserurl = $_POST['facebookuserurl'];}else {$facebookuserurl = '';}
    if (isset($_POST['tel'])) {$tel = $_POST['tel'];}else {$tel = '';}
    if (isset($_POST['email'])) {$email = $_POST['email'];}else {$email = '';}
    if (isset($_POST['address'])) {$address = $_POST['address'];}else {$address = '';}
    if (isset($_POST['itemforrepair'])) {$itemforrepair = $_POST['itemforrepair'];}else {$itemforrepair = '';}
    if (isset($_POST['repairdetails'])) {$repairdetails = $_POST['repairdetails'];}else {$repairdetails = '';}
    if (isset($_POST['otherdetails'])) {$otherdetails = $_POST['otherdetails'];}else {$otherdetails = '';}
    if (isset($_POST['itemnumber'])) {$itemnumber = $_POST['itemnumber'];}else {$itemnumber = '';}
    if (isset($_POST['pricequoted'])) {$pricequoted = $_POST['pricequoted'];}else {$pricequoted = '';}
    if (isset($_POST['partprice'])) {$partprice = $_POST['partprice'];}else {$partprice = '';}
    $profit = $pricequoted - $partprice;
    if (isset($_POST['datepartordered'])) {$datepartorderedpre = $_POST['datepartordered'];$date = DateTime::createFromFormat("D F d, Y", $datepartorderedpre);$datepartordered = date('Y-m-d',strtotime($datepartorderedpre));}else {$datepartorderedpre = ''; $datepartordered = '';}
    if (isset($_POST['jobstatus'])) {$jobstatus = $_POST['jobstatus'];}else {$jobstatus = '';}
    if (isset($_POST['dateofcompletion'])) {$dateofcompletionpre = $_POST['dateofcompletion'];$date = DateTime::createFromFormat("D F d, Y", $dateofcompletionpre);$dateofcompletion = date('Y-m-d',strtotime($dateofcompletionpre));}else {$dateofcompletionpre = ''; $dateofcompletion = '';}



    // Checks to see if the key value is set
    if (isset($_GET['key'])) {$key = $_GET['key'];} else {$key = '';}

    // Checks to see if the key value is valid to authenticate the user
    if ($key == 'mysecretkey'){
    // If the key value is correct the user is granted access

    include("connectmysqli.php"); 

    $stmt = $db->prepare("UPDATE `jobdetails` SET  itemnumber='$itemnumber',datecreated='$datecreated',customerID='$customerID',name='$name',facebookuserurl='$facebookuserurl',tel='$tel',email='$email',address='$address',itemforrepair='$itemforrepair',repairdetails='$repairdetails',otherdetails='$otherdetails',pricequoted='$pricequoted',partprice='$partprice',profit='$profit',datepartordered='$datepartordered',jobstatus='$jobstatus',dateofcompletion='$dateofcompletion' WHERE customerID='$customerID'");
    $stmt->execute(); 
    if (!$stmt)
        echo $db->error . "\n";
    $stmt->close();


    header('Location: jobsmanager.php?&key='.$key);
    }
    else {
    // Denies the user access if the key value isnt correct 
    echo '<h1>Access Denied !</h1>';}
    ?>
4

2 回答 2

1

您正在以错误的方式检查错误。

$stmt = $db->prepare("...");
if (!$stmt) trigger_error($db->error); // you need th check it right after prepare
$stmt->execute(); 

你还需要确保你可以看到 PHP 错误,至少这样

ini_set('display_errors',1);
error_reporting(E_ALL);

当然,您的查询容易受到 SQL 注入的影响。

于 2013-05-01T07:48:32.683 回答
0

好的,我现在已经解决了这个问题,我的主机帐户上的 PHP 5.2 不支持 DateTime::createFromFormat(),所以在控制面板中进行了一些调整后,我已经升级了它,它现在似乎可以按预期工作了。

于 2013-05-01T08:07:41.320 回答