mage1 Posted October 6, 2008 Share Posted October 6, 2008 i have a two buttons on my page the first button is UPDATE and the second is DELETE. how can i handle this two in one page? Link to comment https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/ Share on other sites More sharing options...
beansandsausages Posted October 6, 2008 Share Posted October 6, 2008 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 https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/#findComment-657944 Share on other sites More sharing options...
mage1 Posted October 6, 2008 Author Share Posted October 6, 2008 yes 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 https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/#findComment-658016 Share on other sites More sharing options...
JasonLewis Posted October 6, 2008 Share Posted October 6, 2008 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 https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/#findComment-658017 Share on other sites More sharing options...
mage1 Posted October 6, 2008 Author Share Posted October 6, 2008 thanks! sorry im just new in php trying to learn Link to comment https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/#findComment-658024 Share on other sites More sharing options...
mage1 Posted October 6, 2008 Author Share Posted October 6, 2008 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 https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/#findComment-658065 Share on other sites More sharing options...
dennismonsewicz Posted October 6, 2008 Share Posted October 6, 2008 you could do a switch... http://www.tizag.com/phpT/switch.php the above URL has a good tutorial on how to use a switch. I use switches all the time when I am doing a edit/delete/add function in a custom CMS. Link to comment https://forums.phpfreaks.com/topic/127197-update-and-delete-in-one-page/#findComment-658076 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.