0

Great, now I can 'insert' into the database, but in phpmyadmin the fields are white, without content... This is the php code:

$name = $_POST["name"];
$institution = $_POST["institution"];
$email = $_POST["email"];
$country = $_POST["country"];
$hcp = $_POST["hcp"];
$texto = $_POST["texto"];
$state = $_POST["state"];
$license = $_POST["license"];

$consulta = ("INSERT INTO `1264`(`name`,`institution`,`email`,`country`,`hcp`,`texto`,`state`,`license`) VALUES ('$name','$institution','$email','$country','$hcp','$texto','$state','$license');");

mysql_query($consulta,$connection) or die("You cannot register. Try it later, please.");

Does anybody know why?

  • you don't need to give the id – SuperDJ May 27 '14 at 09:01
  • 2
    Remove extra `,` after `license` – Krish R May 27 '14 at 09:01
  • 1
    When this will work, it sill be a huge security gap. You should read about prepared statements at least, and sanitize user input as much as possible if not already done. – Laurent S. May 27 '14 at 09:03
  • Removed...but it still doesn't work... – user3665872 May 27 '14 at 09:06
  • add `echo $consulta`; between the two lines and please show us the output of that line - that will show the text that gets sent to the db server. – fvu May 27 '14 at 09:08
  • What happened to the extra commas in the question? That was the problem, now the answers make no sense. – Barmar May 27 '14 at 09:18
  • This was the old code: $consulta = ("INSERT INTO `1264`(`name`,`institution`,`email`,`country`,`hcp`,`texto`,`state`,`license`,) VALUES ('$name','$institution','$email','$country','$hcp','$texto','$state','$license',);"); – user3665872 May 27 '14 at 09:21
  • Please be aware that the mysql extension (supplying the `mysql_` functions) has been deprecated since 2012, in favor of the mysqli and PDO extensions. It's use is highly discouraged. See http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php – Oldskool May 27 '14 at 13:05

6 Answers6

1

Try this:

$consulta = ("INSERT INTO `1264`(`id`,`name`,`institution`,`email`,`country`,`hcp`,`texto`,`state`,`license`) VALUES (NULL, '$institution','$email','$country','$hcp','$texto','$state','$license');");

ie, remove the extra comma at the last

Rahul Tripathi
  • 168,305
  • 31
  • 280
  • 331
1

Please change your query

you have extra ',' both after 'license' and '$license'

 $consulta = ("INSERT INTO `1264`(`id`,`name`,`institution`,`email`,`country`,`hcp`,`texto`,`state`,`license`) VALUES (NULL, '$name','$institution','$email','$country','$hcp','$texto','$state','$license');");

 mysql_query($consulta,$connection) or die("You cannot register. Try it later, please.");

Also try using mysqli_* functions. mysql_* functions going to deprecated.

fortune
  • 3,361
  • 1
  • 20
  • 30
0

Dont make the query so clumpsy. Here is a simple edit,

$consulta = "INSERT INTO `1264` SET 
    `name` = '$name',
    `institution` = '$institution',
    `email` = '$email',
    `country` = '$country',
    `hcp` = '$hcp',
    `texto` = '$texto',
    `state` = '$state',
    `license` = '$license'";

You don't have to write the id and leave its value field null, it will be auto generated by default.

dipak_pusti
  • 1,645
  • 2
  • 23
  • 42
0

if id is an primary key then it should not be null and if it is an auto increment field have no need to put it on field list and value
$consulta = ("INSERT INTO 1264(name,institution,email,country,hcp,texto,state,license,) VALUES ( '$name','$institution','$email','$country','$hcp','$texto','$state','$license',);");

do echo $consulta ;

to check if the query is coming properly or try put the variables out of cote check the name one

VALUES ( '".$name."','$institution','$email','$country','$hcp','$texto','$state','$license',)
Swarna Sekhar Dhar
  • 550
  • 1
  • 8
  • 25
-1

Removed the last comma and Id -> NULL so try this:

`$consulta = ("INSERT INTO` `1264`(`name`,`institution`,`email`,`country`,`hcp`,`texto`,`state`,`license`) VALUES `('$name','$institution','$email','$country','$hcp','$texto','$state','$license');");
Thanos Markou
  • 2,587
  • 3
  • 25
  • 32
  • Although your answer is quite probably correct, please add a short description about what you changed to make it work, for posteriority. – fvu May 27 '14 at 09:06
  • You haven't fixed the extra comma after `license`. – Barmar May 27 '14 at 09:10
-1

This should work - enter each variable between quotes, especially when its a string

$consulta = ("INSERT INTO `1264`(`id`,`name`,`institution`,`email`,`country`,`hcp`,`texto`,`state`,`license`) VALUES (NULL, "'. $name ."','".$institution."','".$email."','".$country."','".$hcp.'","'.$texto.'","'.$state.'",'".$license."');");
ratmalwer
  • 700
  • 5
  • 14
  • You still have the extra comma. Why do you think changing from string substitution to concatenation will fix it? – Barmar May 27 '14 at 09:08
  • You still haven't explained why you think it's necessary to use concatenation instead of interpolation. That's a personal style choice, it doesn't affect the validity of the code. – Barmar May 27 '14 at 09:17