I am attempting to create a table in sql using a php script but I am receiving this message.
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Createtable\index.php on line 7
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Createtable\index.php on line 9
learning as I go (using Build your own database driven web site using php & mysql) so not solid on what a 1st parameter is - and - the database is not created yet so I cannot select from it.
This is the script I used:
<?php
$sql = ‘CREATE TABLE joke(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
joketext TEXT,
jokedate DATE NOT NULL
) DEFAULT CHARACTER SET utf8’;
if (!mysqli_query($link, $sql))
{
$output = 'Error creating joke table: ’ . mysqli_error($link);
include ‘output.html.php’;
exit();
}
$output = ‘Joke table successfuly created.’;
include ‘output.html.php’;
?>
And - this is the error received:
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Createtable\index.php on line 7
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\Createtable\index.php on line 9
this is my point…so what I need is the command or program to create a database in sql with php. I have phpmyadmin but I would like to know how to use php program to do this.