總網頁瀏覽量

2015年8月25日 星期二

[網站] PHP連接SQL



<?php
        echo $_POST['name']."<br>";
        echo $_POST['email']."<br>";
        echo $_POST['pass']."<br>";
        $dbhost = '127.0.0.1';
        $dbuser = $_POST['name'];//'root';   以登入root
        $dbpass = $_POST['pass'];  //123456   密碼 隨便打 自己設定的
        $dbname = 'test0921_database';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error with MySQL connection');
       
        mysql_query("SET NAMES 'utf8'");
        mysql_select_db($dbname);
        $sql = "SELECT * FROM test0921.test0921_database";
        $result = mysql_query($sql,$conn) or die(" MySQL query error: " . mysql_error());
        $show=mysql_fetch_row($result);
        //print_r($show);
       
        if (mysqli_connect_errno()){
                echo "Failed to connect to MySQL: " . mysqli_connect_error();
                //you need to exit the script, if there is an error
                exit();
        }
       
        $insert_query = "INSERT INTO test0921.test0921_database(ID,name,telephone,information)
VALUES ('985','ppp','132','ghgh')";
        $result2 = mysql_query($insert_query,$conn) or die(" Insert data fail: " . mysql_error());
        $show2=mysql_fetch_row($result2);

        while($row = mysql_fetch_array($result)){
echo "ID: ".$row['ID']." Name: ".$row['name']." Telephone: ".$row[telephone]." Information: ".$row[information].'<br>';
        }
?>

沒有留言:

張貼留言