Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

PHP CMS


ghost's Avatar
0 0

PHP CMS TROUBLE updated ive followed a tutorial for a php cms ok these are the folders i have

[ ] admin [ ] includes [ ] news.php

here are the contents of the admin folder

[ ] add-news.php
[ ] add-user.php
[ ] admin.php
[ ] check-user.php
[ ] delete-news.php
[ ] edit-news.php
[ ] edit-user.php
[ ] login.php

here is the contect of the includes folder [ ] connect.php

Ive created a usres table in mysql and also created a news table in mysql the files i am having trouble with are

[ ] delete-news.php
[ ] edit-news.php
[ ] edit-user.php
[ ] news.php

the erorr i get with delete-news.php is

markupParse error: parse error, unexpected $ in /home/www/php.arabian-outlaw.com/admin/pix/admin/delete-news.php on line 44

here is the code for this file

session_start();
if($login_username=="") {
Header("Location: login.php");
} else {
//The following PHP script deletes entries from your MySQL database..
//Connecting to the MySQL database
include("../includes/connect.php");

//Naming some variables here.
$id = $_GET['id'];
$id2 = $_POST['id'];


if($_POST['deny']) {
//We shall not delete the entry, my lord.
$path = "http://".$_SERVER['HTTP_HOST']."/edit.php";
header("Location: $path");
exit;
} elseif($_POST['confirm']) {
//We shall proceed to delete!
//Naming some variables here.

//The MySQl query. Deletes an entry from the database.
$query = "DELETE FROM news WHERE ID = '$id2'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "The entry has been deleted";
header("Refresh: 2; edit-news.php");
} else {
//OK, we've ID'd the thing, can we proceed Cap'n?
?>

<!-- Some tables for formatting and a form to confirm the deletion.-->
<table align="center">
<form action="delete.php" method="post">
<tr><td>Do you really want to delete this entry?</td></tr>
<tr><td><input type="hidden" name="id" value="<?php echo "$id"; ?>" /><input type="submit" name="confirm" value="Yes" /><input type="submit" name="deny" value="No" /></td></tr>
</form>
</table>
<?php
}
?>```


the error i get for edit-news.php is 

```markupParse error: parse error, unexpected '}', expecting ',' or ';' in /home/www/php.arabian-outlaw.com/admin/pix/admin/edit-news.php on line 77```

the code for this page is 

```markup<?php
session_start();
if($login_username=="") {
Header("Location: login.php");
} else {
//The following PHP script allows you to edit the
//contents of your MySQL table.
//Connecting to the MySQL database
include("../includes/connect.php");

//Should we show a single item or a list?
if($_POST['edit']) {
//Simplifying the variables.

$id = $_POST['id'];
$title = $_POST['title'];
$author = $_POST['author'];
$date = $_POST['date'];

$content = $_POST['content'];

//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$author = htmlspecialchars($author);


//The MySQL query which will update the content in the table.
$query = "UPDATE news SET title = '$title', author = '$author', date = '$date', content = '$content' WHERE ID = '$id'";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
echo "<center><strong>News item modified!</strong></center>";


} elseif($_GET['action'] == "edit") {
//Display a single result.
$id = $_GET['id'];
//The MySQL query. Select all from the table news where the ID equals the id sent in URL.

$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
?>
<form method="post" action="edit-news.php">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" value="<?php echo "$title"; ?>" maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" value="<?php echo "$author"; ?>" maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="<?php echo "$date"; ?>" maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10"><?php echo "$content"; ?></textarea></td></tr>

<tr><td> </td><td><input type="hidden" name="id" value="<?php echo "$ID"; ?>" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>

<?php
}
} else {
//Since we're not displaying a single result,
//we're going to display a list of results.

//The MySQl query. Selects all from the table news.
$query = "SELECT * FROM news ORDER BY ID DESC";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
echo "<table><tr><td><strong><a href='edit-news.php?action=edit&id=$ID'>$title</a></strong></td></tr>
<tr><td><small>Written by $author on $date</small></td></tr>

<tr><td><strong><a href='delete-news.php?id=$ID'>DELETE</a></strong></td></tr>"
}
?>

the error i get for edit-user.php is

Parse error: parse error, unexpected T_ELSE in /home/www/php.arabian-outlaw.com/admin/pix/admin/edit-user.php on line 31

the code for it is

// Make sure page is secure
session_start();
if($login_username=="") {
Header("Location: login.php");
} else {
// If it is then include file
include("../includes/connect.php");


if($_POST['submit']) {

$id = $_GET['id'];
$username = $_POST['username'];
$pw = $_POST['pw'];

//The MySQL query. Select all from the table users where the ID equals the id sent in URL.

$query = "SELECT * FROM users WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);

$query = "UPDATE users SET username = '$username', pw = '$pw' WHERE ID = '$id'";

echo "User modified.";
} else {

// Lets get into the code!

$query = "SELECT * FROM users ORDER BY ID DESC";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);

?>


<form method="post" action="<?php echo $_SERVER[PHP_SELF]; ?>">
<table align="center">
<tr>
  <td align="right">Username:</td>
  <td><input type="text" name="username" value="<?php echo "$username"; ?>" maxlength="250" /></td></tr>
<tr>
  <td align="right">Password:</td>
  <td><input type="text" name="pw" value="<?php echo "$pw"; ?>" maxlength="250" /></td></tr>

<tr><td> </td><td><input type="hidden" name="id" value="<?php echo "$ID"; ?>" /><input type="submit" name="edit" value="Modify" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>
<?php } } } ?>

