0

Im haveing a problem with this code:

<?php    
include 'connect.php';
$SQL = "INSERT into users(username, password, email,) 
VALUES ('dado','123','neki@gmail.com',)";
mysql_query($SQL) or die("could not register");
?>

My connect.php looks like this:

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'igra';
?>

When I try to exectue it, Im getting error. Tryed testing connection with

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = 'igra';
$connect = mysql_connect($dbhost, $dbuser, $dbpass)
or die("Unable to connect to dbhost");
mysql_select_db($dbname) 
or die("Could not connect to db");
$test_query = "SHOW TABLES FROM $dbname";
$result = mysql_query($test_query);
$tblCnt = 0;
while($tbl = mysql_fetch_array($result)) {
$tblCnt++;
#echo $tbl[0]."<br />\n";
}
if (!$tblCnt){
echo "There are no tables<br />\n";
} else {
echo "There are $tblCnt tables<br />\n";
}
?>   

and it return msg: There are 4 tables. Which means connect.php is properly set. Now I tryed to run code into MySQL Admin program itself with "INSERT into" query, and it worked. So, everything seems to work fine separatly, but when put together, it wont work. Can somebody point me to misstake Im makeing please?

Verzus
  • 9
  • 4
  • it's 2017, mysql_* functions are long dead ! – Pedro Lobito Mar 14 '17 at 01:50
  • Do **not** use `mysql_` anymore, it doesn't support prepared statements so you'll always be open for `sql injection`! Thereby are the `mysql_` functions removed from the latest version. Use `PDO` *or* `mysqli_` instead. – Nytrix Mar 14 '17 at 01:51
  • Thank you for your advice. However, my question havent been resolved.. If it is writen properly, why is not working? Someone stated (and it is deleted, wtf) that I shouldnt put commas, but shouldnt values be sepparated with commas? "INSERT INTO table_name (column1, column2, column3, ...) VALUES (value1, value2, value3, ...); " – Verzus Mar 14 '17 at 05:22

0 Answers0