0

I've been working on a MySQL database, and now I started to make some basic features for it; like single row deleting, updating and etc... My problem is, that my PHP file is not sending data to the database/table. I checked the variables, and they get trough the form, but no error message is shown except one notice.

My code is:

$tablanev = $_POST['tablaNev']; 
$oktazon = $_POST['OktAzon'];
$ehaazon = $_POST['EHA'];
$teljnev = $_POST['TeljesNev'];
$szemelyszam = $_POST['Szemelyazon'];
$anyanyelv = $_POST['Anyanyelv'];
$vegzettseg = $_POST['Vegzettseg'];
$anyanev = $_POST['AnyjaNeve'];
$szulhely = $_POST['SzulHe'];
$szulev = $_POST['SzulEv'];
$allampolg = $_POST['Allampolg'];
$neme = $_POST['Nem'];
$adoaz = $_POST['AdoSz'];
$taj = $_POST['TajSz'];
$bszamla = $_POST['BankSz'];

mysql_connect("localhost","root","alma");
mysql_select_db('etr');
mysql_query("INSERT INTO $tablanev(`OktAzonosito`,`EHAazonosito`,`TeljesNev`,`Szemelyazonosito`,`AnyaNyelv`,`VegzettsegSzint`,`AnyjaNeve`,`SzuletesiHely`,`SzuletesiEv`,`Allampolgarsag`,`Neme`,`Adoazonosito`,`TAJszam`,`BankszamlaSzam`) VALUES ('$oktazon','$ehaazon','$teljnev','$szemelyszam','$anyanyelv','$vegzettseg','$anyanev','$szulhely','$szulev','$allampolg','$neme','$taj','$bszamla')");

echo "Az adat sikeresen fel lett véve a táblába!!\n";

And I've checked the names of the table, and they fit perfectly.

3
  • Have you sql-escaped any of your post variables before adding them to the query? It doesn't look like it, which means your code is wide open to being hacked and having unexpected errors. Also, please be aware that the mysql_xxx() functions are considered obsolete and insecure; you are recommended to switch to using the mysqli_xx() functions instead, or the PDO library. Commented Nov 27, 2012 at 16:33
  • thx for the info!! i don't really know the best methods yet, casue i just started learning recently.But i'll be looking itno this:) Commented Nov 27, 2012 at 16:40
  • no worries. Read this question for more info on which functions to use: stackoverflow.com/questions/12859942/…. That answer also has info and further links regarding preventing SQL injection attacks. Commented Nov 27, 2012 at 16:43

2 Answers 2

1

You should catch the error to see what is happening:

    mysql_query("INSERT INTO $tablanev(`OktAzonosito`,`EHAazonosito`,`TeljesNev`,`Szemelyazonosito`,`AnyaNyelv`,`VegzettsegSzint`,`AnyjaNeve`,`SzuletesiHely`,`SzuletesiEv`,`Allampolgarsag`,`Neme`,`Adoazonosito`,`TAJszam`,`BankszamlaSzam`) VALUES ('$oktazon','$ehaazon','$teljnev','$szemelyszam','$anyanyelv','$vegzettseg','$anyanev','$szulhely','$szulev','$allampolg','$neme','$taj','$bszamla')") or die("Error: ".mysql_error());
Sign up to request clarification or add additional context in comments.

Comments

1

try to set a variable like this

$result = mysql_query("INSERT INTO $tablanev(`OktAzonosito`,`EHAazonosito`,`TeljesNev`,`Szemelyazonosito`,`AnyaNyelv`,`VegzettsegSzint`,`AnyjaNeve`,`SzuletesiHely`,`SzuletesiEv`,`Allampolgarsag`,`Neme`,`Adoazonosito`,`TAJszam`,`BankszamlaSzam`) VALUES ('$oktazon','$ehaazon','$teljnev','$szemelyszam','$anyanyelv','$vegzettseg','$anyanev','$szulhely','$szulev','$allampolg','$neme','$taj','$bszamla')");

if (!$result) {
    die('Invalid query: ' . mysql_error());
}

by the way, you should use the MySQLi or PDO_MySQL extension, the use of the extension you're using is discouraged.

Ref: http://php.net/manual/en/function.mysql-query.php

edit: you miss an argument in the query the correct one is:

"INSERT INTO $tablanev(`OktAzonosito`,`EHAazonosito`,`TeljesNev`,`Szemelyazonosito`,`AnyaNyelv`,`VegzettsegSzint`,`AnyjaNeve`,`SzuletesiHely`,`SzuletesiEv`,`Allampolgarsag`,`Neme`,`Adoazonosito`,`TAJszam`,`BankszamlaSzam`) VALUES ('$oktazon','$ehaazon','$teljnev','$szemelyszam','$anyanyelv','$vegzettseg','$anyanev','$szulhely','$szulev','$allampolg','$neme',' $adoaz','$taj','$bszamla')"

3 Comments

It says column count doesn't match at row 1, so that means i'm trying to insert the data in the wrong orger, or i forgot something out, right?
you miss an argument, i think you have to add $adoaz to your query :)
you're welcome :) if you found useful my answers, please upvoted it and make it as accepted :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.