Jump to content


NEws system


9 replies to this topic

#1 jatt

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 26 July 2005 - 03:32 AM

:D Hello All i Am New Here And i need Some Help With News System The news Tutorials is from http://www.greycobra.com Since i see we have more Pro people Here some one Can help me :) ok all the Credtis goes to http://www.greycobra.com and here is the Code from there Site
dbconnect.php
<?php
    $username = "punjabi_3";//your username
    $password = "3";//your password
    $host = "localhost";//your mySQL server
    $database = "punjabi_3";//The name of the database your table is in

         mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error());//connect, but if there is a problem, display an error message telling why there is a problem
         mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error());//Choose the database from your mySQL server, but if there is a problem, display an error telling why
?>

editnews.php
<?
include("dbconnect.php"); //connect to the database

if(!isset($cmd)) //if the variable $cmd is not set, do this
{
//display all the news
$result = mysql_query("select * from mynews order by id DESC"); //select all posts from table mynews


while($r=mysql_fetch_array($result)) //for every row in the table, do this
{
extract($r);//remove the $r, so that its just the variable

//display each entry with links to edit and delete them
echo "<b><u>$title</b></u><br>".stripslashes($message)."<br>By $user<p><a href='editnews.php?cmd=edit&id=$id'><i>Edit</i></a> :: :: <a href='editnews.php?cmd=delete&id=$id'><i>Delete</i></a><br>";
echo "<br>";//so we have spacing between entries
}//end functions
}
?>
<?
if($_GET["cmd"]=="edit" || $_POST["cmd"]=="edit") //if the link for the edit cmd was selected, do this
{
if (!isset($_POST["submit"])) //if submit has not yet been pressed, do this
{
$id = $_GET["id"]; //get the id of the news article being edited.  This is provided in the link to edit it.
$sql = "SELECT * FROM mynews WHERE id=$id"; //select all columns from mynews with this id
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>

<form action="editnews.php" method="post">
<input type=hidden name="id" value="<?php echo $myrow["id"] ?>">

Title*:<br>
<INPUT TYPE="TEXT" NAME="title" VALUE="<?php echo $myrow["title"] ?>" SIZE=30><br>
Message*:<br>
<TEXTAREA NAME="message" rows=10 cols=43><? echo $myrow["message"] ?></TEXTAREA><br>
User*:<br>
<INPUT TYPE="TEXT" NAME="user" VALUE="<?php echo $myrow["user"] ?>" SIZE=30><br>
<br>
<hr>

<input type="hidden" name="cmd" value="edit">

<input type="submit" name="submit" value="submit">

</form>

<? } ?>


<?
if ($_POST["$submit"]) //if submit was pressed, do this
{
$title = $_POST["title"];
$message = $_POST["message"];
$user = $_POST["user"];
$email = $_POST["email"];

$sql = "UPDATE mynews SET title='$title',message='$message',user='$user',email='$email' WHERE id=$id"; //UPDATE the columns in your table with the new content provided in the text areas in the form

$result = mysql_query($sql); //run this query
echo "Information updated. <a href=editnews.php>Return</a>"; //provide an easy link back to editnews.php
}
}
?>


<?
if($_GET["cmd"]=="delete")
{
$sql = "DELETE FROM mynews WHERE id=$id"; //DELETE the row that contains the $id of the post selected
$result = mysql_query($sql); //run query
echo "News Article Deleted!<br><a href=editnews.php>Return to Edit News</a>"; //easy link back to editnews.php
}

submit.php
 <?php
include("./dbconnect.php");//include the file that connects to the database
if(!empty($title)) {//if the title is not empty, than do this function
$title = addslashes($title);
$user = addslashes($user);
$message = addslashes($message);

$date = date("F j, Y");//set up the date format
$date2 = mktime();

$sql = "INSERT INTO mynews (id, title, user, message, date) VALUES ('NULL', '$title','$user','$message','$date')";//Insert all of your information into the mynews table in your database
$query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error());
echo "Database Updated.";
} else {//However, if the title variable is empty, than do this function
?>
<form name="news" method="post" action="<?php echo $PHP_SELF; ?>">
<p>Please fill out all of the following fields:</p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="117"><font size="1">News Topic/Title*: </font> </td>
<td width="577">
<font size="1">
<input type="text" name="title" size="50">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Username*:</font></td>
<td width="577">
<font size="1">
<input type="text" name="user" size="50">
</font>
</td>
</tr>
<tr>
<td width="117"><font size="1">Message*:</font></td>
<td width="577">
<font size="1">
<textarea name="message" rows=10 cols=43></textarea>
</font>
</td>
</tr>
</table>
<p>
<font size="1">
<input type="submit" name="Submit" value="Submit"></font>
</p>
</form> <?php
}//end this function
?>


