2012-08-25 66 views
0

我沒有任何其他選項,但再次詢問這裏......問題在過去的5個小時裏讓我失望。我得到了那個調用javascript函數的按鈕,然後javascript打開另一個php頁面,並插入到MySQL數據庫中。Web服務器意外退出,重新啓動新實例

HTML代碼:

<ul> 
<li id="ConfirmButton" name="Insert" onclick="GetAllIDs()"><a>Potvrdi</a></li> 
</ul> 

Javascript代碼:

var request_type; 
var browser = navigator.appName; 
if (browser == "Microsoft Internet Explorer") { 
request_type = new ActiveXObject("Microsoft.XMLHTTP"); 
} 
else { 
request_type = new XMLHttpRequest(); 
} 

var http = request_type; 
http.open('get', 'insert.php?MatchID='+MatchID+'&TipID='+TipID+'&UserID=' + 1,true); 
http.send(null); 

PHP代碼:

include('config.php'); 
$matchID = $_GET['MatchID']; 
$tipID = $_GET['TipID']; 
$userID = $_GET['UserID']; 

// Escape User Input to help prevent SQL Injection 
$MatchID = mysql_real_escape_string($matchID); 
$TipID = mysql_real_escape_string($tipID); 
$UserID = mysql_real_escape_string($userID); 

$insertTicket_sql = "INSERT INTO 
betslips(DateTime,MatchID,TipID,UserID) 
VALUES(".$MatchID.",".$TipID.",'".date("Y-m-d H:i:s")."',".$UserID.")"; 
$insertTick= mysql_query($insertTicket_sql) or die(mysql_error()); 

所以之後我運行此代碼,我使用斷點我在我的PHP見代碼我通過表格正常發送的所有參數,它都在那裏,但是當我到達代碼$insertTick時,我得到錯誤 Web服務器意外退出,重新啓動新實例。

有沒有人見過這個問題,我該如何處理?

感謝

回答

0

有沒有人見過這個問題嗎?

不是我,我不使用mysql_ *函數。

您的INSERT查詢參數和值不匹配。

所以IVE移植您的示例代碼PDO也許它的一些利益:

<?php 
//PDO Connect 
try{ 
    $con = new PDO('mysql:host=127.0.0.1;dbname=yourDB','root','password'); 
    $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); 
    $con->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); 
    $con->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE,PDO::FETCH_ASSOC); 
}catch (Exception $e){ 
    die('Cannot connect to database. Details:'.$e->getMessage()); 
} 

//Check that the variables are set 
if(isset($_GET['MatchID']) && isset($_GET['TipID']) && isset($_GET['UserID'])){ 

    //Prepare your query 
    $query = $con->prepare("INSERT INTO betslips (DateTime,MatchID,TipID,UserID) 
          VALUES ('".date("Y-m-d H:i:s")."', :matchID, :tipID, :userID)"); 

    //Bind your values with the placeholders 
    $query->bindParam(":matchID", $_GET['MatchID']); 
    $query->bindParam(":tipID", $_GET['TipID']); 
    $query->bindParam(":userID", $_GET['UserID']); 

    //Execute 
    $query->execute(); 
    die('Success!'); 
}else{ 
    die('Error: Parameter not set.'); 
} 
?> 
+0

謝謝你這麼多隊友......我只是不明白的錯誤是多麼愚蠢我做了......我猜它不冷靜坐下來做整天的編程 – Veljko89