Hi,

I want to create a table in Mysql but i receive an error.
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in C:\wamp\www\CreateTable\create.php on line 11
Table veriler_2 couldn't been created! :

i give you the whole lines to check it for me. I can not find anything.
$sql = "CREATE TABLE veriler_2
(id INT NOT NULL PRIMARY KEY AUTO_INCREMENT, ad VARCHAR (10), soyad VARCHAR (10))";
$res = mysqli_query($mysql, $sql);

Thanks

Dani AI

Generated

The mysqli warning means the first argument passed to mysqli_query was null instead of a mysqli link object — most often because the connection variable is wrong or the connection failed. ’s typo (using the wrong variable name) is a classic cause, and ’ prompt to check the connection is exactly the right next step.

A minimal, clear check (object-oriented style) will show whether the connection exists and surface any error returned by MySQL:

$mysqli = new mysqli('host','user','pass','database');
if ($mysqli->connect_errno) {
    printf("Connect failed: %s\n", $mysqli->connect_error);
    exit;
}

if (! $mysqli->query($create_sql)) {
    printf("Create failed: (%d) %s\n", $mysqli->errno, $mysqli->error);
}

Troubleshooting checklist and cautions:

  • Confirm the script uses the same connection variable everywhere and that it actually holds a mysqli object (not null or false).
  • Remove any HTML from the SQL string (e.g. stray <br /> tags copied from a page), as that will make the query invalid.
  • Make sure the connected DB user has CREATE TABLE privileges and the correct database is selected.
  • Be consistent: use either procedural or object-oriented mysqli calls to avoid confusion.
  • For development, enable mysqli exceptions/reports (mysqli_report) to get immediate, descriptive failures.

If the typo was the only problem, correcting the variable name fixes the warning; otherwise the connection-check and the query-error output above will reveal the real cause (failed connect, SQL error, or permissions).

Recommended Answers

All 3 Replies

resource mysql_query ( string $query [, resource $link_identifier ] )

$res = mysqli_query($mysql, $sql);
$res = mysql_query( $sql, $mysql );
Where $sql - query to mysql server
And $mysql - resource givven by mysql_connect().

done, i have forgotten to put "i" after "mysql"
$res = mysqli_query($mysqli, $sql);

Oh, sure my mistake. Did you get a link identifier by mysqli_connect?

mysqli mysqli_connect ([ string $host [, string $username [, string $passwd [, string $dbname [, int $port [, string $socket ]]]]]] )

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.