Click here to Skip to main content
15,847,077 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
<?php	

include 'db_connection.php';


$fname = $_REQUEST['fname'];


$Lname = $_REQUEST['Lname'];


$Mname=$_REQUEST['Mname'];

$fathername= $_REQUEST['fathername'];


$address= $_REQUEST['address'];

$gender= $_REQUEST['gender'];



$sql ="INSERT INTO  form (first_name, last_name, mother_name, father_name, address_detail, gender_detail ) VALUES ('".$fname."', '".$Lname."', '".$Mname."', '".$fathername."', '".$address."', '".$gender."' )";

if ($conn->query ($sql) == TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
	
	
?>


What I have tried:

doesn't seem to do with it....
Please answer as fast as you can.
Posted
Updated 10-Nov-22 22:10pm
Comments
Member 15627495 11-Nov-22 2:18am    
hello !


where is
$conn = mysqli->open(..,..?..?..);

if you don't use a function on $_REQUEST, it's just a reallocation of the value for nothing, it's useless the way you do.
$var_for_nothing = $_request['first_var'];
you're making 2 vars for 1 value. it's a problem.
$_REQUEST is an array, with vars in, already in memory stamp.
about gender_detail : if it's a boolean, you have to integrate this value without escaping characters, so 'no quote' 1 or 0 will pass.
the db engine wait for a 'boolean' and you send a 'string'. so an error is return.
CHill60 28-Mar-23 9:58am    
Solution 1 is incorrect. Your database table does not have a column called gender_detail - check the spelling

Do not do it like that! Never concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Always use Parameterized queries instead.

When you concatenate strings, you cause problems because SQL receives commands like:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'Baker's Wood'
The quote the user added terminates the string as far as SQL is concerned and you get problems. But it could be worse. If I come along and type this instead: "x';DROP TABLE MyTable;--" Then SQL receives a very different command:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';DROP TABLE MyTable;--'
Which SQL sees as three separate commands:
SQL
SELECT * FROM MyTable WHERE StreetAddress = 'x';
A perfectly valid SELECT
SQL
DROP TABLE MyTable;
A perfectly valid "delete the table" command
SQL
--'
And everything else is a comment.
So it does: selects any matching rows, deletes the table from the DB, and ignores anything else.

So ALWAYS use parameterized queries! Or be prepared to restore your DB from backup frequently. You do take backups regularly, don't you?
 
Share this answer
 
using a 'boolean' for gender :

$sql ="INSERT INTO  form (first_name, last_name, mother_name, father_name, address_detail, gender_detail ) VALUES ('".$fname."', '".$Lname."', '".$Mname."', '".$fathername."', '".$address."',$gender)";
 
Share this answer
 

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



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