Click here to Skip to main content
15,885,914 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello everyone!, I have a problem in my php code, the error is when I send my form data it throws me, this the error:


Error: INSERT INTO usuario(name,last,nameDad,nameMom,tipoIdentificacion,identificacion,telefono,email,address ,born,rango,estadoC,sex,contraseña) values ('Caca','acac','caca','acac','Venezolano:','123123123','123123123123','sdsds@gmail.com','jjashdjhasjd2!#F','128887-02-21','2131231','Viudo(A)', 'Man','sdsdsdsdsd')
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '�a) values ('Caca','acac','caca','acac','Venezolano:','123123123','1231231231' at line 2


This is my code php:
<?php 
 
$dbhost = "localhost";
$dbuser = "root";
$dbpass = "";
$dbname = "clini";

$conn = mysqli_connect($dbhost,$dbuser,$dbpass,$dbname);
 
if(!$conn)
{
	die("No hay conexion:" .mysqli_connect_error());
}
 ?>
 
<?php 
 
 $nombre = $_POST['name'];
 $identi = $_POST['ci'];

//Login
if(isset($_POST["ingre"]))
{
	$query = mysqli_query($conn,"SELECT * FROM usuario WHERE nombre = '$nombre' AND identificacion='$identi'");
	$nr = mysqli_num_rows($query);
	
	if($nr==1)
	{
		echo "<script> alert('Bienvenido: $nombre,$appelidoC:'); window.location='home.php' </script>";
	}else
	{
		echo "<script> alert('Usuario no existe 😞'); window.location='index.php' </script>";
	}
}
  
  //Registrar
$name = $_POST["name"];
$apellido = $_POST["apec"];
$dad = $_POST["namep"];
$mom = $_POST["namem"];
$tipeCI = $_POST["tipeid"];
$ci = $_POST["ci"];
$phone = $_POST["te"];
$correo = $_POST["email"];
$add = $_POST["dirre"];
$day = $_POST["diana"];
$gradoI = $_POST["gradoin"];
$esC = $_POST["estado"];
$sex = $_POST["sex"];
$pass = $_POST["pass"];
  
if(isset($_POST["butt"]))
{
	$sqlgrabar = "INSERT INTO usuario(name,last,nameDad,nameMom,tipoIdentificacion,identificacion,telefono,email,address
	,born,rango,estadoC,sex,contraseña)
	values ('$name','$apellido','$dad','$mom','$tipeCI','$ci','$phone','$correo','$add','$day','$gradoI','$esC',
	'$sex','$pass')"; 
	
	if(mysqli_query($conn,$sqlgrabar))
	{
		echo "<script> alert('Feliciddes el usuario fue registrado con exito: $nombre'); window.location='index.html' </script>";
	}else 
	{
		echo "Error: ".$sqlgrabar."<br>".mysqli_error($conn);
	}
}
?>  


What I have tried:

I tried very things, what do they say on Internet, but good is same
Posted
Updated 5-Nov-21 8:41am
v2
Comments
[no name] 5-Nov-21 14:33pm    
It says it doesn't like the "ñ" in contraseña.
Richard Deeming 9-Nov-21 6:40am    
Your code is vulnerable to SQL Injection[^]. NEVER use string concatenation to build a SQL query. ALWAYS use a parameterized query.
PHP: SQL Injection - Manual[^]
PHP: Prepared statements and stored procedures - Manual[^]
Richard Deeming 9-Nov-21 6:41am    
You are storing passwords in plain text. Don't do that.
Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]

PHP even has built-in functions to help you do the right thing:
PHP: password_hash[^]
PHP: password_verify[^]

1 solution

You must quote identifiers when they contain extended characters (like the ñ in contraseña). A good habit would be to **not** use such characters for identifiers, but if you really need to, try
SQL
INSERT INTO usuario(name, last, nameDad, nameMom, tipoIdentificacion, identificacion, telefono, email, address, born, rango, estadoC , sex, `contraseña`) values ...
 
Share this answer
 
Comments
XEmmanuel21 5-Nov-21 20:02pm    
Hi thanks you very much for!
phil.o 5-Nov-21 20:10pm    
I mean: every database element name that you define (database name, table name, column name, etc...) should not hold any extended characters. It's best to stick with ASCII characters, no accent, no language-specific letter, etc.
For example, in your query, you could just use english names for columns, for the sake of consistency. I find it rather disturbing to read text with mixed-languages. I never name any code element or database member in my native language.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900