home hardware prices news articles forums photos user reviews
Go Back   Tech Support Forums - TechIMO.com > PC Hardware and Tech > Webmastering and Programming
Join TechIMO for Free!
Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read
Reply Get bargains at  »  Dealighted.com
 
Thread Tools
Currently Active Users: 1710
Discussions: 188,402, Posts: 2,243,609, Members: 232,632
Old April 19th, 2005, 07:14 PM   Digg it!   #1 (permalink)
Member
 
Join Date: Feb 2005
Location: CA
Posts: 99
Send a message via AIM to Matrix0978
PHP Admin Panel

ok well my friend as for a admin control panel for a news system so i decided to make it for him. Now when i go to to admin panel and then i type in what i want for updated news, i click submit, it goes to MySQL, then shows up on the website and were all happy. The problem is now i cant edit it. I go to the edit/delete area, and it shows the news i have posted, and when i try and edit or delete it, it wont do anythign. It doesnt edit or delete the post i would like. Here is the code for the input.php.

Code:
<?php 


 * *$linkID = mysql_connect('localhost', 'username', 'password') 

 * * * *or die("Error, database not accessing!"); 

 * *mysql_select_db('database',$linkID); 

 * *if(IsSet($_POST['Submit'])) 

 * *{ * 

 * * 

 * * * *for($i = 1;;$i++) 

 * * * *{ 

 * * * * * *$query = "SELECT * FROM `news` WHERE `id` = '$i'"; 

 * * * * * *$result = mysql_query($query, $linkID) 

 * * * * * * * *or die(mysql_error()); 

 * * * * * * 

 * * * * * * * * * * * *if(mysql_num_rows($result) == 0) 

 * * * * * * * *break; 

 * * * *} 

 * * * * 

 * * * *$date = getdate(); 

 * * * *$date = $date['year'].'-'.$date['mon'].'-'.$date['mday'].'-'.$date['hours']. 

 * * * * * * * * * ':'.$date['minutes'].':'.$date['seconds']; 

 * * * * 

 * * * *$query = "INSERT INTO `news` (`news`, `id`, `entry_time`) 

 * * * * * * * * * VALUES ('".$_POST['new_news']."', '$i', '$date')"; 

 * * * *$result = mysql_query($query, $linkID) 

 * * * * * *or die(mysql_error()); 

 * * * * 

 * *} 


 * *$num_of_news = $_POST['num']; 

 * * 



 * *for($i = 1; $i <= $num_of_news; $i++) 

 * *{ 

 * * * *if(isset($_POST['edit'.$i])) 

 * * * *{

 * * * * * *$query = "UPDATE `news` SET `news` = '".$_POST['news'.$i]."' 

 * * * * * * * *WHERE `id` = '".$_POST['id'.$i]."'"; 

 * * * * * *$result = mysql_query($query, $linkID) 

 * * * * * * * *or die(mysql_error()); 

 * * * *} 

 * * * *if(isset($_POST['delete'.$i])) 

 * * * *{

 * * * * * *$query = "DELETE FROM `news` WHERE `id` = '".$_POST['id'.$i]."'"; 

 * * * * * *$result = mysql_query($query, $linkID) 

 * * * * * * * *or die(mysql_error()); 

 * * * *} 

 * *}; 


 * *$i = 0; 

 * * * *

 * *$query = "SELECT * FROM `news` ORDER BY `entry_time` DESC"; 

 * *$result = mysql_query($query, $linkID) 

 * * * *or die(mysql_error()); 

 * *echo '<table>'; 

 * *while($row = mysql_fetch_array($result)) 

 * *{ 

 * * * *$i++; 



 * * * *echo '<tr><td><textarea name = "news'.$i.'" cols="100" rows="5">'.$row['news'].' 

 * * * * * * * * </textarea></td></tr> 

 * * * * <tr> 

 * * * * * *<td> 

 * * * * * * * *<input name="edit'.$i.'" type="submit" id="edit" value="edit"> 

 * * * * * * * *<input name="delete'.$i.'" type="submit" id="delete" value="delete"> 

 * * * * * * * *<input name="id'.$i.'" type="hidden" value="'.$row['id'].'"> 

 * * * * * *</td> 

 * * * *</tr>'; 

 * *} 

 * *

 * *echo '</table> 

 * *<input type = "hidden" name = "num" value = "'.$i.'">'; 

 * * 

