As the title suggests I am getting the ‘Column count doesn’t match value count at row 1’ error. After comparing the values I want to send to database with my database and did not find a mistake, I looked over the internet and tried various solutions. None of them worked so far. I also tried to use SET instead of VALUES. Like ‘Passwort’ = ‘$passwort’ – Also did not do the trick. Here is my code, maybe someone spots an obvious mistake that I missed?
$name = ($_GET["name"]);
$sql = "INSERT INTO $DB_Table VALUES('$name')";
$passwort = ($_GET["passwort"]);
$sql = "INSERT INTO $DB_Table VALUES('$passwort')";
$con = mysql_connect($DB_HostName,$DB_User,$DB_Pass) or die (mysql_error());
mysql_select_db($DB_Name,$con) or die(mysql_error());
mysql_set_charset('utf8', $con);
mysql_query("INSERT INTO $DB_Table (Name,Passwort) VALUES ('$name','$passwort')");
$res = mysql_query($sql,$con) or die(mysql_error());
mysql_close($con);
if ($res) {
echo "Der Benutzer wurde neu angelegt!";
}else{
echo "Der Benutzername ist bereits vergeben";
}
Here you just overwritten the previous variable, so what’s the point of having the previous one?
And then you’re trying to execute the query, which will fail, as the table has more columns.
I don’t even know why you’re trying to do this, as the previous line already did the insert. Did you meant to do this? :
That all said, your code is vulnerably to SQL injection attacks, and it’s using a the old mysql interface.