Jump to content

having fun with a news script.(needs attention theo.


redarrow

Recommended Posts

i created the below code so users can send news on a web site for fun,

 

i wanted to use session's for fun,

 

i used a array for testing and session's no database,

 

if a user press a link then you can see the news and read it in the same form they post new news.

 

crazy i no but all fun.

 

wonder if any one can improve my little idea cheers.

 

remember it only for fun and one page long.

 

 

 

 

 


<?php session_start();?>

<html>
<head>
<title>Redarrow's news web test</title>

<body>

<center><h1>Welcome to redarrow's new's web site!</h1>

<br><br>

<h3>Please use the form below, to add a new's statement,<br> or read our current news, via the links provided! </h3>

</center>

<?php if(isset($_SESSION['warn'])){echo $_SESSION['warn'];unset($_SESSION['warn']);}else{unset($_SESSION['warn']); $_SESSION['warn']="";}?>
<br><br>

<table border="0" align="center">
<tr>
<td width="300px"  valign="top" align="center"><br><br><b>Current new's links!</b><br><br>


<?php

$array1=array("title"=>"My day at work","do you like php","my new car");

$array2=array("My day at work"=>"i had a grate day at work cheers!","do you like php"=>"i love php cheers mate!","my new car"=>" i haven got the car i wanted yet!");



foreach($array1 as $titles){

echo "<table border='0' align='left'><tr><td align='left'><a href='".$_SERVER['PHP_SELF']."?read_title=$titles'>$titles</a></tr></td></table><br><br>";



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

		$x=$_GET['read_title'];

		$_SESSION['description']=$array2[$x];


}
}




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

			$news_title=$_POST['news_title'];

			if($news_title==$_GET['read_title']){

				$_SESSION['warn']="<center><h1><b>Sorry you are trying to add a new's that already exist's</b></h1>
				<br> Please use this link, to enter a new post <a href='{$_SERVER['PHP_SELF']}'>ADD NEW POST HERE</a>";
			}

}
?>

</td>

<td  valign="top" align="center">
<table border="0" valign="top" align="center">
<tr>
<td valign="top" align="center">
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<br><br>
News Title
<br>
<input type="text" name="news_title" value='<?php if(isset($_GET['read_title'])){echo $_GET['read_title'];}else {}; ?>'>
<br><br>
News Description
<br>
<textarea rows="25" cols="50" name="news_description"><?php if(isset($_SESSION['description'])){ echo $_SESSION['description']; unset($_SESSION['description']);}?></textarea>
<br><br>
<input type="submit" name="submit" value="Add my news!"><input type="reset" value="Reset the form!">
</form>
</tr></td></table>
</tr></td></table>
</body>
</head>
</html>

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.