?>
Ignore the Stars!!!
Anything wrong?
__________________
http://s9.invisionfree.com/wdf/index.php?act=idx
Web Development forum -----^


Last edited by Matrix0978 : April 19th, 2005 at 07:17 PM.
Matrix0978 is offline   Reply With Quote
Old April 20th, 2005, 01:20 AM     #2 (permalink)
Ultimate Member
 
Join Date: Dec 2004
Posts: 1,558
Try this:
PHP Code:
<?php 
  $linkID 
mysql_connect('localhost''username''password')
    or die(
"Error, database not accessing!");
  
mysql_select_db('database',$linkID);

  if(IsSet(
$_POST['Submit'])){
    for(
$i 1;;$i++){
      
$query "SELECT * FROM news WHERE id = '$i'";
      
$result mysql_query($query$linkID)
        or die(
mysql_error());
          if(
mysql_num_rows($result) == 0)
            break;
    }

    
$date getdate(); 
    
$date $date['year'].'-'.$date['mon'].'-'.$date['mday'].'-'.$date['hours'].
            
':'.$date['minutes'].':'.$date['seconds'];

    
$query "INSERT INTO news (news, id, entry_time)
           VALUES ('"
.$_POST['new_news']."', '$i', '$date')";

    
$result mysql_query($query$linkID)
      or die(
mysql_error());
  } 

  
$num_of_news $_POST['num'];

  for(
$i 1$i <= $num_of_news$i++){
    if(isset(
$_POST['edit'.$i])){
      
$query "UPDATE news SET news = '".$_POST['news'.$i]."'
               WHERE id = '"
.$_POST['id'.$i]."'";
      
$result mysql_query($query$linkID)
        or die(
mysql_error());
    }
    if(isset(
$_POST['delete'.$i])){
      
$query "DELETE FROM news WHERE id = '".$_POST['id'.$i]."'";
      
$result mysql_query($query$linkID)
        or die(
mysql_error());
    }
  };

  
$i 0;

  
$query "SELECT * FROM news ORDER BY entry_time DESC";

  
$result mysql_query($query$linkID)
    or die(
mysql_error());

  echo 
'<table>';

  while(
$row mysql_fetch_array($result)){
    
$i++;
    echo 
'<tr><td><textarea name = "news'.$i.'" cols="100" rows="5">'.$row['news'].'
         </textarea></td></tr>
     <tr>
      <td>
        <input name="edit'
.$i.'" type="submit" id="edit" value="edit">
        <input name="delete'
.$i.'" type="submit" id="delete" value="delete">
        <input name="id'
.$i.'" type="hidden" value="'.$row['id'].'">
      </td>
    </tr>'
;
  }

  echo 
'</table>
  <input type = "hidden" name = "num" value = "'
.$i.'">';

?>
I'm not sure if it'll fix your problem because I don't really have any way to test it.

Oh, and when you post php code here, you can use the [php] tags to have it higlighted.
__________________
"Be quiet, Brain, or I'll stab you with a Q-tip"
-Homer Simpson

large_nostril is offline   Reply With Quote
Reply


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

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

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
index.php?mode=something.php RyanD Webmastering and Programming 16 October 20th, 2004 11:20 PM
Win2K problem, logged in as admin, but still cant do admin stuff buddhafest Applications and Operating Systems 13 December 29th, 2003 08:41 PM

Most Active Discussions
Is It Just Me? (2906)
3-days in and no threads about Gaza (161)
Misery Loves Company... (2144)
New Build ( Finally ) (7)
CPU wont boot (7)
Building a gaming computer advice (5)
I think I just killed my computer w.. (24)
RCA 52Inch HDTV wont turn on (5)
Folderchat Weekday thread (444)
Recent Discussions
Futronix has water features? (0)
Laptop proccesor to desktop mob.. (2)
Please help! multiple problems! (4)
RCA 52Inch HDTV wont turn on (5)
New Build ( Finally ) (7)
Common Spyware Solutions (97)
How do you move a hard-drive to.. (4)
What is the best external enclo.. (0)
Partition Magic 7.0 (Unallocate.. (17)
Blackberry Storm, Gears of War .. (1)
Core 2 Quad Q9550 system (3)
COWBOOM Ripoff! Used Laptop w/$.. (4)


All times are GMT -4. The time now is 04:44 AM.
TechIMO Copyright 2008 All Enthusiast, Inc.



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28