Jump to content

UPDATE and DELETE in one page


mage1

Recommended Posts

2 seperate forms?

 

<form action="mypage.com?mod=edit" method="POST"/>
some text <br />
<input type="text" name="name" id="name" value="enter name to edit"/>
</form>

<form action="mypage.com?mod=delete" method="POST"/>
some text <br />
<input type="text" name="name" id="name" value="enter name to delete"/>
</form>

yes  :D

 

btw why does after I call the delete page.. Im not redirected to my header??

 

<?php
session_start(); 
$username=$_SESSION['user'];
if(!isset($_SESSION['user'])){
    
    header("Location: login.php"); 
} 


mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("<db>") or die(mysql_error());


mysql_query("DELETE FROM regusers WHERE username='$username'")
or die(mysql_error());

?>

Because you're logged in?

 

It should really be like this:

<?php
session_start(); 
if(!isset($_SESSION['user'])){
    header("Location: login.php");
exit; 
}else{
$username = $_SESSION['user'];
}


mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("<db>") or die(mysql_error());


mysql_query("DELETE FROM regusers WHERE username='$username'")
or die(mysql_error());

header("Location: index.php");
exit;

?>

where should i put the update? i have a two forms in my profile.php.. and i think i messup the code @ update.php

 

PROFILE.PHP


<?php
session_start(); 
$username=$_SESSION['user'];
if(!isset($_SESSION['user'])){
    
    header("Location: login.php"); 
} 
?>

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("<db>") or die(mysql_error());


$result = mysql_query("SELECT * FROM regusers WHERE username='$username'")
or die(mysql_error());  


$row = mysql_fetch_array( $result );

?>

*********************************************
<html part>

<input type="text" name="email" maxlength="32" value="<?php echo $row['email']; ?>" />
<input type="text" name="nickname" maxlength="32" value="<?php echo $row['nickname']; ?>" />

<form action="update.php" method="POST"/>
<input type="submit" name="update" value="Update" />
</form>
<form action="delete.php" method="POST"/>
<input type="submit" name="delete" value="Delete" />

 

DELETE.PHP

<?php
session_start(); 
if(!isset($_SESSION['user'])){
    header("Location: login.php");
exit; 
}else{
$username = $_SESSION['user'];
}


mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("<db>") or die(mysql_error());


mysql_query("DELETE FROM regusers WHERE username='$username'")
or die(mysql_error());

header("Location: index.php");
exit;

?>

 

 

UPDATE.PHP

 

<?php
session_start(); 
if(!isset($_SESSION['user'])){
    header("Location: login.php");
exit; 
}else{
$username = $_SESSION['user'];
}


mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("<db>") or die(mysql_error());


mysql_query("UPDATE regusers SET email='$email', nickname='$nickname' WHERE username='$username'")
or die(mysql_error());



header("Location: profile.php");
exit;

?>

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.