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>

Link to comment
Share on other sites

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());

?>

Link to comment
Share on other sites

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;

?>

Link to comment
Share on other sites

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;

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.