0

所以,我将在下面发布代码。代码下面是我提出问题的地方。

if (!empty($_SESSION['username']) && !empty($_SESSION['password']))  
{  

$server=mysql_real_escape_string($_POST['server']);
$teamname=mysql_real_escape_string($_POST['teamname']);
$creator=$_SESSION['username'];
$verify = mysql_real_escape_string($_POST['verify']);
$date = date("F j, Y, g:i a");

if (!empty($teamname)) {
//  if ($verify == "wookie" ||
//  $verify == "Wookie" ||
//  $verify == "WOOKIE") 
//  {
        $sql="INSERT INTO rated_teams (server, name, creator, created, players, win, loss)
                            VALUES ('$server', '$teamname', '$creator','$date', '', '', '')";

        if (mysql_query($sql,$con))
          {
            echo "<p>Added ". $teamname . " on " . $server . " by " . $creator . " on " . $date ." <br /><a href='myprofile.php'>Return to Profile</a></p>";
          }
         else
          {
            echo $sql . "<br />";
            echo "<br /><h1>Error</h1>";  
            echo "<p><a href='myprofile.php'>Sorry, your team registration has failed. Please go back and try again.</a></p>
            <br />" . $teamname . " on " . $server . " by " . $creator . " on " . $date;
          }
    //} else { echo "That isn't how you spell Wookie!"; }
} else { echo "Team Name is empty, <a href='myprofile.php'>go back and give yourself a Team Name</a>"; }
} else { echo "You must be <a href='login.php'>logged in</a>!"; }

这个问题是“if (mysql_query($sql,$con))”这一行直接进入 ELSE。我假设问题出在我的 $sql 上,但我无法确定它在哪里。另一双眼睛真的很有帮助。非常感谢!

4

1 回答 1

0

要使用 跟踪错误mysql_query(),您应该使用mysql_error(). 这是一个示例,灵感来自PHPmysql_error()文档之一

    $sql="INSERT INTO rated_teams (server, name, creator, created, players, win, loss)
                        VALUES ('$server', '$teamname', '$creator','$date', '', '', '')";

    mysql_query($sql,$con);
     if (mysql_errno()) {
         $error = "MySQL error ".mysql_errno().": ".mysql_error()."\n<br>When executing:<br>\n$sql\n<br>";

        // Your stuff
        echo $sql . "<br />";
        echo "<br /><h1>Error</h1>";  
        echo "<p><a href='myprofile.php'>Sorry, your team registration has failed. Please go back and try again.</a></p>
        <br />" . $teamname . " on " . $server . " by " . $creator . " on " . $date;
      }
     else {
           echo "<p>Added ". $teamname . " on " . $server . " by " . $creator . " on " . $date ." <br /><a href='myprofile.php'>Return to Profile</a></p>"; 
      }

此外,您应该使用PDOmysqli,因为mysql_*自 PHP 5.x 起已弃用

于 2013-08-01T20:02:54.070 回答