Web designing newb. Creating a PHP forum from scratch!

delete1cs4.jpg


Right guys, I'm having a problem with deleting users. Basically, I have an ID which you select and when I press delete, the page refreshes but no member is deleted from the database.

Below is the php for the button, checkbox and the delete command:

Code:
<input class="button" name="delete" type="submit" id="delete" value="delete">
---------------------------------------------------------------------------
<td align="center" bgcolor="#000000"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
---------------------------------------------------------------------------

<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful redirect to delete_multiple.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=deleteuser.php\">";
}
}
mysql_close();
?>
I'd appreciate any advice as per usual :(
 
That didn't work Matt. Sorry I should have included more php, I did indeed have a form, but the method was set to post instead of get? Not that it made a difference, is there any reason in particular to my method?

Talbs, care to elaborate?
 
Right, it's not even echo'ing anything after if result is successful.

Code:
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
?>

//A fair amount of html stuff . . 

<?php
while($rows=mysql_fetch_array($result))
{ // Start looping table row
?>

<tr>
<td>&nbsp;</td>
<td align="center" bgcolor="#000000"><? echo $rows['id']; ?></a><BR></td>
<td align="center" bgcolor="#000000"><? echo $rows['myusername']; ?></td>
<td align="center" bgcolor="#000000"><? echo $rows['email']; ?></td>
<td align="center" bgcolor="#000000"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td>
<tr>
</tr>
<?php
}
?>
<table align="center" class="t8">
<tr>
<td align="right" ><input class="button" name="delete" type="submit" id="delete" value="Delete"></td>
</tr>
</table>
<?
// Check if delete button active, start this
if($delete){
for($i=0;$i<$count;$i++){
$del_id = $checkbox[$i];
$sql = "DELETE FROM $tbl_name WHERE id='$del_id'";
$result = mysql_query($sql);
}

// if successful echo WTF ffs etc
if($result){
echo "wtf";
}
}
mysql_close();
?>

</form>
</table>
 
snip

1) also place this code before you run the query that gets the results for the table display. i think the reason for that is obvious. :p

2) also, i'm assuming you have to be logged on as admin to view this page, so i haven't bothered with sanitising input. :)
That method worked a treat, thanks :)


A couple of questions:

1) It seems to be working using the same structure as above. When I budge things up, it gets upset. Any reason in particular for your reason? Seems to be working fine at the moment.

2) Unfortunately, I'm yet to have admin features added. I have the following plan of attempting to do so:
i) Create an extra column in the members db which differentiates admins from normal users (all users default to normal users)​
ii) Have a statement on every page like sessions, to check if user is an admin. If so, display the extra powers.​


What do you think?

Thank you for your input talbs, nice to gain more knowledge :)
 
is it not blindingly obvious? :confused:

you must process the deletion of users before running the query to display all users, otherwise you're going to be displaying users that are no longer in the database by time the page has finished loading.

Isn't it okay the way it is?

Code:
Connect to DB

Select * from tbl_name

html

Start looping table row

html

Finish looping table row

Functional buttons

Run the for loop

It works fine this way, as I see it the following way:

Code:
Retrieve

Delete

Refresh
That does not display any deleted members, all my 20 pages of php are done in a similar fashion.
 
Thanks Marc, I'll look into that if I get time.

I've managed to book holidays for this weekend. Deadline is for Monday and I have a lot of work lined up for me! Wish me luck :)
 
Thanks for the input . . I've gone too far into the design, there's no chance of a revamp, it's only for an assignment, once it's marked it shall be archived for reference :)

A quick one . . Once a user logs in and comes back to the main page, how would I go about customising the page? For example, when a guest visits the forum they can select the logout option which is merely pointless. However, I'd like to tailor it so that guests can only see limited options.

I've also managed to sort out registration confirmation emails! :)

Now the following to go:
1) Avatars
2) Admin/Normal users
3) Editing posts
4) Quoting posts​

I haven't got time for validation as we were hinted they wouldn't check but recommended we should do so.
 
Last edited:
Bah, not long to go and not doing too well.

I've created a control panel which allows a user to insert a url for an avatar, however I've now become confused :\

Code:
<!-- Connect shizzle -->

$myusername=$_SESSION['myusername'];
$avatar=$_POST['avatar'];

$sql="INSERT INTO $tbl_name(myusername, avatar)VALUES('$myusername', '$avatar')";
$result=mysql_query($sql);

