PDA

View Full Version : Help Please



Lysine
28-01-2007, 08:37 PM
I want to add news catergories into this news script. I want it so i click UK News and the uk news will show.


<?
ob_start(); # Allows Cookies
include("config.php");
if($logged[username] && $logged[level] == 12 || $logged[level] == 9){
switch($_GET[action]){
default:
echo("<b><u>Add News</b></u><br>Here you can add news to Thishabbo. Please only post news, and make sure the image url is correct, and check it once you have posted it");
echo("<form method=\"post\" action=\"addnews.php?action=submit_news\">
Title:<br>
<input type='text' size='30' name='title'>
<br>
<br>
Image URL:<br>
<input type='text' size='30' name='image'><br><br>
News Story: (Simple HTML Allowed eg. Bold, Underline, Italic)<br>
<textarea name=\"content\" cols='80' rows='10'></textarea>
<br>
<input type=\"submit\" value=\"Submit Article\"></form>");
break;

case 'submit_news':
$author = $logged[username];
$date = $date = date("j F");
$title = $_POST[title];
$image = $_POST[image];
$contents = $_POST[content];
if($title==NULL||$image==NULL||$content==NULL){
echo("<meta http-equiv=\"Refresh\" content=\"2; URL=addnews.php\"/>You have left a field blank<br><br><b>Please Wait...</b>");
}else{
$sql=("INSERT INTO `news` (id, date, author, title, content, image)VALUES('', '$date', '$author', '$title', '$contents', '$image')");
$result = mysql_query($sql) or die ('Error during the execution of the MySQL query : ' . mysql_error());
echo("<meta http-equiv=\"Refresh\" content=\"2; URL=viewnews.php\"/>Your News Article has successfulyl been submitted!<br><br><b>Please Wait...</b>");
}
break;
}
}else{
echo("You need to be Admin or a Manager to view this!");
}
?>

+ rep if you can help.

Lysine
29-01-2007, 04:26 PM
UPDATE :-

The catergories i need are

UK News
CA News
USA News
World News
Site News

ThisNameWillDo!
29-01-2007, 04:35 PM
<?
ob_start(); # Allows Cookies
include("config.php");
if($logged[username] && $logged[level] == 12 || $logged[level] == 9){
switch($_GET[action]){
default:
echo("<b><u>Add News</b></u><br>Here you can add news to Thishabbo. Please only post news, and make sure the image url is correct, and check it once you have posted it");
echo("<form method=\"post\" action=\"addnews.php?action=submit_news\">
Title:<br>
<input type='text' size='30' name='title'>
<br>
<br>
Image URL:<br>
<input type='text' size='30' name='image'><br><br>
News Story: (Simple HTML Allowed eg. Bold, Underline, Italic)<br>
<textarea name=\"content\" cols='80' rows='10'></textarea>
<br>
Category:<br />
<select name='cat'>
<option>UK News</option>
<option>CA News</option>
<option>USA News</option>
<option>World News</option>
<option>Site News</option>
</select>
<br>
<input type=\"submit\" value=\"Submit Article\"></form>");
break;

case 'submit_news':
$author = $logged[username];
$date = $date = date("j F");
$title = $_POST[title];
$image = $_POST[image];
$cat = $_POST[cat];
$contents = $_POST[content];
if($title==NULL||$image==NULL||$content==NULL){
echo("<meta http-equiv=\"Refresh\" content=\"2; URL=addnews.php\"/>You have left a field blank<br><br><b>Please Wait...</b>");
}else{
$sql=("INSERT INTO `news` (id, date, author, title, content, image)VALUES('', '$date', '$author', '$title', '$contents', '$image')");
$result = mysql_query($sql) or die ('Error during the execution of the MySQL query : ' . mysql_error());
echo("<meta http-equiv=\"Refresh\" content=\"2; URL=viewnews.php\"/>Your News Article has successfulyl been submitted!<br><br><b>Please Wait...</b>");
}
break;
}
}else{
echo("You need to be Admin or a Manager to view this!");
}
?>
---------------------------------

Hope that's what you wanted and hope it works.
If not tell me :P

ThisNameWillDo!
29-01-2007, 04:38 PM
Just edited the above code so if you used it before I edited it, try it now :P

Lysine
29-01-2007, 05:59 PM
I have been told to do this but i cant get it too work. How would i set out the SQL table for it. and where abouts would i add the code below. + rep for help.


create a new MySQL table called cats then set names and id's for them. Then in your news table add a new field called cat_id then in there put the id of the cat you want that news item to be in. Then to select the specific news do

CODE

$id = $_GET['cat'];//GEt the cat in the url

$query = @mysql_query(SELECT * FROM `news` WHERE `cat_id` = '".$id."';")or die("Could not get news!" . mysql_error());//Query the db or show an error
while( $n = mysql_fetch_array($query))//Get the array
{
//Echo the news here!
}

ThisNameWillDo!
29-01-2007, 06:10 PM
Hold on, I'm confused with what you want help with now :P

is it creating the database or getting the category to show?

Lysine
29-01-2007, 08:01 PM
creating a database for the catergorys and ID's and to add that code above into the code in my first post so it will work.

ThisNameWillDo!
29-01-2007, 08:17 PM
Oh, Ok, I've PMed you.

Lysine
29-01-2007, 09:32 PM
Anyone help on this?

Want to hide these adverts? Register an account for free!