G.Jones G.Jones - 1 year ago 74
SQL Question

Whats wrong with my php to sql?

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');

I'm trying to link my website to sql database on x10 hosting. however it's not working?

Does anyone know why?

this is my php code i'm using

Answer Source

mysql_* is deprecated so try to use mysqli_* or 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 (?,?)");


                //  The argument may be one of four types:

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


                    $row_count= $stmt->affected_rows;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download