Ronit
Ronit

Reputation: 57

PHP not inserting data into MYSQLi

I tried a little program to insert data in mysql through PHP but nothing happens. It neither gives an error nor it is inserting the data. Unable to understand where is the problem?

<?php
$database=mysqli_connect("localhost","root","","aaa")or die('Localhost Connection Problem');
$xyz=mysqli_select_db($database,"aaa");
if(isset($_POST['submit']))
{
    $dlqty=$_POST['dlqty'];
    $slqty=$_POST['slqty'];
    $price=$_POST['price'];
$ins=mysqli_query($database,"insert into bbb (dlqty,slqty,price) values ('$dlqty','$slqty','$price')");
mysqli_close($database);
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<form name="eee" method="post">
<input type="text" name="dlqty"  />
<input type="text" name="slqty"  />
<input type="text" name="price"  />
<input type="button" name="submit" value="submit" />
</form>
</body>
</html>

Help will be appreciated.

Upvotes: 1

Views: 136

Answers (2)

Ciprian Stoica
Ciprian Stoica

Reputation: 2439

It's a HTML problem. Your form actually doesn't submit anything.

Change your submit button definition from

<input type="button" name="submit" value="submit" />

to

<input type="submit" name="submit" value="submit" />

Upvotes: 2

Strawberry
Strawberry

Reputation: 33945

How about:

$query = "
INSERT INTO bbb (dlqty,slqty,price) VALUES ('$dlqty','$slqty','$price');
";

$ins = mysqli_query($database,$query) or die(mysqli_error());

And then, once you've figured out the problem, switch to prepared statements

Upvotes: 0

Related Questions