Below is whole code with cencored username, password and databasename.

<?php
	$connection = mysql_connect("localhost", "*********", "********");
	mysql_select_db("********", $connection);

$request = "CREATE TABLE persons (id TEXT, type TEXT, name TEXT, name2 TEXT, group TEXT, movie TEXT)";
if(!mysql_query($request, $connection)) {
	echo "LUONTI EPÄONNISTUI!<br />";
}

$request = "INSERT INTO persons (id, type, name, name2, group, movie) VALUES ('1', 'group', 'test_group', 'none', 'none', 'none')";
if(!mysql_query($request, $connection)) {
	echo "LUONTI EPÄONNISTUI!<br />";
}

$request = "INSERT INTO persons (id, type, name, name2, group, movie) VALUES ('2', 'person', 'esa järvi', 'none', 'test_group', 'none')";
if(!mysql_query($request, $connection)) {
	echo "LUONTI EPÄONNISTUI!<br />";
}

$request = "INSERT INTO persons (id, type, name, name2, group, movie) VALUES ('3', 'person', 'testi mikko', 'none', 'test_group', 'none')";
if(!mysql_query($request, $connection)) {
	echo "LUONTI EPÄONNISTUI!<br />";
}

mysql_close($connection);
?>

It doesn't give any errors it just prints "LUONTI EPÄONNISTUI" on every single creating or inserting time.

    Expand your error checking:

    $connection = mysql_connect("localhost", "*********", "********");
        or die('mysql_connect() failed: ' . mysql_error());
    mysql_select_db("********", $connection);
        or die('mysql_select_db() failed: ' . mysql_error($connection));
    $request = "CREATE TABLE persons (id TEXT, type TEXT, name TEXT, name2 TEXT, group TEXT, movie TEXT)";
    if (!mysql_query($request, $connection)) {
        die('mysql_query() failed: ' . mysql_error($connection));
    }
    // etc.

      I already did that and it gives somekind of syntax error at line 1. For example when I try to create table it gives:

      LUONTI EPÄONNISTUI!
      Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'group TEXT, movie TEXT)' at line 1

      I just don't get it.

        I think I see the problem now. Try putting backticks ( ` ) around "group" (it's a reserved word).

        BTW, that would have been useful information to include in your first post. 🙂

        Also, the line number given in a MySQL error message refers to the line number of the query, not of the scipt. And usually the error can be found at or just before the quoted portion of the query.

          if adding ``doesn't work, try it by creating a Primary key.

          $request = "CREATE TABLE persons (id TEXT, type TEXT, name TEXT, name2 TEXT, group TEXT, movie TEXT, PRIMARY KEY (id))";

            I changed group to p_group and it works perfectly. Thank you for your help.

              Write a Reply...