Jump to content

help with using $_GET['editid'] to display edit options


Jnerocorp

Recommended Posts

Hello,

 

I am developing an administration panel and have hand coded a very large administration page so everything would run out of 1 file  called admin.php

 

I am having trouble getting the part when I visit admin.php?editid=3

 

Here is the part of the code that this is placed:

<?php
if(isset($_GET['editid'])) {

$id = $_GET['editid'];
$report = $id;
mysql_query("SELECT * FROM clans WHERE id='$id'") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$clanname = $row['clanname'];
$logo = $row['logo'];
$status = $row['status'];

echo "<fieldset>
<legend> Edit Clan </legend>
<table>
<tr>
<form action='' method='post'>
<td>Clan name:</td><td><input type='text' name='clanname' value='".$clanname."'></td>
</tr>
<tr>
<td>Logo url:</td><td><input type='text' name='logourl' value='".$logo."'></td>
</tr>
<tr>
<td>Status:</td><td><input type='text' value='".$status."' disabled='true'></td>
</tr>
<tr>
<td></td><td><input type='submit' value='Update Clan info'></td>
</tr>
</table>
</form>
</fieldset>";

}


}
?>

 

 

And this is the code of the whole page:

<?php 
session_start(); 

mysql_connect("localhost", "jnero_admin", "sc55207") or die(mysql_error());
mysql_select_db("jnero_clanlist") or die(mysql_error());

#################################################
$username = "username";    # <=== # Admin Username #
$password = "password"; # <=== # Admin Password #
#################################################
$report = "-";
$devlink = " ";
// Start Login Codes
if(isset($_POST['submitlogin'])) {
if(isset($_POST['username'])) {

if(isset($_POST['password'])) {

if($username == $_POST['username']) {

if($password == $_POST['password']) {

$_SESSION['username'] = $_POST['username'];
$_SESSION['password'] = $_POST['password'];

$report = "You are now logged in";

} else { 
$report = "Incorrect Username/Password"; 
}

} else { 
$report = "Incorrect Username/Password"; 
}

} else { 
$report = "Password not Set"; 
}

} else { 
$report = "Username not Set"; 
}
}
// End Login Codes

//Start News Codes
if(isset($_POST['submitnews'])) {

if(isset($_POST['add'])) {
if(isset($_POST['newstitle']) && isset($_POST['newsinfo'])) {

$title = $_POST['newstitle'];
$info = $_POST['newsinfo'];


mysql_query("INSERT INTO news 
(id, title, info) VALUES('', '$title', '$info') ") 
or die(mysql_error());  

$report = "You have added a new news article called: $title";

} else {
$report = "Please Make Sure all News Fields are field";
}

}

if(isset($_POST['edit'])) {

if(isset($_POST['newstitle']) && isset($_POST['newsinfo'])) {

$title = $_POST['newstitle'];
$info = $_POST['newsinfo'];
$id = $_POST['id'];


mysql_query("UPDATE news SET title='$title' WHERE id='$id'") 
or die(mysql_error()); 

mysql_query("UPDATE news SET info='$info' WHERE id='$id'") 
or die(mysql_error()); 

  $report = "You have edited Aricle ID: $id";

} else {
$report = "Please Make Sure all News Fields are field";
}
}
}

if(isset($_POST['submitdeletenews'])) {

$id = $_POST['deletenews'];

mysql_query("DELETE FROM news WHERE id='$id'") 
or die(mysql_error());  

$report = "You have deleted News ID: $id";
}

//end News Codes

//Add Clan Codes

if(isset($_POST['addclan'])) {

$devlink = "<a href='./admin.php?addclan'>Click Here to Add a New Clan</a>";


}

if(isset($_POST['submitaddclan'])) {

if(isset($_POST['clanname'])) {

if(isset($_POST['clanlogo'])) {

$clanname = $_POST['clanname'];
$logo = $_POST['clanlogo'];
$status = $_POST['status'];

mysql_query("INSERT INTO clans 
(id, clanname, logo, status) VALUES('', '$clanname', '$logo', '$status' ) ") 
or die(mysql_error());  

$report = "You have added $clanname as a clan to your list.";


} else {
$report = "Clan Logo Not Set";
}

} else {
$report = "Clan not set";
}


}

if(isset($_POST['editclan'])) {
$id = $_POST['clans'];

$result = mysql_query("SELECT * FROM `clans` WHERE id='$id'") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$clanname = $row['clanname'];

$devlink = "<a href='./admin.php?editid=$id'>Click Here to Edit: $clanname stuff</a>";

}
}

if(isset($_POST['deleteclan'])) {

$id = $_POST['clans'];
$clanname = $_POST['nameclan'];

mysql_query("DELETE FROM clans WHERE id='$id'") 
or die(mysql_error());  

mysql_query("DELETE FROM members WHERE clanid='$id'") 
or die(mysql_error());  

$report = "You have deleted a clan: $clanname and all of its members!";

}

if(isset($_POST['clanwin'])) {
$id = $_POST['clans'];

$result = mysql_query("SELECT * FROM `clans` WHERE id='$id'") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$status = $row['status'];
$one = "1";
$newstatus = $status + $one;
$clanname = $row['clanname'];

mysql_query("UPDATE clans SET status='$newstatus' WHERE id='$id'") 
or die(mysql_error());

$report = "You have added +1 win to $clanname";

} 



}

if(isset($_POST['clanlose'])) {
$id = $_POST['clans'];

$result = mysql_query("SELECT * FROM `clans` WHERE id='$id'") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$status = $row['status'];
$one = "1";
$newstatus = $status - $one;
$clanname = $row['clanname'];

mysql_query("UPDATE clans SET status='$newstatus' WHERE id='$id'") 
or die(mysql_error());

$report = "You have added -1 loss to $clanname";


}
}

