Current location: Hot Scripts Forums » Programming Languages » PHP » Cool tutorial I found, One of my scripts, and a question I REALLY NEED HELP WITH


Cool tutorial I found, One of my scripts, and a question I REALLY NEED HELP WITH

Reply
  #1 (permalink)  
Old 09-01-05, 07:17 PM
HoTDaWg's Avatar
HoTDaWg HoTDaWg is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Question Cool tutorial I found, One of my scripts, and a question I REALLY NEED HELP WITH

Hi,

I am currently learning the outstanding feature of php know as, "User authentication". I found a great tutorial on it,
Here's the url:
http://www.howthenetworks.org/view.php?id=2

The script worked, and I decided to make a user panel
(A page which would display all the users and their details)
(You guys can use it for free as I based it on another tutorial I learned on http://www.greycobra.com/)

Here's the script:
Code:
<?php

//First, we need to connect to the server
//the format is $connection = mysql_connect("address","username","password");
$conn = mysql_connect("localhost","username","password");

//now choose the database to use
mysql_select_db("mydatabase");

$getusers = mysql_query("SELECT * FROM users ORDER BY id DESC");//query 
//the database for all of the news



while($r=mysql_fetch_array($getusers)){//while there 
//are rows in the table

extract($r);//remove the $r so its just $variable 




echo("<hr>

<font size=3>Username: $username <br></font>
<font size=3>Password: $password </font><p>");



}



?>
Now, my question is, how can delete a user from the database? As well as how can I edit a users details? I know it's a lot to ask for but, what else can I do? If you know any tutorials, or even better know the code PLZ HELP ME OUT. Help would be greatly appreciated.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 09-02-05, 03:59 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
hi,
first you need to display your data in tables, it's ways easier in use, second,
just add another 2 columns to your 'userlist', lke this:

PHP Code:

<table border="1">

<tr>
  <td><b>Username</b></td>
  <td><b>Password</b></td>
  <td><b>Edit</b></td>
  <td><b>Delete</b></td>
</tr>

<?php

//First, we need to connect to the server
//the format is $connection = mysql_connect("address","username","password");
$conn mysql_connect("localhost","username","password");

//now choose the database to use
mysql_select_db("mydatabase");

$getusers mysql_query("SELECT * FROM users ORDER BY id DESC");//query 
//the database for all of the news



while($r=mysql_fetch_array($getusers)){//while there 
//are rows in the table

extract($r);//remove the $r so its just $variable 




echo("<tr><td><font size=3>$username</font></td>
<td><font size=3>Password: 
$password </font></td>
<td><a href=\"edit_user.php?id=
$id\">Edit</a></td>
<td><a href=\"del_user.php?id=
$id\">Delete</a></td></tr>");



}
?>
</table>
Now lets make the edit_user page. It's a basic page (no checking for script tags or invalid usernames/passwords:
PHP Code:

<?php

//open connection here
$id$_GET['id'];
if(
$_POST['edit'])):

if(!empty(
$_POST['username']) && !empty($_POST['password'])):
 
$sql "UPDATE users SET username='".$_POST['username']."', password='".$_POST['password']."' WHERE id='$id'";
 
mysql_query($sql) or die(mysql_error());
 
header("Location: //userlistingscript");
 exit();
else:
 echo 
"Some fields Were left blank";
endif;

else:
$sql "SELECT username,password FROM users WHERE id='$id'";
$r mysql_query($sql) or die(mysql_error());
while(
$all mysql_fetch_object($res)):
$username=$all->username;
$password=$all->password;
endwhile;
?>
<html>
<form method="post"> //action= not defined => page recalls itself
<input type="text" name="username" size="25" value="<? echo $username?>"><br>
<input type="password" name="password" size="25" value="<? echo $password?>"><br><!-- you don't do this normally: displaying a password so you can edit it -->
<input type="submit" name="edit" value="Edit !">
</form>
</html>
so now we've made the edit script, let's make the delete script:
PHP Code:

<?

//open connection here
$id=$_GET['id'];
$sql"DELETE FROM users WHERE id='$id'";
mysql_query($sql) or die(mysql_error());
header("Location: //userlisting page here");
exit();
Hope it helped you
Greetz

UnrealEd
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 09-02-05, 05:49 PM
HoTDaWg's Avatar
HoTDaWg HoTDaWg is offline
Newbie Coder
 
Join Date: Aug 2005
Posts: 43
Thanks: 0
Thanked 0 Times in 0 Posts
Hi,
Firstly, thank you for your help, secondly, I'm having trouble with the edit_user.php file. There were some errors in the script which I found out about, here's the code I have so far:
Code:
<html>
<head>
<title>Edit A User</title>
</head>
<body bgcolor="#FFFFFF">
<?php
$conn = mysql_connect("localhost","unenclosed","youtellme");

//now choose the database to use
mysql_select_db("my_db");
$id= $_GET['id'];
if($_POST['edit']):

if(!empty($_POST['username']) && !empty($_POST['password']));
$sql = "UPDATE users SET username='".$_POST['username']."', password='".$_POST['password']."' WHERE id='$id'";
mysql_query($sql) or die(mysql_error());
header("Location: http://www.hotdawg.hostyournet.com/driverpanel/userauthentication/user.php");

else:
echo "Some fields Were left blank";

else
$sql = "SELECT username,password FROM users WHERE id='$id'";
$r = mysql_query($sql) or die(mysql_error());
while($all = mysql_fetch_object($res));
$username=$all->username;
$password=$all->password;
?>

<form method="post">
<!--action= not defined => page recalls itself--!>
<input type="text" name="username" size="25" value="<? echo $username ?>"><br>
<input type="password" name="password" size="25" value="<? echo $password ?>"><br>
<!-- you don't do this normally: displaying a password so you can edit it -->
<input type="submit" name="edit" value="Edit">
</form>
</html>

</body>
</html>
I was hoping that you could help me fix the problem, as it continuesly says the following:
Code:
Parse error: syntax error, unexpected T_ELSE in C:\Documents and Settings\Bakhtawar\Desktop\saeedsite\driverpanel\_debug_tmp.php on line 22
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 11:01 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.