• Welcome to TechPowerUp Forums, Guest! Please check out our forum guidelines for info related to our community.

some html php and mysql mixed question

r9

Joined
Jul 28, 2008
Messages
3,300 (0.57/day)
System Name Primary|Secondary|Poweredge r410|Dell XPS|SteamDeck
Processor i7 11700k|i7 9700k|2 x E5620 |i5 5500U|Zen 2 4c/8t
Memory 32GB DDR4|16GB DDR4|16GB DDR4|32GB ECC DDR3|8GB DDR4|16GB LPDDR5
Video Card(s) RX 7800xt|RX 6700xt |On-Board|On-Board|8 RDNA 2 CUs
Storage 2TB m.2|512GB SSD+1TB SSD|2x256GBSSD 2x2TBGB|256GB sata|512GB nvme
Display(s) 50" 4k TV | Dell 27" |22" |3.3"|7"
VR HMD Samsung Odyssey+ | Oculus Quest 2
Software Windows 11 Pro|Windows 10 Pro|Windows 10 Home| Server 2012 r2|Windows 10 Pro
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 :D.
 
Joined
Aug 10, 2007
Messages
4,267 (0.70/day)
Location
Sanford, FL, USA
Processor Intel i5-6600
Motherboard ASRock H170M-ITX
Cooling Cooler Master Geminii S524
Memory G.Skill DDR4-2133 16GB (8GB x 2)
Video Card(s) Gigabyte R9-380X 4GB
Storage Samsung 950 EVO 250GB (mSATA)
Display(s) LG 29UM69G-B 2560x1080 IPS
Case Lian Li PC-Q25
Audio Device(s) Realtek ALC892
Power Supply Seasonic SS-460FL2
Mouse Logitech G700s
Keyboard Logitech G110
Software Windows 10 Pro
Your Persons table has a primary key? Use that instead of a first/last name combination.

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

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 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.
 
  • Like
Reactions: r9

FordGT90Concept

"I go fast!1!11!1!"
Joined
Oct 13, 2008
Messages
26,259 (4.62/day)
Location
IA, USA
System Name BY-2021
Processor AMD Ryzen 7 5800X (65w eco profile)
Motherboard MSI B550 Gaming Plus
Cooling Scythe Mugen (rev 5)
Memory 2 x Kingston HyperX DDR4-3200 32 GiB
Video Card(s) AMD Radeon RX 7900 XT
Storage Samsung 980 Pro, Seagate Exos X20 TB 7200 RPM
Display(s) Nixeus NX-EDG274K (3840x2160@144 DP) + Samsung SyncMaster 906BW (1440x900@60 HDMI-DVI)
Case Coolermaster HAF 932 w/ USB 3.0 5.25" bay + USB 3.2 (A+C) 3.5" bay
Audio Device(s) Realtek ALC1150, Micca OriGen+
Power Supply Enermax Platimax 850w
Mouse Nixeus REVEL-X
Keyboard Tesoro Excalibur
Software Windows 10 Home 64-bit
Benchmark Scores Faster than the tortoise; slower than the hare.
FYI:
HTML:
<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).
 
  • Like
Reactions: r9
Top