//end Add Clan Codes
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml" lang="en"><head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Clan List Admin Login</title>

<link href="admin.php_files/stylesheet.css" rel="stylesheet" type="text/css">

</head>

<body>
<div style="background-image: url('./admin.php_files/report.png'); background-repeat: repeat-x; "><?php echo $report; ?> </div>
<br>
<div style="background-image: url('./index_files/nav.gif'); background-repeat: repeat-x;"><?php include('nav.php'); ?> </div>
<?php
if(isset($_SESSION['username']) && isset($_SESSION['password'])) {
?>
<h1> Admin Panel </h1>

<?php
if(isset($_GET['addclan'])) {
?>
<fieldset>
<legend> Add a Clan</legend>
<form action="" method="post">
<table>
<tr>
<td>Clan Name:</td><td><input type="text" name="clanname"></td>
</tr>
<tr>
<td>Logo Link:</td><td><input type="text" name="clanlogo"></td>
</tr>
<input type="hidden" name="status" value="0">
<tr>
<td></td><td><input type="submit" name="submitaddclan" value="Add new clan"></td>
</tr>
</table>

</form>
  </fieldset>

<?php
}

if(isset($_GET['editid'])) {

$id = $_GET['editid'];
$report = $id;
mysql_query("SELECT * FROM clans WHERE id='$id'") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$clanname = $row['clanname'];
$logo = $row['logo'];
$status = $row['status'];

echo "<fieldset>
<legend> Edit Clan </legend>
<table>
<tr>
<form action='' method='post'>
<td>Clan name:</td><td><input type='text' name='clanname' value='".$clanname."'></td>
</tr>
<tr>
<td>Logo url:</td><td><input type='text' name='logourl' value='".$logo."'></td>
</tr>
<tr>
<td>Status:</td><td><input type='text' value='".$status."' disabled='true'></td>
</tr>
<tr>
<td></td><td><input type='submit' value='Update Clan info'></td>
</tr>
</table>
</form>
</fieldset>";

}


}
?>


<fieldset>
<legend> News Article Editor </legend>
<?php


$result = mysql_query("SELECT *
FROM `news`
WHERE id = (
SELECT MAX( id )
FROM `news` ) ") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {
$title = $row['title'];
$info = $row['info'];
$id = $row['id'];

echo "
<form action='' method='post'>
<input type='hidden' name='submitnews' value='submitnews'>
<input type='hidden' name='id' value='$id'>
<table>
<tr>
<td>Title:</td><td><input type='text' name='newstitle' value='$title'></td>
</tr>
<tr>
<td>Info</td><td><textarea name='newsinfo' rows='10' cols='100'>$info</textarea></td>
</tr>
<tr>
<td><input type='submit' name='edit' value='Edit Current News'></td><td><input type='submit' name='add' value='Add New News'></td>
</tr>
</table></form>";

}
echo "<form action='' method='post'><table>
<tr>
<td>Delete News:</td>
<td>
<select name='deletenews'>";

$result = mysql_query("SELECT * FROM `news` ORDER BY `id` DESC") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$title = $row['title'];
$id = $row['id'];

echo "<option value='$id'>$title</option>";

}


echo "</select></td></tr><tr><td><input type='submit' name='submitdeletenews' value='Delete News'></td></tr></table></form></fieldset>";

?>
<fieldset>
<legend> Clan Editor </legend>
<form action="" method="post">
<table>
<tr>
<td>Select a Clan: <select name="clans">
<?php
$result = mysql_query("SELECT * FROM `clans` ORDER BY `id` ASC") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$clanname = $row['clanname'];
$id = $row['id'];

echo "<option value='$id'>$clanname</option> ";

}

?>
</select></td>
<?php
$result = mysql_query("SELECT * FROM `clans` ORDER BY `id` ASC") or die(mysql_error());  
while($row = mysql_fetch_array( $result )) {

$clanname = $row['clanname'];

echo "<input type='hidden' value='$clanname' name='nameclan'> ";

}

?>

</tr>
<tr>
<td><input type="submit" name="addclan" value="Add Clan"></td>
</tr>
<tr>
<td><input type="submit" name="editclan" value="Edit Clan"> </td>
</tr>
<tr>
<td><input type="submit" name="deleteclan" value="Delete Clan"></td>
</tr>
<tr>
<td><input type="submit" name="clanwin" value="Clan win +1"> <input type="submit" name="clanlose" value="Clan lose -1"></td>
</tr>
<tr>
<td>Dev Link</td><td style="background: #000;"><?php echo $devlink; ?></td>
</tr>
<table>

</fieldset>


<?php
} 
if(!isset($_SESSION['username']) && !isset($_SESSION['password'])) { ?>
<form name="login" action="" method="POST">
  <fieldset>
    <legend>Admin Login</legend>
    <label class="loginLabel" for="username">Admin Username:</label>
<input style="float: left;" id="username" name="username" type="text">
<br class="clearBoth">
    <label class="loginLabel" for="password">Admin Password:</label>
<input style="float: left;" id="password" name="password" value="" type="password">
<br class="clearBoth">
    <input class="button" value="Login" type="submit" name="submitlogin">
    <a style="float: right;" href="mailto:[email protected]">[email protected]</a>  </fieldset>
</form>
<?php
}
?>

</body></html>

 

thanks for any help I have been  coding this by hand in notepad for the past 5  hours straight

 

-John

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.