2014-10-28 117 views
0

我想從表單獲取數據並將其發送到我的數據庫,即phpmyadmin。代碼在本地正常工作,但在服務器上上傳時無法正常工作。 我使用本地主機作爲我的主機名連接到服務器上的數據庫,因爲我正在使用(Linux)Cpanel。代碼工作在本地但不能在服務器上工作

的代碼如下:

<?php 
if(isset($_POST['name'])) 
{ 

$seniorstar=mysql_connect("localhost","username","password"); 

    if(!$seniorstar) 
    { 
    die("Cannot Connect:".mysql_error()); 

    } 
    $name=$_POST['name']; 
    $testimony=$_POST['testimony']; 

    mysql_select_db("seniorstarsdb",$seniorstar); 

$sql="INSERT INTO testimonial (name,testimony) VALUES ('$name','$testimony')"; 

$result=mysql_query($sql,$seniorstar); 

mysql_close($seniorstar); 

    header('Location: thank-you.html'); 
    } 
    ?> 

正從形式牽強,但沒有被插入database.Please幫助即時通訊新的PHP 其得到執行的數據,直到謝謝頁面,但數據沒有被插入..

+5

您日誌中的一些錯誤?你做了一些SQL注入,你應該通知你。 – Stony 2014-10-28 08:59:42

+0

'mysql'壞習慣使用'mysqli'或更好'PDO'! – Rizier123 2014-10-28 09:00:30

+2

嘗試爲'connect()'添加'或die()'你創建了數據庫嗎?用戶名和密碼是否正確?是授予使用該數據庫的用戶(用於插入,刪除,更新...) – Yazan 2014-10-28 09:01:33

回答

0

嘗試與 mysql_connect("127.0.0.1","username","password");

你可以找到替代 mysql_connect("localhost","username","password"); 一些細節here

+0

沒有這沒有幫助它給了我一個訪問被拒絕的錯誤'username'@'127.0.0.1'(使用密碼:是) – user3818870 2014-10-28 09:28:25

相關問題