April 19th, 2005, 07:14 PM
|
#1 (permalink)
| | Member
Join Date: Feb 2005 Location: CA
Posts: 99
|
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?
Last edited by Matrix0978 : April 19th, 2005 at 07:17 PM.
|
| |
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
|
| | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |
Posting Rules
| You may post new threads You may post replies You may not post attachments You may not edit your posts HTML code is Off | | | | Most Active Discussions | | | | | Recent Discussions  | | | | | |