Hello! I'm following a CRUD tutorial with PDO, Ajax and Modal Bootstrap for implementation in a project. My database has 2 tables ( users ) and ( type_ps ). The users table has the following structure:
CREATE TABLE 'users' (
'id' int(11) NOT NULL AUTO_INCREMENT,
'first_name' varchar(150) CHARACTER SET latin1 NOT NULL,
'last_name' varchar(150) CHARACTER SET latin1 NOT NULL,
'image' varchar(150) CHARACTER SET latin1 NOT NULL,
'tipo_fk' int(11) NOT NULL,
PRIMARY KEY ('id'),
KEY 'tipo_fk' ('tipo_fk'),
CONSTRAINT 'users_ibfk_1' FOREIGN KEY ('tipo_fk') REFERENCES 'tipo_ps' ('tipo_id') ON DELETE NO ACTION ON UPDATE CASCADE
) ENGINE=InnoDB AUTO_INCREMENT=94 DEFAULT CHARSET=utf8
And the table type_ps has the following structure:
CREATE TABLE 'tipo_ps' (
'tipo_id' int(11) NOT NULL AUTO_INCREMENT,
'tipo' varchar(11) NOT NULL,
PRIMARY KEY ('tipo_id')
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8 COMMENT='Tabela tipo produto ou serviços'
As you can see, in the users table I created a foreing Key named f_type whose relationship was created correctly where inserting data into users via phpMyAdmin is ok.
The problem is that after I created the F_type column in the users table, I inserted this column into the PHP PDO scripts that are part of the tutorial based on structure PHP PDO that is there, but still the table does not load and does not add data in Mysql, where when the form is filled and then the submit button is clicked, an Ajax alert appears blank as below:
Afterthisactionofsubmit,thebrowsersthroughtheF12buttonNetworkmenu,informthestructureoftheactionoccurredasshownbelow:
<?php
include('db.php');
include('function.php');
if(isset($_POST["operation"]))
{
if($_POST["operation"] == "Add")
{
$image = '';
if($_FILES["user_image"]["name"] != '')
{
$image = upload_image();
}
$statement = $connection->prepare("
INSERT INTO users (tipo_fk, first_name, last_name, image)
VALUES (:tipo_fk, :first_name, :last_name, :image)
");
$result = $statement->execute(
array(
**********':tipo_fk' => $_POST['tipo_fk'],**********
':first_name' => $_POST['first_name'],
':last_name' => $_POST['last_name'],
':image' => $image
)
);
if(!empty($result))
{
echo 'Data Inserted';
}
}
?>