-1

I'm using XAMPP and practice for my upcoming exams. I am trying to create a new table in phpMyAdmin in a database. The code is:

<?php
$kapcsolat = mysql_connect("127.0.0.1","root","jelszo");    
mysql_select_db("gyakorlas", $kapcsolat);   
?>

<html>
<head>
<title>MySQL alapok</title>
</head>

<body>


<?php

$parancs = "CREATE TABLE uj_tabla ( 
(`id` BIGINT(20) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`nev` VARCHAR(100)   CHARACTER SET latin2 COLLATE latin2_hungarian_ci NOT NULL , 
`eletkor` INT(3) NOT NULL , 
INDEX (`nev`,`eletkor`)) 
ENGINE = InnoDB CHARSET=latin2 COLLATE latin2_hungarian_ci;";

mysql_query($parancs);
?>


</body>

</html>

<?php
mysql_close($kapcsolat);
?>

I get no error messages, and when i check phpMyAdmin, it doesn't create the table in my database:(

If anyone can help me out with this, i will be very grateful!

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
Wexutar
  • 1
  • 2
  • Don't use the deprecated and insecure `mysql_*`-functions. They have been deprecated since PHP 5.5 (in 2013) and were completely removed in PHP 7 (in 2015). Use MySQLi or PDO instead. – M. Eriksson May 06 '18 at 13:54
  • As a side note, `mysql_*` functions are deprecated. use `mysqli` (http://php.net/manual/en/book.mysqli.php) or, my preferred, `PDO` (http://php.net/manual/en/book.pdo.php) – Joas May 06 '18 at 13:55
  • Every time you use [the `mysql_`](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) database extension in new code **[this happens](https://media.giphy.com/media/kg9t6wEQKV7u8/giphy.gif)** it is deprecated and has been for years and is gone for ever in PHP7. If you are just learning PHP, spend your energies learning the `PDO` or `mysqli` database extensions and prepared statements. [Start here](http://php.net/manual/en/book.pdo.php) – RiggsFolly May 06 '18 at 13:55
  • _Note:_ PHPMyAdmin is simply a web based application for managing MySQL-databases. Unless you're modifying the core files of the PHPMyAdmin-application, your code has nothing to do with it. You're simply attempting to create a table in your MySQL-database. – M. Eriksson May 06 '18 at 13:55
  • Copy your query into PHPMyAdmin and try and execute it from there. Then you might see where it goes wrong (since that application have proper error handling, while you don't handle errors at all). – M. Eriksson May 06 '18 at 13:57
  • You are not processing errors. If you look for errors they will tell you what is wrong. HINT: `mysql_error()` – RiggsFolly May 06 '18 at 13:58

1 Answers1

1

First of all: mysql_* functions are deprecated. use mysqli_* or, my preferred: PDO.

You should use prepared stamements.

Actual answer:

You have an error in your SQL syntax. Try running the query in phpmyadmin to see whats wrong.

My guess is the second ( here:

CREATE TABLE uj_tabla ( 
( <-
Joas
  • 1,796
  • 1
  • 12
  • 25
  • 1
    I can confirm that the extra `(` is the error. Good catch! Demo: https://www.db-fiddle.com/f/kTcgzGnydtZqk7tFkLbjdU/0 – M. Eriksson May 06 '18 at 14:05