Jump to content

Editing Something in a Database Through a Form


jonoc33

Recommended Posts

Hi guys,

I have a form with a bunch of text boxes, with writing in it that has been taken out of a database. eg:

 

In the database:

servername: Jono

ipaddress: 129.124 etc

time: 11:00

date: 18th march

password: pass

 

In the form it has the same thing.

 

What I need is a code for a page, that you are taken to after you hit submit, that updates a record with what you put in, and it will know what record to edit through hidden inputs that are also taken from the database.

 

Many thanks,

Jono

EDIT AGAIN:

Ok what i've tried is to delete it off the database, and if that works, then add the edited version of it.

 

<?php
error_reporting(E_ALL);
$con = mysql_connect("localhost","jonoc33","******") or die('Could not connect: '.mysql_error());
mysql_select_db("revolutiongamerz_net_-_squads", $con);
mysql_query("DELETE FROM alpha_scrims WHERE servername='$_POST[servername]' ") or die(mysql_error());

$sql="INSERT INTO alpha_scrims (servername, ipaddress, time, date, password)
VALUES ('" . $_POST["servername"] . "','" . $_POST["ipaddress"] . "','" . $_POST["time"] . "','" . $_POST["date"] . "','" . $_POST["password"] . "')";
$rs = mysql_query($sql) or die ("Problem with the query: $sql <br>" . mysql_error);
echo "<center>Record edited.";
echo "<center><a href=admin.php>Back</a>";
?>

That only seems to add it to the database, but doesn't delete it.

 

AHA! Spotted an error in the code.. Checking now

 

EDIT:

Lol, did it all myself.. Sorry for posting :D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.