Jump to content

Help me with blog please.


Saturnfirefly

Recommended Posts

Hi!
My english isn't good, so i cant say much. I need help with a blog-script i got from my friend, he cant do better so please help me with this script.
I'm not good at php so please, please help me.
Please dont remove any html-codes... it helps me to find everything.
Thanx!

Index of blog.
[code]<div id="content">
<?php
session_start();
include "conn.php"; // Databasanslutningen
if (isset($_GET['ny_nyhet'])){
if (isset($_SESSION['sess_firefly'])){
echo "<h1>Skriv en ny nyhet:</h1>";
if (isset($_POST['submit'])){
$date = date("Y-m-d H:i:s");
  // Tag bort eventuella blanksteg i början eller slutet
  foreach($_POST as $key => $val){
    $_POST[$key] = trim($val);
  }
$sql = "INSERT INTO firefly_news(av, nyhet, rubrik, date, cat)
            VALUES('{$_SESSION['sess_firefly']}', '{$_POST['nyhet']}', '{$_POST['rubrik']}', '{$date}', '{$_POST['cat']}')";
    mysql_query($sql) or die("sql: $sql<br/>".mysql_error());

    echo "En ny nyhet är klar =)";
    exit;
  }


?>

Skriv en ny nyhet!
<form action="index.php?ny_nyhet=" method="post">
<table cellspacing="3">
<?php
$result = @mysql_query("SELECT * FROM firefly_news_cat")
  or die("Error fetching data<br>".mysql_error());
    echo '
<select name="cat">

<option selected value="Välj här!">Välj här!</option>';
while ($row = @mysql_fetch_array($result)){
    echo '
<option value="'.$row['id'].'">'.$row['rubrik'].'</option>
';
}
echo '</select>';
?>
<tr>
<td>Rubrik:</td>
<td><input type="text" name="rubrik" value=""></td>
</tr>
<tr>
<td></td>
<td><textarea cols="35" rows="10" name="nyhet"></textarea></td>
</tr>


<tr>
<td colspan="2" align="center">
  <input type="submit" name="submit" value="Spara!">
</td>
</tr>

</table>
</form>


<?php

}
}elseif (isset($_GET['ny_nyhets_cat'])){
if (isset($_SESSION['sess_firefly'])){
echo "<h1>Skapa en ny nyhets kategorie:</h1>";
if (isset($_POST['submit'])){
  // Tag bort eventuella blanksteg i början eller slutet
  foreach($_POST as $key => $val){
    $_POST[$key] = trim($val);
  }
$sql = "INSERT INTO firefly_news_cat(rubrik)
            VALUES('{$_POST['rubrik']}')";
    mysql_query($sql) or die("sql: $sql<br/>".mysql_error());

    echo "En ny nyhets kategorie är klar =)";
    exit;
  }


?>
Skapa en ny kategorie till nyheterna
<form action="index.php?ny_nyhets_cat=" method="post">
<table cellspacing="3">


<tr>
<td>Namn på kategorin:</td>
<td><input type="text" name="rubrik" value=""></td>
</tr>


<tr>
<td colspan="2" align="center">
  <input type="submit" name="submit" value="Spara!">
</td>
</tr>

</table>
</form>

<?php

}
}elseif (isset($_GET['comment'])){

include "conn.php"; // Databasanslutningen
$resultt= @mysql_query("SELECT * FROM firefly_news WHERE id = {$_GET['comment']}")
  or die("Error fetching data<br>".mysql_error());
while ($row = @mysql_fetch_array($resultt)){
echo '
<h3> '.$row['rubrik'].'</h3></font></b>
<font face="arial" color="888888" size="1"> Written by:  '.$row['av'].' | '.$row['date'].'<br><br></font>
'.nl2br($row['nyhet']).'<br><br><font size="2"> Comments on "'.$row['rubrik'].'".</font> ';
echo '<br>';
if (isset($_SESSION['sess_firefly'])){
echo '<a href="index.php?edit='.$row['id'].'">Ändra</a>';
}
}

echo '<br>';
$result = @mysql_query("SELECT * FROM firefly_com WHERE nyhet = {$_GET['comment']} ORDER by id DESC")
  or die("Error fetching data<br>".mysql_error());
if (mysql_num_rows($result) == 0) {
echo "<i>No comments yet =(.</i><br><br>";
}else{
while ($row = @mysql_fetch_array($result)){
echo 'From:<b> <a href="mailto:' . $row['mail'] . '">' . $row['av'] . '</a> ' .$row['date'] . ' <br></b> ' . nl2br($row['text']) . '';
echo '<br>';
if (isset($_SESSION['sess_firefly'])){
echo '<a href="index.php?del='.$row['id'].'">Ta bort denna kommentar</a>';
}
echo '<br><br>';
}
}


$date = date("Y-m-d H:i:s");

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

    $sql = "INSERT INTO firefly_com(nyhet, av, text, date, mail)
            VALUES('{$_GET['comment']}', '{$_POST['namn']}', '{$_POST['kom']}', '{$date}', '{$_POST['email']}')";
    mysql_query($sql)
        or die("Error fetching data<br>".mysql_error());
              echo 'Din kommentar blev postad utan problem! <a href="index.php">Gå tillbaka till startsidan</a>';
    exit;    

}
?>

