2016-09-26 52 views
-3

我的PHP到SQL最新怎么了?

<?php 
 
phpinfo 
 
php $connect = mysql_connect(“localhost:3306”, “thebigsh_formdata”, “GaryJones123”); 
 
if (!connect) { die('Connection Failed: ' . mysql_error()); 
 
{ mysql_select_db(“database_name”, $connect); 
 

 
$user_info = “INSERT INTO table_name (username, email) VALUES ('$_POST[username]', '$_POST[email]')”; 
 
if (!mysql_query($user_info, $connect)) { die('Error: ' . mysql_error()); 
 
} echo “Your information was added to the database.”; mysql_close($connect); 
 
    
 
header('Location: http://thebigsheep.x10.bz/page2.html'); 
 
?>

我想我的网站链接到SQL数据库上X10主机。但它不工作?

有谁知道为什么?

这是我的PHP代码我使用

+2

我似乎已经忘记了我在家里的魔法水晶球。有人可以借我一个吗?但现在认真,你需要发布更多的信息。 – Andrew

+0

<?php phpinfo php $ connect = mysql_connect(“localhost:3306”,“thebigsh_formdata”,“GaryJones123”);如果(!connect){die('Connection Failed:'。mysql_error()); {mysql_select_db(“database_name”,$ connect); ('$ _POST [用户名]','$ _POST [email]')“;或者用户名和密码。 (!mysql_query($ user_info,$ connect)){die('Error:'。mysql_error()); “您的信息已添加到数据库中。”; mysql_close($连接); header('Location:http://thebigsheep.x10.bz/page2.html'); ?> –

+0

你的代码是什么? –

回答

0

mysql_ *已被弃用所以尽量使用mysqli_ *或PDO

refer the quickstart for connection creation

Warning mysql_query, mysql_fetch_array,mysql_connect etc.. extensions were deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.

 $servername = "localhost"; //host name 

     $username = "thebigsh_formdata"; //username 

     $password = "GaryJones123"; //password 

     $mysql_database = "database_name"; //database name 

    //mysqli prepared statement 

     $conn = mysqli_connect($servername, $username, $password) or die("Connection failed: " . mysqli_connect_error()); 

     mysqli_select_db($conn,$mysql_database) or die("Opps some thing went wrong"); 

    $stmt = $conn->prepare("INSERT INTO table_name (username, email) VALUES (?,?)"); 

        $stmt->bind_param('ss',$_POST[username],$_POST[email]); 

       // The argument may be one of four types: 

       // i - integer 
       // d - double 
       // s - string 
       // b - BLOB 
        //change it by respectively 

        $stmt->execute(); 

        $row_count= $stmt->affected_rows; 
        $stmt->close(); 
        $conn->close(); 
+0

很多谢谢生病尝试,现在 –

+0

它现在出现这个错误? 警告:mysqli_connect():(28000/1045):拒绝访问用户'thebigsh_formdat'@'localhost'(使用密码:YES),位于第24行的/home/thebigsh/public_html/database.php中 连接失败:访问被拒绝用户'thebigsh_formdat'@'localhost'(使用密码:YES) –

+0

可能是用户名或密码错误@ G.Jones – JYoThI