1

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.

6
  • Do you get any errors or warnings ? Commented Nov 21, 2015 at 16:58
  • The only way to show those errors is to modify your php.ini with this line: display_errors = on Commented Nov 21, 2015 at 17:00
  • Nothing, no error and not inserting Commented Nov 21, 2015 at 17:00
  • display_errors = on is already done Commented Nov 21, 2015 at 17:01
  • Attentiom! If you manage to make this code run, it is very dangerous. You directly use the server-variables for sql, this is highly related to sql injection. It is very easy to attack your website an doete your data, modify your database, etc. Commented Nov 21, 2015 at 17:02

2 Answers 2

2

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" />
Sign up to request clarification or add additional context in comments.

2 Comments

YOU ROCK DUDE. You solved the issue. Silly mistake by me.
Glad I could help. Have fun coding further. ;-)
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.