<?php
echo '
<form method="post" action="' . $_SERVER['REQUEST_URI'] . '">
';
?>
Namn:<br>
<input type="text" name="namn" value=""><br>
Din email adress:<br>
<input type="text" name="email" value=""><br>
Kommentar:<br>
<textarea cols="35" rows="10" name="kom"></textarea><br>
<input type="submit" name="post" value="Kommentera!">

</form>
<?php
}elseif (isset($_GET['edit'])){
if (isset($_SESSION['sess_firefly'])){
echo "<h1>Ändra nyheten:</h1>";
// Tag bort eventuella blanksteg i början eller slutet
  foreach($_POST as $key => $val){
    $_POST[$key] = trim($val);
  }
if(isset($_POST['su']))
{
$sql = "UPDATE firefly_news

        SET rubrik = '".$_POST['rubrik']."',
                nyhet = '".$_POST['nyhet']."'
        WHERE id = '{$_GET['edit']}'";
            
mysql_query($sql) or die("SQL: $sql <br>".mysql_error());
echo "Nyheten är nu ändrad!";
   exit;
}
$sql = "SELECT * FROM firefly_news WHERE id = '{$_GET['edit']}'";
$result = mysql_query("$sql") or die("$sql funkade inte...");
while($rad = mysql_fetch_array($result))
{
echo '
<form method="POST" action="' . $_SERVER['REQUEST_URI'] . '"><input type="hidden" name="id" value="'.$_GET['edit'].'">
Rubrik:<br>
<input type="text" name="rubrik" value="'.$rad['rubrik'].'" size="20">
<br>Nyheten:<br>
<textarea cols="35" rows="10" name="nyhet">'.$rad['nyhet'].'</textarea>
<input type="submit" name="su" value="Spara">
</form>
';
}
}
}elseif (isset($_GET['del'])){
if (isset($_SESSION['sess_firefly'])){
$sql = "DELETE FROM firefly_com WHERE id = ".intval($_GET['del']);
mysql_query($sql);

echo "Kommenteren är nu borttagen =(";
exit;
}
}elseif (isset($_GET['del_news'])){
if (isset($_SESSION['sess_firefly'])){
$sql = "DELETE FROM firefly_news WHERE id = ".intval($_GET['del_news']);
mysql_query($sql);

echo "Nyheten är nu borttagen =(";
exit;
}
}elseif (isset($_GET['arkiv'])){
if (isset($_GET['id'])){

$query = mysql_query("SELECT * FROM firefly_news WHERE cat = '{$_GET['id']}' ORDER BY id DESC")
or die(mysql_error());

while($row = mysql_fetch_array($query))
{

$queryy = mysql_query("SELECT * FROM firefly_com WHERE nyhet = '{$row['id']}'")
or die(mysql_error());
$antal=mysql_num_rows($queryy);

echo '
<h3> '.$row['rubrik'].'</h3></font></b>
<font face="arial" color="888888" size="1"> Written by: '.$row['av'].' | '.$row['date'].'<br><br></font>
'.nl2br($row['nyhet']).'<br> <img src="underline.gif">';
echo '<a href="index.php?comment='.$row['id'].'"><font face="arial" size="1"> <img border="0" src="postcomment.gif"> Comment ('.$antal.') </a></font></a>';
echo '<br>';
if (isset($_SESSION['sess_firefly'])){
echo '<a href="index.php?edit='.$row['id'].'">Ändra</a>';
echo '<br><a href="index.php?del_news='.$row['id'].'">Ta bort denna nyhet</a>';
}
echo '<br><br>';
}
}else{

$query = mysql_query("SELECT * FROM firefly_news ORDER BY id DESC")
or die(mysql_error());

while($row = mysql_fetch_array($query))
{

$queryy = mysql_query("SELECT * FROM firefly_com WHERE nyhet = '{$row['id']}'")
or die(mysql_error());
$antal=mysql_num_rows($queryy);

echo '
<h3> '.$row['rubrik'].'</h3></font></b> <img src="underline.gif"> <img src="underline.gif">
<font face="arial" color="888888" size="1"> Written by: '.$row['av'].' | '.$row['date'].'<br><br></font>
'.nl2br($row['nyhet']).'<br> <img src="underline.gif">';
echo '<a href="index.php?comment='.$row['id'].'"><br><font face="arial" size="1"> <img border="0" src="postcomment.gif"> Comment ('.$antal.') </a></font></a>';
echo '<br>';
if (isset($_SESSION['sess_firefly'])){
echo '<a href="index.php?edit='.$row['id'].'">Ändra</a>';
echo '<br><a href="index.php?del_news='.$row['id'].'">Ta bort denna nyhet</a>';
}
echo '<br><br>';
}
}
}else{

$query = mysql_query("SELECT * FROM firefly_news ORDER BY id DESC")
or die(mysql_error());

while($row = mysql_fetch_array($query))
{

$queryy = mysql_query("SELECT * FROM firefly_com WHERE nyhet = '{$row['id']}'")
or die(mysql_error());
$antal=mysql_num_rows($queryy);


echo '
<h3> '.$row['rubrik'].'</h3></font></b>
<font face="arial" color="888888" size="1"> Written by: '.$row['av'].' | '.$row['date'].'<br><br></font>
'.nl2br($row['nyhet']).'<br> <img src="underline.gif">';
echo '<a href="index.php?comment='.$row['id'].'"><font face="arial" size="1"> <img border="0" src="postcomment.gif"> Comment ('.$antal.') </a></font></a>';
echo '<br>';
if (isset($_SESSION['sess_firefly'])){
echo '<a href="index.php?edit='.$row['id'].'">Ändra</a>';
echo '<br><a href="index.php?del_news='.$row['id'].'">Ta bort denna nyhet</a>';
}
echo "<br><br>";
}

}
?> <br><br></div>
[/code]


