Driving me crazy...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Wldrumstcs
Forum Commoner
Posts: 98
Joined: Wed Nov 26, 2003 8:41 pm

Driving me crazy...

Post by Wldrumstcs »

Ok, this is driving me nuts. I made a form where someone types in their email address and it deletes it from a mysql DB. Here's the code:

Code: Select all

<form method="POST" action="edit.php">
		<table border="0" width="100%" id="table3">
			<tr>
				<td colspan="2">
				<p align="center"><font face="Arial">If you would like to end 
				your membership with TidBitFacts.com, please type your email 
				below!</font></td>
			</tr>
			<tr>
				<td align="right" width="50%"><font face="Arial">Your Email 
				Address:</font></td>
				<td align="left">
				<input type="text" name="delemail" size="25" style="border: 1px solid #C0C0C0"></td>
			</tr>
		</table>
		<p align="center">
		<input type="submit" value="deleteaccount" name="deleteaccount" style="border: 1px solid #000000"></p>
	</form>
<? mysql_connect("localhost","awegweg","wegwelone") or die ("Unable to connect to MySQL server."); 
$db = mysql_select_db("adsfadsfh") or die ("Unable to select requested database.");

if($_POST[deleteaccount]) {
$id=$_COOKIE[id]
DELETE FROM members WHERE id='$id';
}
?>
Could i get help?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

you totally made this part wrong:

Code: Select all

<?php
if($_POST[deleteaccount]) { //No ' and '
$id=$_COOKIE[id]; //Here neither, also, you forgot the ;
DELETE FROM members WHERE id='$id'; //Where are you queryeing?
} 
?>
it should be something like this:

Code: Select all

<?php
if ($_POST['deleteaccount']) { 
$id = $_COOKIE['id'];
$query = "DELETE * FROM members WHERE id='$id'"; // Not sure about the star (*), since im a beginner at MySQL
mysql_query($query); // You need to query it
} 
?>
BTW, where are you checking the email? didn't you just show it for us, or have you frogt it? from what i can see, the email filed isn't needed
microthick
Forum Regular
Posts: 543
Joined: Wed Sep 24, 2003 2:15 pm
Location: Vancouver, BC

Post by microthick »

vigge almost had it.

Code: Select all

<?php
if ($_POST['deleteaccount']) { 
$id = $_COOKIE['id']; 
$query = "DELETE FROM members WHERE id='$id'"; // No star needed.
mysql_query($query); // You need to query it 
} 
?>
Jim
Forum Contributor
Posts: 238
Joined: Fri Apr 19, 2002 5:26 am
Location: Near Austin, Texas

Post by Jim »

Or, save yourself a bit of memory...

Code: Select all

<?php 
if ($_POST['deleteaccount']) { 
$id = $_COOKIE['id']; 
$query = mysql_query("DELETE FROM members WHERE id='$id'"); // No need to set up a variable and then query it.. just query it straight away!
} 
?>
User avatar
lazy_yogi
Forum Contributor
Posts: 243
Joined: Fri Jan 24, 2003 3:27 am

Post by lazy_yogi »

also, you don't need to connect to mysql unless in the if statement:

Code: Select all

<?php
if($_POST[deleteaccount]) { 

    mysql_connect("localhost","awegweg","wegwelone") 
        or die ("Unable to connect to MySQL server."); 
    $db = mysql_select_db("adsfadsfh") 
        or die ("Unable to select requested database."); 

    $id = $_COOKIE['id']; 
    $query = mysql_query("DELETE FROM members WHERE id='$id'"); 

} 
?>
Post Reply