/    Sign up×
Community /Pin to ProfileBookmark

delete and update

now i have a database and a from.
i can now insert data from a form into mydatabase but till now i’m trying to update data and i can not
after that i treid to delete data and i can not reach it also
can anyone help me

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@MindzaiDec 01.2008 — What exactly is the problem you are having? Can you post your code? Without those nobody can do much except point you to the MySQL Manual.
Copy linkTweet thisAlerts:
@john_zakariaauthorDec 01.2008 — Form code:


<form method="post" action="create_subject.php" id="1" name="gateway" >

<table width="500" border="0" cellspacing="0" cellpadding="0">

<tr>

<td width="190">Hotel Name</td>

<td>:::</td>

<td width="200"><label for="hotel_name"></label>

<input type="text" name="hotel_name" id="hotel_name"></td>

<td>

<input type="checkbox" name="hotel" id="hotel">

<label for="hotel"></label></td>

</tr>

<tr>

<td>Tel</td>

<td>:::</td>

<td><input type="text" name="tel" id="tel"></td>

<td><input type="checkbox" name="te" id="te"></td>

</tr>

<tr>

<td>Tel2</td>

<td>:::</td>

<td><input type="text" name="tel2" id="tel2"></td>

<td><input type="checkbox" name="te2" id="te2"></td>

</tr>

<tr>

<td>Fax</td>

<td>:::</td>

<td><input type="text" name="fax" id="fax"></td>

<td><input type="checkbox" name="fa" id="fa"></td>

</tr>

<tr>

<td>Contact Person</td>

<td>:::</td>

<td><input type="text" name="contact_person" id="contact_person"></td>

<td><input type="checkbox" name="cp" id="cp"></td>

</tr>

<tr>

<td>E-mail</td>

<td>:::</td>

<td><input type="text" name="emal" id="emal"></td>

<td><input type="checkbox" name="eml" id="eml"></td>

</tr>

<tr>

<td>Notes</td>

<td>:::</td>

<td><input type="text" name="notes" id="notes"></td>

<td><input type="checkbox" name="nts" id="nts"></td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td><label for="submit"></label>

<input type="submit" name="submit" id="submit" value="Submit"> <label for="update"></label></td>

<td>&nbsp;</td>

</tr>

</table>

</form>



Create_subject.php


<?

$DBhost = "localhost";

$DBuser = "root";

//$DBpass = "123456";

$DBname = "gateway";

/// 1. create a database connection
$connection = mysql_connect($DBhost, $DBuser)
or die ("database connect error: " . mysql_error());
//// 2. select a database to use
$db_connect = mysql_select_db($DBname, $connection)
or die ("database select error: " . mysql_error());

///// 3. Perform database query
$qryp = "SELECT * FROM hotels";
print "qryp: " . $qryp . "<br>";
$result = mysql_query($qryp)
or die ("table error: " . mysql_error());?>
<table border="1">
<tr>

<td>Hotel </td>
<td>Tel</td>
<td>Tel2</td>
<td>Fax</td>
<td>Contact Person</td>
<td>E-mail</td>
<td>Notes</td>

</tr>
<p>
<?



$hotel_name=$_POST["hotel_name"];

$tel=$_
POST["tel"];

$tel2=$_POST["tel2"];

$fax=$_
POST["fax"];

$contact_person=$_POST["contact_person"];

$emal=$_
POST["emal"];

$notes=$_POST["notes"];

?>

<?

$qryp2="INSERT INTO hotels (

Hotel_Name ,

Tel ,

Tel2 ,

Fax ,

Contact_Person ,

E-mail ,

Notes

)

VALUES (

'$hotel_name', '$tel', '$tel2', '$fax', '$contact_person', '$emal', '$notes'

)";

$result2 = mysql_query($qryp2);

///// 3. Perform database query

$qryp = "SELECT * FROM hotels";

print "qryp: " . $qryp . "<br>";

$result = mysql_query($qryp)

or die ("table error: " . mysql_error());

//// 4. Use returned data
while ($tr_res = mysql_fetch_array($result)){

echo "<tr>";

echo

"<td>" . $tr_res["Hotel_Name"] . "</td>
<td>" . $tr_res["Tel"] . "</td>
<td>" . $tr_res["Tel2"] . "</td>
<td>" . $tr_res["Fax"] . "</td>
<td>" . $tr_res["Contact_Person"] . "</td>
<td>" . $tr_res["E-mail"] . "</td>
<td>" . $tr_res["Notes"] . "</td>


";

echo "</tr>";
}

echo("</table>");








?>



i want to update data entered before or delete data entered before

this is an example for how i made the insert
Copy linkTweet thisAlerts:
@MindzaiDec 01.2008 — I'm still not sure exactly what you're asking but if it;s how to update data take a look at the MySQL Manual Page for Update which shows you.

Also you really need to sanitize your form data. As it stands I could very easily delete all the data in your tables (or do pretty much anything else) just from filling out your form in a certain way.
×

Success!

Help @john_zakaria spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...