viewnews.php
<center> <?
include("dbconnect.php");//include the file to connect to the database
$getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC");//query the database for all of the news

while($r=mysql_fetch_array($getnews)){//while there are rows in the table
extract($r);//remove the $r so its just $variable

echo("<hr>
<font size=3>$title added on $date</font><br>
<font size=1>Posted by $user</font><br>
<font size=2>$message</font><p>");

}

?>
</center>

ok this is the code for the script :) it's normal script. if some one Can help me i wanna make it like when ever i SUbmith a news it Makes it like Posted Image
what i am saying is it put the news in Tables insted like
http://www.desipeeps...ws/viewnews.php

Edited by jatt, 26 July 2005 - 04:00 AM.


#2 meadow

    Young Padawan

  • Members
  • Pip
  • 224 posts
  • Location:Devon, England
  • Interests:Php, Hockey, mysql, web design.

Posted 26 July 2005 - 03:40 AM

Whats the actual problem you have?

#3 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 26 July 2005 - 11:56 AM

To do that, i'm guessing you need to edit viewnews.php
You should be able to make what what the HTML is in there.

#4 jatt

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 26 July 2005 - 04:54 PM

if i do that every time i click submith news it's goona make a table and put the title and news in borders :unsure:

#5 fiv3isaliv3

    Young Padawan

  • Members
  • Pip
  • 258 posts
  • Gender:Male

Posted 27 July 2005 - 01:00 PM

i don't understand the problem either. what exactly are you trying to do?

#6 MillerTime

    Young Padawan

  • Members
  • Pip
  • 69 posts

Posted 27 July 2005 - 01:08 PM

here is what i would do:

<? 
include("dbconnect.php");//include the file to connect to the database
$getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC");//query the database for all of the news

while($r=mysql_fetch_array($getnews)){//while there are rows in the table
extract($r);//remove the $r so its just $variable

echo("<hr>
<table style="border:1px solid #000000;"><tr><td bgcolor="" name="top">
<font size=3>$title added on $date</font><br>
<font size=1>Posted by $user</font></td></tr><tr><td bgcolor="" name="bottom">
<font size=2>$message</font></td></tr></table>");
/* i haven't test it yet but it should work.
all you have to do is add the color you want for the top between the quotes of bgcolor where the name of the table cell is top. Do the same for the bottom where the table cell's name is bottom. */

}

?>

Edited by MillerTime, 27 July 2005 - 01:08 PM.


#7 jatt

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 28 July 2005 - 10:56 PM

it says
Parse error: parse error, unexpected T_STRING in /home/punjabi/public_html/menu/1/viewnews.php on line 9
also what i am trying to say is that
i want is this should appear like http://www.strikers-...net/Archive.php with porper color combination and nice And Clean Borders.

#8 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 30 July 2005 - 10:54 PM

echo('<hr>
<table style="border:1px solid #000000;"><tr><td bgcolor="" name="top">
<font size=3>$title added on $date</font><br>
<font size=1>Posted by $user</font></td></tr><tr><td bgcolor="" name="bottom">
<font size=2>$message</font></td></tr></table>');

Miller forgot what kind of quotes he was dealing with

jatt, on Jul 28 2005, 08:56 PM, said:

i want is this should appear like http://www.strikers-...net/Archive.php with porper color combination and nice And Clean Borders.
You can figure out how you want it to be displayed on your own, that's the easy part now.

#9 MillerTime

    Young Padawan

  • Members
  • Pip
  • 69 posts

Posted 31 July 2005 - 05:51 PM

thnx rc69 ;)

#10 jatt

    Young Padawan

  • Members
  • Pip
  • 16 posts

Posted 01 August 2005 - 06:32 AM

after adding that when i viewnews.php it only shows
$title added on $date
Posted by $user
$message http://www.desipeeps.../1/viewnews.php
http://www.desipeeps.com/menu/1 for all the pages we are gettomg close to fix this lol :) thx for the help so far :P





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users