Current location: Hot Scripts Forums » Programming Languages » PHP » Php and Mysql


Php and Mysql

Reply
  #1 (permalink)  
Old 12-23-09, 07:06 AM
piotek piotek is offline
Newbie Coder
 
Join Date: Dec 2009
Posts: 6
Thanks: 4
Thanked 0 Times in 0 Posts
Php and Mysql

Damn! Sorry bad name of topic - should be "PHP and Mysql function"

Well. From my other topic I have problem with adding reply to my forum but few members helping me and its ok now.
I have some question too. I would like to add privilages to not delete topics for guest and only I will do that. The "........" are info about database like name, password etc. This is codes of delete files:
delete_ac.php:
Code:
..........
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$id=$_GET['id'];

// Delete data in mysql from row that has this id
$sql="DELETE FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);

// if successfully deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='delete.php'>Back to main page</a>";
}

else {
echo "ERROR";
}

// close connection
mysql_close();

?>
delete.php


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

// select record from mysql
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);

?>
<table width="400" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form id="form1" name="form1" method="post" action="delete.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td width="14%"><strong>Topic</strong></td>
<td width="2%">:</td>
<td width="84%"><input name="topic" type="text" id="topic" size="50" /></td>
</tr>
<tr>
<td valign="top"><strong>Detail</strong></td>
<td valign="top">:</td>
<td><textarea name="detail" cols="50" rows="3" id="detail"></textarea></td>
</tr>
<tr>
<td><strong>Name</strong></td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50" /></td>
</tr>
<tr>
<td><strong>Email</strong></td>
<td>:</td>
<td><input name="email" type="text" id="email" size="50" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
</table>
</td>
</form>
</tr>
</table>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Detail']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Name']; ?></td>
<td bgcolor="#FFFFFF"><? echo $rows['Email']; ?></td>
<td bgcolor="#FFFFFF"><a href="delete_ac.php?id=<? echo $rows['id']; ?>">delete</a></td>
</tr>
<?

// close while loop
}

// close connection;
mysql_close();

?>
</table></td>
</tr>
</table>
Now what I think the delete function must be in new column with posted topic. Like this:

[ test topic ] [ views ] [ replys ] [ date/time ] [ "delete button" ]

The form in bold should be added to base in column. I cant find how to add another column.

Last edited by piotek; 12-23-09 at 07:12 AM.
Reply With Quote
  #2 (permalink)  
Old 12-28-09, 11:48 AM
ruteckycs's Avatar
ruteckycs ruteckycs is offline
Coding Addict
 
Join Date: Jul 2009
Posts: 377
Thanks: 6
Thanked 10 Times in 10 Posts
I know nothing about how you code works or how you database is structured .. however if I were to do this, I would have a field in my members table that has a privilege level I would then check this prior to allowing the delete code to run.
__________________
This post was created with 100% recycled electrons.
Reply With Quote
  #3 (permalink)  
Old 12-28-09, 12:56 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Quote:
The form in bold should be added to base in column. I cant find how to add another column.
Start with this link: HTML table tag, it will explain how to add another column.
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

Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP or PHP which is better? nepala The Lounge 9 07-14-10 05:48 AM
PHP and MySQL ? rob2132 Hot Scripts Forum Questions, Suggestions and Feedback 4 08-29-08 02:22 AM
PHP not recognizing admin in MySQL gizelle Database 3 04-15-07 08:39 PM
Php Mysql Bug??? tranquilraven PHP 4 03-01-06 03:06 AM
Need help with some php mysql TheTinkeringToad PHP 9 02-01-06 10:56 AM


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