Unable to insert data into MySQL table

DarkEyeDragon

I've been trying to find a solution, I've found some similar issues but nothing seems to tell exactly how to fix it.

<?php
$connect = mysql_connect("localhost", "root", "test") or die("Couldn't connect!");
    $connectdb = mysql_select_db("test") or die("Couldn't connect to database!");
    echo "Connection established to Database.";

    $sql = "INSERT INTO hell (name, age) VALUES ('Josh',17)";

    if ($connect->query($sql) === TRUE) {
        echo "New record created successfully";
            } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
?>

this returns:

Connection established to Database.
Fatal error: Call to a member function query() on resource in C:\xampp\htdocs\php\connect-database.php on line 8

I'm using a slightly changed version from http://www.w3schools.com/php/php_mysql_insert.asp

Could someone provide me the documentation to fix this or fix the code?

momouu

Use:

if (mysql_query($sql) === TRUE) {

instead of

if ($connect->query($sql) === TRUE) {

And please use mysqli or PDO

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Unable to insert data in a MySQL table using PHP

From Dev

Unable to insert data into MySQL

From Dev

mySQL - Unable to Insert Values to Table

From Dev

Unable to insert data in MySQL database

From Dev

insert data form to mysql table

From Dev

insert form data into mysql table

From Dev

Unable to insert into table using PDO in mysql

From Dev

Unable to add data in to table mysql

From Dev

unable to insert data in table in web application?

From Dev

MySQL - Insert table data from another table

From Dev

MySQL - Insert table data from another table

From Dev

Unable to insert data from post array in MySQL

From Dev

Unable to insert data using mysql query in php

From Dev

IOS unable to insert data in to mysql database

From Dev

Unable to insert data into mysql database using AJAX

From Dev

Unable to insert data on mysql using php

From Dev

Mysql insert data on table a when insert in table b

From Dev

Proper way to insert data into table with php and mysql?

From Dev

Insert data instead of drop table into mysql

From Dev

Issue trying to insert data into a MySQL table with php

From Dev

Insert data inside a table in mysql stored procedure

From Dev

How to insert data in mysql table randomly

From Dev

How to insert data into mySQL table with java

From Dev

MySQL/PHP check if data is in database table, if not insert it

From Dev

Proper way to insert data into table with php and mysql?

From Dev

Insert XML Data to MySQL Table Using PHP

From Dev

Issue trying to insert data into a MySQL table with php

From Dev

How do I insert data into mysql table?

From Dev

MySQL insert into column data from another table

Related Related

HotTag

Archive