Admin.

[code]
<div id="content">
<?php
session_start();
if (isset($_GET['logout'])){
  session_unset();
  session_destroy();
    echo "Utloggad!";
  exit;
}
if (!isset($_SESSION['sess_firefly'])){
if (isset($_POST['submit'])){
if ($_POST['name'] == "losenord" && $_POST['pass'] == "losenord"){
$_SESSION['sess_firefly'] = $_POST['name'];
header("Location: index.php");
}else{
echo "Herregud, du försöker ju bara göra intrång, sluta!";
exit;
}
}
?>
<form action="admin.php" method="post">
Användarnamn:<br>
<input type="text" name="name"><br>
Lösenord:<br>
<input type="password" name="pass"><br>
<input type="submit" name="submit" value="Logga in">
</form>
<?php
}else{
echo "Du är inloggad som Admin, här kan du inte ändra något, de gör du direkt på nyheterna;)";
}
?> <br><br></div>
[/code]


And last. Sidebar
[code]<a href="index.php">  Startsidan</a><br>
<a href="index.php?arkiv=">  Alla nyheter</a><br>
<a href="admin.php">  Admin</a><br>
<br>
<font face="arial" size="2"><b>Categories</b><br></font>
<font face="arial">
<?php
$query = mysql_query("SELECT * FROM firefly_news_cat ORDER BY id DESC")
or die(mysql_error());

while($row = mysql_fetch_array($query))
{
$queryy = mysql_query("SELECT * FROM firefly_news WHERE cat = '{$row['id']}'")
or die(mysql_error());
$antal=mysql_num_rows($queryy);
echo '
<a href="index.php?arkiv=&id='.$row['id'].'">  '.$row['rubrik'].'</a> <font face="arial" color="888888">('.$antal.')<br>
';
}
?><br></font>


<?php
if (isset($_SESSION['sess_firefly'])){
?>
<font face="arial" size="2"><b>Administrate</b></font><br>
<font face="arial">
<a href="index.php?ny_nyhet=">  Ny nyhet</a><br>
<a href="index.php?ny_nyhets_cat=">  Ny nyhets kategorie</a><br>
<a href="admin.php?logout=">  Logga ut</a>
<?php
}
?> </div>[/code]
Link to comment
Share on other sites

You didn't write the script, you didn't say what was wrong with it, and you obviously didn't even try to work with it. I'm about 3 seconds away from closing the thread. If you're asking for modifications, go to the freelance board. We're not here to add features to your stuff. We're here to help you work through errors and problems and understanding things.
Link to comment
Share on other sites

Well, im just wondering if somone find something wrong or something that isn't supposed to be there. Im sorry if i didnt explain so good

Because i think something is wrong with the code, it wont connect thru the conn.php and the conn.php is full correct so it has to be something with the code.
Link to comment
Share on other sites

look there's no point getting someone to go through that entire parade of code, if you have anything in the future you'll have to ask for small things. You have to learn php to use it. In any case if there's something specifically wrong apart from the all around consitency of the code then what would it be?
Link to comment
Share on other sites

Well, im getting wrong with the connection:
[code]<?php
$db = mysql_connect('localhost', 'juicy_clan_com', 'passw') or die("Kan inte sluta till databasen eftersom: ".mysql_error());
mysql_select_db("juicy_clan_com");
?>[/code]

So i asked the B-one support about help and they said that the connection is fully correct but that it is something wrong with the blog-script, and not anything else.


Im getting this error:
Access denied for user: 'juicy_clan_com@localhost' (Using password: YES)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.