Edit Users and News

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
brbsta
Forum Newbie
Posts: 4
Joined: Mon Sep 01, 2003 10:33 am
Location: USA

Edit Users and News

Post by brbsta »

I have a php news program made that has levels of login to post in different areas. I got everything working except I cannot edit anything, users or the news. I got these files:

FOR USER EDIT
1st page:
http://www.rct2unlimited.com/admin/edituser.php
on page - Please click on a username to edit user:
brbsta
code in page-
<?php
include "secure.php";
include "config.php";
//change $nlev to the level needed to access page
$nlev = 0;
if ($lev >= $nlev) {

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
/* We have now connected, unless you got an error message */
/* Lets display the current titles, so we can select one for editing */
echo "<b>Please click on a username to edit user:</b><BR>";
$query = "SELECT * FROM admin";
$result = mysql_query($query);
/* Here we fetch the result as an array */
while($r=mysql_fetch_array($result))
{
/* This bit sets our data from each row as variables, to make it easier to display */
$id=$r["uid"];
$title=$r["username"];
/* Now lets display the titles */
echo "<A HREF=\"editu1.php?id=$id\">$title</A><BR>";
}
mysql_close($db);
} else {
print "Sorry, you do not have the required access levels";
}
?>
Then next page to get a user is http://www.rct2unlimited.com/admin/editu1.php?id=12 :

On the page are the fields to edit them and the code is:
<?php
include "secure.php";
include "config.php";
//change $nlev to the level needed to access page
$nlev = 0;
if ($lev >= $nlev) {

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
/* We have now connected, unless you got an error message */
/* We now select one news post, and bring it into some text boxes */
$query = "SELECT * FROM admin WHERE uid = $_GET[id]";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
/* This bit sets our data from each row as variables, to make it easier to display */
$title=$r["username"];
$news=$r["password"];
$email=$r["email"];
/* Now lets display the titles */
echo '<form name="edit_process.php" method="post" action="editsave.php?id=$_GET[id]">
<p>Username:
<input type="text" name="title" value="'.$title.'">
</p>
<p>password:</p>
<p>
<input type"text" name="password" value="'.$news.'">

</p>
<p>
email:<input type"text" name="email" value="'.$email.'">
<p>
<input type="submit" name="Submit" value="Save">
</p>
</form>';
}

} else {
print "Sorry, you do not have the required access levels but infact have".$lev; }
?>
Then after that page is http://www.rct2unlimited.com/admin/edit ... d=$_GET[id]

The code on that page is:
<?php
include "secure.php";
include "config.php";
//change $nlev to the level needed to access page
$nlev = 3;
if ($lev >= $nlev) {

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
/* We have now connected, unless you got an error message */
/* Lets save some news ! */
$query = "UPDATE admin SET usernameusername='".$_POST['title']."',
password='".$_POST['news']."', email='".$_POST[password]."' WHERE uid = '".$_GET['id']."'";
mysql_query($query);
echo "User updated";
mysql_close($db);
} else {
print "Sorry, you do not have the required access levels but infact have".$lev;
}
?>
But in the end it dosnt update the user.


Here is what i have for the news edit:

2nd page is http://www.rct2unlimited.com/admin/edit1.php?id=7, where u edit all the fields
The code is:
<?php
include "secure.php";
include "config.php";
//change $nlev to the level needed to access page
$nlev = 0;
if ($lev >= $nlev) {

$db = mysql_connect($db_host,$db_user,$db_pass);
mysql_select_db ($db_name) or die ("Cannot connect to database");
/* We have now connected, unless you got an error message */
/* We now select one news post, and bring it into some text boxes */
$query = "SELECT title, news FROM news WHERE id = $_GET[id]";
$result = mysql_query($query);
while($r=mysql_fetch_array($result))
{
/* This bit sets our data from each row as variables, to make it easier to display */
$title=$r["title"];
$news=$r["news"];
/* Now lets display the titles */
echo "<form name=\"edit_process.php\" method=\"post\" action=\"edit_save.php?id=$_GET[id]\">
<p>Title :
<input type=\"text\" name=\"title\" value=\"$title\">
</p>
<p>News :</p>
<p>
<textarea name=\"news\" cols=\"40\" rows=\"6\">$news</textarea>
</p>
<p>
<input type=\"submit\" name=\"Submit\" value=\"Save\">
</p>
</form>";
}
mysql_close($db);
} else {
print "Sorry, you do not have the required access levels";
}
?>
3rd page is the save page, http://www.rct2unlimited.com/admin/edit_save.php?id=7

Code is:
Well there is no code and i really dont knowhow to write 1 could u help me out there
Im sorry about the long post and everything but i am REALLY new at this and have no idea what i am really doing and why it wont work. Any help you be GREAT.

Thanks
Brbsta
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Do you get any error messages?

Mac
brbsta
Forum Newbie
Posts: 4
Joined: Mon Sep 01, 2003 10:33 am
Location: USA

Post by brbsta »

Nope get no errors
Post Reply