2017-10-19 118 views
0

我是一個完整的代碼nooby和幾個月前建立一個基本的網站之前,我的服務器主板死亡。我只是重建了服務器並複製了我備份到桌面的所有網站/數據庫代碼。據我所知,php代碼和數據庫設置之間的一切都是一樣的。PHP數據庫入口問題(Wampserver)

我的網站工作90%,除了當我去輸入數據。與預期的「成功創建新記錄」相反,我收到了「等待輸入」的錯誤。以下代碼的最底層上的相關if語句爲

有沒有人偶然有任何線索爲什麼輸入我的所有正確的數據後,它不會觸發「成功創建新記錄」?如果這意味着任何代碼工作正常,我的桌面上,除非我做了一件很愚蠢的我適當/ pasta'd一切複製到該服務器:(

<?php 

//Connect to database 

include('database.php'); 

    //grab user logged in for database insertion 

    $user_check = $_SESSION['login_user']; 

    $ses_sql = mysqli_query($dbcon,"select username from t_login where username = '$user_check' "); 

    $row = mysqli_fetch_array($ses_sql,MYSQLI_ASSOC); 

    $login_session = $row['username']; 

// Create DB Variable 

$login_session = $row['username']; 
$excercisename = (isset($_POST['excercisename']) ? $_POST['excercisename'] : null); 
$setcount = (isset($_POST['setcount']) ? $_POST['setcount'] : null); 
$rep1 = (isset($_POST['rep1']) ? $_POST['rep1'] : null); 
$rep2 = (isset($_POST['rep2']) ? $_POST['rep2'] : null); 
$rep3 = (isset($_POST['rep3']) ? $_POST['rep3'] : null); 
$rep4 = (isset($_POST['rep4']) ? $_POST['rep4'] : null); 
$rep5 = (isset($_POST['rep5']) ? $_POST['rep5'] : null); 
$rep6 = (isset($_POST['rep6']) ? $_POST['rep6'] : null); 
$rep7 = (isset($_POST['rep7']) ? $_POST['rep7'] : null); 
$rep8 = (isset($_POST['rep8']) ? $_POST['rep8'] : null); 
$weight1 = (isset($_POST['number1']) ? $_POST['number1'] : null); 
$weight2 = (isset($_POST['number2']) ? $_POST['number2'] : null); 
$weight3 = (isset($_POST['number3']) ? $_POST['number3'] : null); 
$weight4 = (isset($_POST['number4']) ? $_POST['number4'] : null); 
$weight5 = (isset($_POST['number5']) ? $_POST['number5'] : null); 
$weight6 = (isset($_POST['number6']) ? $_POST['number6'] : null); 
$weight7 = (isset($_POST['number7']) ? $_POST['number7'] : null); 
$weight8 = (isset($_POST['number8']) ? $_POST['number8'] : null); 
$cardio = (isset($_POST['cardio']) ? $_POST['cardio'] : null); 
$duration = (isset($_POST['duration']) ? $_POST['duration'] : null); 
$weight = (isset($_POST['weight']) ? $_POST['weight'] : null); 
$comments = (isset($_POST['comments']) ? $_POST['comments'] : null); 


//Execute the insert statement 
if(!empty($excercisename)){ 
$sql = "INSERT INTO t_workout (username, excercisename, setcount, set1reps, set2reps, set3reps, set4reps, set5reps, set6reps, set7reps, set8reps, set1weight, set2weight, set3weight, set4weight, set5weight, set6weight, set7weight, set8weight, cardio, cardio_dur, weight, comments) 
VALUES ('$login_session', '$excercisename', '$setcount', '$rep1', '$rep2', '$rep3', '$rep4', '$rep5', '$rep6', '$rep7', '$rep8', '$weight1', '$weight2', '$weight3', '$weight4', '$weight5', '$weight6', '$weight7', '$weight8', '$cardio', '$duration', '$weight', '$comments')"; 
} 

    if($weight > 0){ 
    $sql = "INSERT INTO t_workout (username, weight) 
    VALUES ('$login_session', '$weight')"; 
    } 

if(isset($sql)){ 
    if ($dbcon->query($sql) === TRUE) { 
    echo "New record created successfully"; 
} else { 
    echo "Waiting for entry."; 
} 
} 
$dbcon->close(); 
?> 
+0

如果設置你的體重則$ SQL重寫第一次插入。你可能想要運行兩個插入,而不是最後一個。 –

+0

是的,我記得那一部分。我忘了確切的原因,但在網站上我指定如果你想記錄你的個人體重,留下一切空白。但即使在我的網站上輸入只有重量返回一個「等待輸入」只有我能想到的是我的桌面上的Wampserver是3.0.6,而在我的服務器上它是3.1.0。這可能是偶然的問題嗎?但是我猶豫是否認爲這只是代碼正確?所有的表格/ php都在那裏:( –

+0

我很迷茫,我卸載了所有東西,在服務器上安裝了相同的Wampserver 3.0.6,放在桌面上的所有代碼中,以便它們應該是相同的。但是仍然會出現「正在等待輸入」的錯誤,而這個問題在桌面上並不存在。非常傷心lol。 –

回答

0

甜憐憫我對任何人都看着這個遺憾笑。

我解決了這個問題。代碼,一切都很好(當然,對於如何代碼業餘的)。

的問題是與wampserver,在我mysql.ini文件有一個分號註釋掉sql-mode。我只是刪除了分號,現在它可以工作了。我不知道ini文件中有什麼sql模式,但是它在ini文件中編輯過前面我比較了所有的wampserver配置文件。

; SQL模式= 「」