1

I'm having a html form where i have 3 fields(ID, NAME, BLOOD GROUP). And below that I've 3 buttons(INSERT, UPDATE, DELETE). And then i want to enter the values in the fields and when click on the INSERT button these values should be entered into a table through a PHP script. Similar respective actions must happen with UPDATE and DELETE also. Can anyone help me out?

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$conn = mysql_connect($dbhost, $dbuser, $dbpass);

if (!$conn) {
    die("couldn't connect" . mysql_error());
}
echo 'connected successfully';
mysql_select_db('DB');

$id = $_POST['Id'];
$name = $_POST['Name'];
$blood = $_POST['BloodGroup'];
$order = "Insert into info(Id, name, BloodGroup) values ('$Id', '$Name', '$BloodGroup')";

$result = mysql_query($order);

if (!$result) {
    die('Input data failed' . mysql_error());
}
echo 'Input data entered successfully';
mysql_close($conn);
gbestard
  • 1,177
  • 13
  • 29
Naga Naveen
  • 99
  • 1
  • 4
  • 16

2 Answers2

1

Firstly make sure your form is submitting to the PHP script.

For this the INSERT button should be of type="submit". Then you can debug your PHP script line by line. For UPDATE and DELETE you can use the same PHP script with the query strings. Ex - ?id=xx&action=update OR ?id=zz&action=delete. Then you can apply the code in your PHP script corresponding to the action.

Rahul Patel
  • 639
  • 6
  • 12
0

Use mysql_select_db('DB') or die(mysql_error()); once. and also your variable names are wrong.

Please Use

$order = "Insert into info(Id, name, BloodGroup) values ('$id', '$name', '$blood')";

Deep Kakkar
  • 5,831
  • 4
  • 39
  • 75