Jump to content


Photo

a bunch of quick questions - delete and edit


  • Please log in to reply
4 replies to this topic

#1 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 12 July 2006 - 05:39 AM

QUESTION ONE:
I can do simple things like this:
session_start();

$username = $_SESSION['username'];

and then do say if($username){ and that basically means if they are logged in, i want to do if NOT LOGGED In. how would I do this?

QUESTION TWO:
I want to know how to make a form redirect someplace after it executes the query, I have this script:
if(isset($_POST['submit']) && !empty($_POST['password']) && !empty($_POST['cpassword']))
{


$password = $_POST['password'];
$cpassword = $_POST['cpassword'];

if($password!=$cpassword)
{
echo "Passwords do not match.";
}

$securepass = base64_encode($password);

$sql2 = "UPDATE admins SET password = '$securepass' WHERE username = '$username'";
$sqlr2 = mysql_query($sql2) or die(mysql_error());

}
?>
<form action="editpass.php" method="POST">
New Password:
<input type="password" name="password" />
<br />
New Password again:
<input type="password" name="cpassword" />
<Br />
<input type="submit" name="submit" value="Submit" />
</form>

Can someone post back that script having it redirect to logout.php after the query is executed?

QUESTION THREE:
I have a news and download system, both use POST and are fairly simple, I need to have edit and delete functions for each one, they obviously have their own unique ID. I know it is probably fairly easy to do I have just never seen the code for it. so im assuming it would do something like this:

fetch array to fetch id for each post, usign a while statement to link to deletenews.php?id=$id uniquely, etc etc. although probably a bit different for edit, using update table set.

anyway if anyone could point me to a good tutorial for question three it would be much appreciated.

anyone taking the time to read this and able to answer at least 1 question, very much appreciated and rep will be given.

thanks



#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 12 July 2006 - 05:48 AM

ONE:

if(!$username)


TWO:

2 options: JavaScript way:
<body onLoad="me.location("logout.php");">

or PHP way:
header("Location: http://www.uscript.com/logout.php");

THREE:

I never actually delete anything from my database unless I really, really need to. Fact is, sometimes we delete things and we really don't mean to, even after we press YES I REALLY MEAN TO button. I normally add a status field, and if the status is set to some number like 2, then I wont display it, but if it's set to 1 or something else, I will display it.

As for editing, you would use a SELECT statement to populate your normal addpost form with the data, then

UPDATE posts SET title = 'some here' and body = 'some more here' WHERE postID = $id


Hope that helps.. :)

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#3 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 12 July 2006 - 06:13 AM

hi localhost,

2)  as keeB, has pointed out, you can use the above two methods. i just want to remind you if you already know about working with header, then this is of no use for you,.

Make sure that no code should be executed before the header command.It means no echo statements, no blank spaces or no html output should come before the header statement.


cheers
sai



#4 Daniel0

Daniel0
  • Staff Alumni
  • Advanced Member
  • 11,956 posts

Posted 12 July 2006 - 06:25 AM

2 options: JavaScript way:

<body onLoad="me.location("logout.php");">


Then you are breaking the back button. When/if people click on the back button, then they will immediately get forward again. The header way is to prefer, since the page don't finish loading, but go to the new location as soon as it meets the Location header.

#5 localhost

localhost
  • Members
  • PipPipPip
  • Advanced Member
  • 152 posts

Posted 12 July 2006 - 10:53 AM

please, someone modify this script so it immediately redirects to index.php if logged in successfully!

<?php
session_start();
include('../connect.php');
$username = $_SESSION['username'];


$ip = $_SERVER['REMOTE_ADDR'];
$date = date("M d, Y");
$hitadd= MYSQL_QUERY("INSERT INTO stats(date, ip)".
"VALUES ('$date', '$ip')");

