试图从mysql实现mysqli。 Mysqli不工作

I am trying to switch over from mysql to mysqli as I have been getting a large amount of grief for using mysql to start. I have been looking at examples and thought that I had it right. However, I don't. When I try to add a punch, it doesn't add. I just get a white screen. No error message or the redirect that I request after the punch is added. I have edited the file to hide some sensitive data, but nothing neccessary to trouble shoot. I have looked at the examples multiple times and I can not seem to figure out what is wrong. The punches are added just fine when using mysql. If any one can enlighten me on how to fix this, I would greatly appreciate it. Thank you!

<head>
    <title>Process Punch</title>
    <body bgcolor="#9966FF">
    <link rel="icon" type="image/ico" href="favicon path"/>
</head>

<?php

define('DB_NAME', 'dbname');
define('DB_USER', 'dbuser');
define('DB_PASSWORD', 'dbpass');
define('DB_HOST', 'dhbost');

$link = new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);

if ($link->connect_errno > 0){
    die('Could not connect: ' .$link->connect_error);
}

$userid_value = $_POST['userid'];
$punchtype_value = $_POST['punchtype'];
$group_value = $_POST['group'];
$dept_value = $_POST['dept'];
$notes_value = $_POST['notes'];
$table = "tc_".$userid_value;
$unixtime = time();
$unixtime = $unixtime + 3600;
$date_value = date('m/d/Y h:i:s A', $unixtime);
$checkusersql = "SELECT * FROM tc_users WHERE userid = '$userid_value'";
$usercheck = $link->query($checkusersql);
if ($usercheck->num_rows) == 0) {
    echo "Sorry, " . $userid_value . " is not a valid user ID. Please try again.";
}else {
    $sql = "INSERT INTO $table (time, punchtype, groupname, dept, notes) VALUES ('$date_value','$punchtype_value', '$group_value', '$dept_value', '$notes_value')";
    $link->query($sql);
}
header( 'Location: punch path');
$link->close();
?>

Two things:

if ($usercheck->num_rows) == 0)
                        ^-- this one should be removed

has one bracket too many.

Use ($usercheck->num_rows == 0)

As for your date/time issue; you're using m/d/Y h:i:s instead of date("Y-m-d H:i:s")

MySQL is expecting a numeric representation of the format 2014-07-07 19:30:13 as an example.

So do date("Y-m-d H:i:s A") or date("Y-m-d H:i:s") which is why you're getting all zeros.


Use either H or h: (as per the manual)

h - 12-hour format of an hour with leading zeros 01 through 12
H - 24-hour format of an hour with leading zeros 00 through 23

You could leave it the way it is and set your time column to VARCHAR but that would defeat the purpose.

I believe your script is failing on the mysqli query, but you don't have any way of knowing because there is not error reporting in place. Try this and see what it shows.

$checkusersql = "SELECT * FROM tc_users WHERE userid = '$userid_value'";
if (!$usercheck = $link->query($checkusersql)) {
printf("Error: %s
", $usercheck->error);
}
if ($usercheck->num_rows == 0) {
    echo "Sorry, " . $userid_value . " is not a valid user ID. Please try again.";
}else {
    $sql = "INSERT INTO $table (time, punchtype, groupname, dept, notes) VALUES ('$date_value','$punchtype_value', '$group_value', '$dept_value', '$notes_value')";
    if (!$link->query($sql)) {
    printf("Error: %s
", $link->error);
   }
}