the last error is for news.php (the news reader)

the code for that is

//The following PHP script queries and displays the contents of the MySQL table.

//Connecting to the MySQL database
include("includes/connect.php");

//Should we show a single item or a list?
if($_GET['action'] == "view") {
//Display a single result.
$id = $_GET['id'];
//The MySQL query. Select all from the table news where the ID equals the id sent in URL.

$query = "SELECT * FROM news WHERE ID='$id'";
//Executing the query.
$result = mysql_query($query) or die(mysql_error());
//Displaying the results of the query.
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.

extract($row);
//nl2br() translates all newlines ('n') as HTML tags.
$content = nl2br($content);
echo "<table><tr><td><strong>$title</strong></td></tr>
<tr><td><small>Written by $author on $date</small></td></tr>

<tr><td>$content</td></tr>";
}
} else {
//Since we're not displaying a single result,
//we're going to display a list of results.
//The MySQl query. Selects all from the table news with a limit of 5 results.

$query = "SELECT * FROM news ORDER BY ID DESC LIMIT 5";
//Execute the query.
$result = mysql_query($query) or die(mysql_error());
while ($row = mysql_fetch_array($result)) {
//extract() takes an associative array and treats the keys as variable names and values as variable values.
extract($row);

//nl2br() translates all newlines ('n') as HTML tags.
$content = nl2br($content);
echo "<table><tr><td><strong><a href="view.php?action=view&id=$ID">$title</a></strong></td></tr>
<tr><td><small>Written by $author on $date</small></td></tr>
<tr><td>$content</td></tr>";

}
}

?>```

ghost's Avatar
0 0

ok its updated


ghost's Avatar
0 0

I never knew that you knew PHP lol. ;)


ghost's Avatar
0 0

yeah im learning but right now i need help anyone?


ghost's Avatar
0 0

Edit you post and disable the smilies.

Than i can look at the code now it's messed up


ghost's Avatar
0 0

Problem number one is missing a } although I suggest you tab the code out so that you can see which one needs closing

Problem number two is that the final echo is missing the ";" at the end

Problem three there is a closing "}" missing on the while loop

Final problem corrected line

<tr><td><small>Written by $author on $date</small></td></tr>
<tr><td>$content</td></tr>";```