Trying to create table and insert data, errors for everything after connection (PHP)
Posted by:
A T
Date: October 28, 2017 10:59AM
I have the following code in a .php file for a web page I set up. The connect seems so have worked fine but the CREATEs after it and all are printing the error messages.
<?php
$servername = "db4free.net";
$username = "name";
$password = "pass";
$dbcon = new mysqli($servername, $username, $password);
if ($dbcon->connect-error)
{
die("Connection failed: " . $dbcon->connect_error);
}
else { echo "Connected"; }
// Works up to here, printing the "connected" message.
$sql = "CREATE DATABASE dbmpname";
if ($dbcon->query($sql) === TRUE) {
echo "Database created successfully";
}
else
{
echo "Error creating database: " . $dbcon->error;
}
$sql2 = "CREATE TABLE test1 (id INT)";
if ($dbcon->query($sql2) === TRUE)
{
echo "Table created successfully";
}
else
{
echo "Error creating table: " . $dbcon->error;
}
$sql3 = "INSERT INTO test1 (id) VALUES (50)";
if ($dbcon->query($sql3) === TRUE)
{
echo "New record created successfully";
}
else
{
echo "Error: " . $sql3 . "<br>" . $dbcon->error;
}
?>
Subject
Written By
Posted
Trying to create table and insert data, errors for everything after connection (PHP)
October 28, 2017 10:59AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.