<!--My table/form etc . .-->
That just screams wrong to me, How would I make it read the appropriate username and then insert a url?
 
Awesome it's now storing :)

However, what's the best way to tackle this?

I have 3 tables . . create thread - create reply - members

My view thread displays the original post and then replies after it. Should I just echo the avatar corresponding to the member ID?

Thanks once again Marc :D
 
I've got 6 results tables now in my view thread. Should it be along these lines?:

Code:
<?php
$tbl_name2="members"; // Switch to table "members"

$sql2="SELECT * FROM $tbl_name2 WHERE avatar='$avatar'";
$result2=mysql_query($sql2);

?>

Code:
<td>&nbsp;<img src="$avatar['avatar]" width="62" height="80" alt="Avatar" border="0" />&nbsp;</a></td>
 
It 'should' be however, my layout is posing a large problem.

Code:
Connect to DB

Retrieve original thread details 

Display header table and all usual html stuff

*Connect to table members, to retrieve avatar info* ~This is the one where everything messes up~

HTML/CSS display original post

Connect to table 'create reply'

Retrieve reply details if they exist

Retrieve data and add views

Then add replies if done

Quick reply box

I've learnt from my errors, however now time is running out so I have to make do with what I have now :\
 
That's fair enough then. Next time though, you may want to keep an ordered CSS file. Maybe even use different stylesheets for different elements of the design. This will make it easier to change the appearance of the site, and a hell of a lot quicker. :)

Good luck with. Been following with interest. :)
Thank you for your input. I always used to be very keen about learning CSS someday, especially when I found your site back in the days . . .it was very inspiring :)

Hopefully, I'll starting teaching myself more stuff. I've bookmarked a number of resources that I intend to go back to :)

All in, I'm very pleased with what I managed to knock up, albeit breaking a number of rules and a few things that consist of 'bad practice' but it's all a part of the learning curve I suppose.

Feel like bit of a pillock, I've spent a stupid amount of hours, infact I've never in my life spent so much time on a project. If everything went to plan I could have been looking at 90%. I'm going to try my best but I don't think I can finish what I intended to do, I've been going through the process of trial and for hours and it just isn't working out :(
 
Code:
*Connect to table members, to retrieve avatar info* ~This is the one where everything messes up~

well you'd need to get the avatar for every post - and this is what i don't get.... where are you getting the username from?? if you can get the username, why can't you get the avatar?

Because of the following reason:

Create_reply constsis of:
reply id
a id
myusername
a reply
a datetime

create_thread:
id
topic
detail
myusername
datetime
view
reply

members:
myusername
mypassword
email
avatar

The top 2 use sessions in order to retrieve myusername.

I've made a mess of things, I exhausted most of my efforts and i'm still trying!

So . . .

> create thread contains all its information
> create reply keep stacking in view thread, both are present in order to make a thread
> members are used share information above such as myusername and in order to post
 
Still having problems

Code:
<td>&nbsp;<img src="' . $avatar[$myusername] . "';/></td>
<td>&nbsp;<? echo $rows['avatar']; ?></td>
I've tried echo's just the avatar url but it seems it isn't communicating with the db.

At the very I have following defined:

Code:
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name=""; // Database name
$tbl_name="create_thread"; // Table name



// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];
$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);

?>

Bit of html stuff . . and then

Code:
<div>
<? echo $rows['datetime']; ?>
</div>
</td>
</tr>
<?php
$tbl_name2="members"; // Table name


$result2 = mysql_query("SELECT * FROM members");
while($row = mysql_fetch_assoc($result2)) {
    $avatar[$row['myusername']] = $row['avatar'];
}
?>

<td>
<!-- user info -->
<table class="t5" cellspacing="6" >
<tr>
[B]<td>&nbsp;<img src="' . $avatar[$myusername] . "';/></td>
<td>&nbsp;<? echo $rows['avatar']; ?></td>
<td class="bigusername"><? echo $rows['myusername']; ?></td>[/B]
<td width="100%">&nbsp;</td>
<td valign="top" nowrap="nowrap">
<div></div>
</div> 
</td>
</tr>
</table>
</td>

Thanks once again marc.
 
Last edited:
Starting to make some progress, it's only displaying the same image for all users, in the db 2 users have different avatars set, yet it's only showing one :\
 
This is really retarded :\

Every member has to have an avatar and even then it will only display 1 image and that was whatever was most recently added to the db :confused:
 
Back
Top Bottom