2017-09-18 35 views
0

我完成了我的標記工作,並開始編寫代碼,我寫了註冊這個簡單的代碼,但是當用戶點擊提交按鈕,他們看到的錯誤:PHP和MySQL插入錯誤:UCP目前無法處理此請求今天

This page isn’t working
ucp.ls-rp.ge is currently unable to handle this request.
HTTP ERROR 500

這怎麼解決? 任何形式的幫助將不勝感激,並提前致謝。

<? 
$host = 'localhost'; 
$user = 'lsrpge14_forum'; 
$pass = 'lsrpgeforum123.'; 
$db = 'lsrpge14_forum'; 
$mysqli = new mysqli($host,$user,$pass,$db) or die($mysqli->error); 
/* CREATE CHARACTER FUNCTIONS */ 
$sex = 0; 

function IsRPName($name, $max_underscores = 1) 
{ 
    $underscores = 0; 
    if ($name[0] < 'A' || $name[0] > 'Z') return false; 
    for($i = 1; $i < strlen($name); $i++) 
    { 
    if($name[$i] != '_' && ($name[$i] < 'A' || $name[$i] > 'Z') && ($name[$i] < 'a' || $name[$i] > 'z')) return false; 
    if(($name[$i] >= 'A' && $name[$i] <= 'Z') && ($name[$i - 1] != '_')) return false; 
    if($name[$i] == '_') 
    { 
    $underscores++; 
    if($underscores > $max_underscores || $i == strlen($name)) return false; 
    if($name[$i + 1] < 'A' || $name[$i + 1] > 'Z') return false; 
    } 
    } 
    if ($underscores == 0) return false; 
    return true; 
} 
function SendCharacterAplication($ownerid, $name, $sex, $explainmg, $explainpg, $charbio) 
{ 
    $sql = "INSERT INTO Aplicants (ownerid, charname, sex explainmg, explainpg, charbio) " . "VALUES ('$ownerid', '$name', '$sex', '$explainmg', '$explainpg', '$charbio')"; 
    if ($mysqli->query($sql)){ 
     $_SESSION['createcharerror'] = "<h2 style='color:green'>თქვენი პერსონაჟი წარმატებით შეიქმნა! დაელოდეთ ადმინისტრაციის პასუხს!</h2>"; 
     header("location: profile.php"); 

    } 

    header("location: index.php"); 
} 

/* CREATE CHARACTER CHECK VALUES */ 

if ($_SESSION['logged_in'] != 1) { 
    $_SESSION['createcharerror'] = "<h2 style='color:red'>პროფილის სანახავად გაიარეთ ავტორიზაცია!</h2>"; 
    header("location: index.php");  
} 

if ($_SESSION['countchars'] == 2) 
{ 
    $_SESSION['createcharerror'] = "<h2 style:'color:red'>თქვენ უკვე გაქვთ გაკეთებული 2 პერსონაჟი!</h2>"; 
    header("location: index.php"); 
} 

if(is_null($_POST['charname'])) 
{ 
    $_SESSION['createcharerror'] = "<h2 style:'color:red'>ჩაწერეთ პერსონაჟის სახელი!</h2>"; 
    header("location: index.php"); 
} 

if(!IsRPName($_POST['charname'])) 
{ 
    $_SESSION['createcharerror'] = "<h2 style='color:red;'>პერსონაჟის ნიკი არ არის სწორ ფორმატში Firstname_Lastname!</h2>"; 
    header("location: index.php"); 
} 

if(is_null($_POST['gender'])) 
{ 
    $_SESSION['createcharerror'] = "<h2 style='color:red;'>მონიშნეთ პერსონაჟის სქესი!</h2>"; 
    header("location: index.php"); 
} 

if($_POST['gender'] == 'male') 
{ 
    $sex = 1; 
} 
else 
{ 
    $sex = 2; 
} 

if(str_word_count($_POST['charbio']) < 70) 
{ 
    $_SESSION['createcharerror'] = "<h2 style='color:red'>პერსონაჟის ბიოგრაფია არ უნდა იყოს 70 სიტყვა-ზე ნაკლები!</h2>"; 
    header("location: index.php"); 
} 
else{ 
    SendCharacterAplication($_SESSION['masterid'], $_POST['charname'], $sex, $_POST['explainmg'], $_POST['explainpg'], $_POST['charbio']); 
} 
+0

你總是在500內部服務器錯誤上做的第一件事就是去檢查服務器的日誌文件。 – CBroe

回答

0

您可能會收到500錯誤,因爲服務器配置爲壓制SQL錯誤。如果您查看錯誤日誌或輸出正在運行的SQL並手動運行它,則可能會看到確切的錯誤。

您必須清理從用戶輸入傳遞給SQL的任何值,任何這些字段中使用撇號將導致SQL錯誤(或更糟糕的SQL注入)。

http://php.net/manual/en/mysqli.real-escape-string.php

也有可能你已經有了表名錯誤相比,現在的數據庫;應用程序應該有2個p

+0

感謝您的反饋。 –

相關問題