$date = date("M d, Y");
$uniquea = mysql_query("SELECT DISTINCT ip FROM stats");
$uniqueb = mysql_num_rows($uniquea);
$tdayua = mysql_query("SELECT DISTINCT ip FROM stats WHERE date = '$date'");
$tdayub = mysql_num_rows($tdayua);
$hitsa = mysql_query("SELECT * from stats");
$hitsb = mysql_num_rows($hitsa);
$tdayhitsa = mysql_query("SELECT * from stats where date = '$date'");
$tdayhitsb = mysql_num_rows($tdayhitsa);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" type="text/css" href="../default.css" />

<title>uScript - Home</title></head>

<body>
	<div class="header"><a href="index.php"><img src="../images/logo.png" alt="LOGO PLACEHOLDER" width="172" height="52" border="0" /></a></div>
<div class="sidebar">
		<div class="subheading"><strong>Navigation</strong></div>
			<div class="sidebarcontent">
			<?php
if($username) { echo "
			<p><a href=\"index.php\">Home</a></p>
			<p><a href=\"news.php\">News</a></p>
			<p><a href=\"downloads.php\">Downloads</a></p>
			<p><a href=\"features.php\">Features</a></p>
			<p><a href=\"changelog.php\">Changelog</a></p>
			<p><A href=\"support.php\">Support</A></p>
			<p><a href=\"forums/\">Forums</a></p>
			<p><A href=\"staff.php\">Staff</A></p>
			<p><a href=\"admin/\">ADMIN PANEL</a></p>
			<p><a href=\"admin/logout.php\">Logout</a></p>";
			} else {
			echo "
			<p><a href=\"index.php\">Home</a></p>
			<p><a href=\"news.php\">News</a></p>
			<p><a href=\"downloads.php\">Downloads</a></p>
			<p><a href=\"features.php\">Features</a></p>
			<p><a href=\"changelog.php\">Changelog</a></p>
			<p><A href=\"support.php\">Support</A></p>
			<p><a href=\"forums/\">Forums</a></p>
			<p><A href=\"staff.php\">Staff</A></p>";
			} 
			?>
		</div>
	        <div class="subheading" style="margin-top:2px;"><strong>Statistics</strong></div>
        <div class="sidebarcontent">
          <p>
		  Hits:<?php echo " $hitsb  <br />

			Hits Today: $tdayhitsb <br />
			Unique Hits: $uniqueb<br />
			Unique Today: $tdayub <br />
			Articles: ";?><?php
			
			$query = mysql_query("SELECT * FROM news") or die(mysql_error());
			$numrows = mysql_num_rows($query);
			
			echo "$numrows"; ?><br />
          </p>
  </div>

        <div class="subheading" style="margin-top:2px;"></div>
</div>
		<div class="content" style="margin-bottom:8px;">
	  <div class="newsheading">
	    <p><strong>Administrative Login </strong></p>
      </div>

	  <div class="newsarticle">
	    <form action="login.php" method="POST">
          <div align="center">
            <p>
              <input type="text" name="username" value="Username" onFocus="this.value=''" />
              <br />
              <input type="password" name="password" value="Password" onFocus="this.value=''" />
              <br />
              <input type="submit" name="submit" value="Login" />
			  <br />
			  <?php


include('../connect.php');

if ($_POST['username']) {
$username=$_POST['username'];
$password=md5($_POST['password']);
if ($password==NULL) {
echo "<font face='verdana' size='2'>No password given.";
}else{
$query = mysql_query("SELECT username,password FROM admins WHERE username = '$username'") or die(mysql_error());
$data = mysql_fetch_array($query);
if($data['password'] != $password) {
echo "Incorrect login, try again.";
}else{
$query = mysql_query("SELECT username,password FROM admins WHERE username = '$username'") or die(mysql_error());
$row = mysql_fetch_array($query);
$_SESSION["username"] = $row['username'];
echo "thanks for loggin in. <a href=../index.php>home</a>";
}
}
}
?>
            </p>
            <p>&nbsp;              </p>
          </div>
	    </form>
	    </div>
	</div>
	
<Font size="1"><center>
  <p>Copyright &copy;2006 <a href="http://uscript.org">uScript.org</a> - All Rights Reserved</p>
  <p>uScript is Free Software released under the GNU/GPL License. </p>
</center></Font> 






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users