# some html php and mysql mixed question



## r9 (Aug 30, 2009)

I have a FORM in HTML file that has CHECKBOX: 

<body>
<form id="form1" name="lastname" method="post" action="delete1.php">
  <label>Label
    <select name="lastname">
      <option value="Ristovski">Ristovski</option>
      <option value="Petacka">Petacka</option>
    </select>
  </label>
<input type="submit" />
</form>

that I want to send data to PHP file delete.php

<?php
$con = mysql_connect("localhost","root","00000000");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("proba", $con);

$sql="DELETE FROM Persons WHERE LastName='$_POST[lastname]' AND FirstName='$_POST[firstname]'";

if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record DELETED";
?> 

The problem is in my html file. I`m new to this and I don`t know how to assign multiple names and values to one radio button so when I submit it would send  that in to the PHP file LastName='$_POST[lastname]' AND FirstName='$_POST[firstname]'";
I just know how to set checkbox how to send just last name or first name. The question is how to send both with just one checkbox selected. I hope this make sense .


----------



## Disparia (Aug 30, 2009)

Your Persons table has a primary key? Use that instead of a first/last name combination.


```
<select name="person_id">
	<option value="1">Ristovski</option>
	<option value="2">Petacka</option>
</select>
```


```
<?php
$con = mysql_connect("localhost","root","00000000");

if (!$con) {
	die('Could not connect: ' . mysql_error());
}

mysql_select_db("proba", $con);

$sql = "DELETE FROM Persons WHERE person_id = ".$_POST['person_id'];

if (!mysql_query($sql,$con)) {
	die('Error: ' . mysql_error());
}

echo "1 record DELETED";
?>
```

There's no protection from SQL injection, nor verification of deletion (anyone could call delete.php?person_id=x, with x = 1 to 2^64 to clear your table out), so keep that in mind if these files are accessible by the outside world.


----------



## FordGT90Concept (Aug 30, 2009)

FYI:

```
<select name="person_id">
	<option value="1" selected>Ristovski</option>
	<option value="2">Petacka</option>
</select>
```
Ristovski would be selected by default.

I usually do names like "checkbox{ID}" or "firstname{ID}" or "lastname{ID}"  That way every single named object in the form has a unique name like checkbox5, firstname100, lastname9.  You have everything you need now to work with it (name, id, and value).


----------

