MySQL Forums
Forum List  »  PHP

Data are not inserted into database table, I donno where is the problem?
Posted by: Ahmed Lazrak
Date: January 19, 2016 02:56PM

Hello everyone!
For a home project I have to create a database and a table inside.
Then let users insert data into table via simple html form.
This form uses a php file to do the inserting, the form is just to get data.
I'm using MyphpAdmin in wampserver to create database and table manually.

here is my code:

in the first file for connecting to server and selecting database

<?php
$server="localhost";
$user= "root";
$password="";

$connect=@MySQL_Connect($server,$user,$password) or die ("connection failed!");

echo "Server Access granted";

$base= "Mabase";
MySQL_Select_db($base);

echo "<br>Mabase was selected"
?>

===================
the second file is a simple html form
===================

<html>
<head>
<title>Formulaire de Saisie</title>
</head>
<body>
<form action = "traiter.php" method = "POST">
Enter Code : <input type = "text" name = "Code"></input><br>
Enter Designation : <input type = "text" name = "Des"></input><br>
Entrez Prix Unitaire : <input type = "text" name = "PU"></input><br>
Entrez Quantite en stock : <input type = "text" name = "QS"></input><br>
<input type = "submit" value = "valider">
</form>
</body>
</html>

====================
the third file is traiter.php that you see in the html form
====================

<?php
require ("choixBD.php");

$code = $_POST["Code"]; // product code
$des = $_POST["Des"]; // meaning
$pu = $_POST["PU"]; // unie price
$qs = $_POST["QS"]; // quantity
$pttc = $pu*1.2; // TAX

$nomtable = "Produit";
$req = "INSERT INTO $nomtable (Code,Designation,Quantite,PrixUnitaire,PTTC) VALUES('$code','$des,'$qs','$pu','$pttc')";
$result = @MySQL_Query($req);

if (!$result) {
echo "<br> impossible to execute ($req) in db".@MySQL_error();
exit;
}
echo"<br>Values have been added";
?>

=====================
the idea is that the user will open the form file and enter data and click submit and data should be added
the problem is that data are not added and I don't know why. here is the error message

impossible to execute (INSERT INTO Produit (Code,Designation,Quantite,PrixUnitaire,PTTC) VALUES('s425','gaming mouses,'190','1300','1560')) in dbYou have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '190','1300','1560')' at line 1

Thanks in advance :)

Options: ReplyQuote


Subject
Written By
Posted
Data are not inserted into database table, I donno where is the problem?
January 19, 2016 02:56PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.