Jump to content

News page - Nearly done just stuck a little lol


xoligy

Recommended Posts

As some already know i have been following a simple tutorial news tutorial which can be located here: http://www.tutorialcode.com/php/news-system-with-comments/

 

But once i had completed it i started to play with the layout and then moving code about and trying to add new features and i believe ive done as much as i possibly can for now and untill i start on the comments section o.0

 

Anyway the problems with the addnews page are:

1. It's not adding the author this is due to me changing the code from you writing it in to trying to grab from the database

2. I would like it to redirect to a page once posted is that possible?

3. Ive added html tag things but they dont work so i'll add the code under the addnews code, i believe i may of entered it wrong somehow basically im calling from another file that holds most the functions!

<?php
if ($_POST['submit']) {
    
    $title = addslashes($_POST['title']);
    $post = nl2br(addslashes($_POST['post']));
    $time = date("g:i a");
    
$query = "INSERT INTO news (`title`, `author`, `post`, `date`, `time`) VALUES ('$title', '$name', '$post', 'NOW()', '$time')";
$result = @mysql_query($query);

        echo "<b>News Posted<br><br>";
echo "Redirecting...</b>";
MRedirect("news.php"); // attempt at redirection.. failed haha
return false;
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0" bordercolorlight="#000000">
<tr> 
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<td width="100%" height="21" valign="top">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
    <tr>
        <td width="10%" height="22"><div align="right">Your Name:</div></td>
        <td width="30%"><?=$user->userName?></td>

 

html_tags code:

<?php
$html_tags = '
<input type="button" value="B" class="input" style="font-weight:bold; width: 20px;" onClick=\'javascript: simpletag("B")\'>
<input type="button" value="I" class="input" style="font-style:italic; width: 20px;" onClick=\'javascript: simpletag("I")\'>
<input type="button" value="u" class="input" style="text-decoration:underline; width: 20px;" onClick=\'javascript: simpletag("U")\'>
<select name="size" id="size" class="input" onChange="javascript: tag_other(\'font\',\'size\',\'size\')">
<option>SIZE</option>
<option value="1">Small</option>
<option value="3">Medium</option>
<option value="5">Large</option>
</select>
<select name="color" id="color" class="input" onChange="javascript: tag_other(\'font\',\'color\',\'color\')">
<option>COLOR</option>
<option value="#FF0000" style="color: #FF0000">Red</option>
<option value="#00FF00" style="color: #00FF00">Green</option>
<option value="#0000FF" style="color: #0000FF">Blue</option>
</select>
<div><img src="images/spacer.gif" width="1" height="5"></div>
<input type="button" value="http://" class="input" onClick="javascript: tag_url()"> 
<input type="button" value="img" class="input" onClick="javascript: tag_img()">
<input type="button" value="@" class="input" onClick="javascript: tag_email()" style="width: 20px;">
';
?>

Link to comment
Share on other sites

 

move that username code above the sql

 

then echo the variable in your code

 

the username wont add becuase the variable is created after the sql where youve used it sooo

 

    =$user->userName
    $title = addslashes($_POST['title']);
    $post = nl2br(addslashes($_POST['post']));
    $time = date("g:i a");
    
$query = "INSERT INTO news (`title`, `author`, `post`, `date`, `time`) VALUES ('$title', '$name', '$post', 'NOW()', '$time')";
$result = @mysql_query($query);

 

and

 

        <td width="30%"><?php echo $user; ?></td>

Link to comment
Share on other sites

Thanks but no good here is what i had:

 

$user->userName;
$name = addslashes($_POST['name']);
$title = addslashes($_POST['title']);
$post = nl2br(addslashes($_POST['post']));
$time = date("g:i a");

// then under the sql

<td width="30%"><?php echo $user; ?></td>

 

Returned: Catchable fatal error: Object of class stdClass could not be converted to string in /home/xoligy/public_html/Medi/addnews.php on line 49

 

which is the <php echo $user; ?> im going to give it a rest for a while ive been messin with this for a good few hrs...

Link to comment
Share on other sites

Ive posted the important part for the addnews.php as for the the vile it's including for the other code that like over 1k lines of code but here is probably the best parts :s

 

<?php
function getUserDetailsByName($name,$fields=" ID "){

$str="select $fields from `UserDetails` where  userName='$name' ";

//echo $str;

$q = @mysql_query($str);

if (!$q) {

	print ('Query failed: '.mysql_error());

	return;

}

if (!@mysql_num_rows($q)) {

	return 0;

}

else{

	$st="";

	$st = mysql_fetch_object($q);

	$st->untrainedSold=floor($st->untrainedSold);

	return $st;

}	

}

function getUserDetails($id,$fields="*"){

$str="select $fields from `UserDetails` where  ID='$id' ";

//echo $str;

$q = @mysql_query($str);

if (!$q) {

	print ('Query failed: '.mysql_error());

	return;

}

if (!@mysql_num_rows($q)) {

	return 0;

}

else{

	$st="";

	$st = mysql_fetch_object($q);

	$st->untrainedSold=floor($st->untrainedSold);

	return $st;

}	

}
$us=getUserDetailsByName($userName);

$userID=$us->ID;

$str= "INSERT INTO `Ranks` (userID) VALUES ('$userID') ";

$q = @mysql_query($str);

return $q;
?>

Link to comment
Share on other sites

The only way i know how to display the username at the moent is via <?=$user->userName?> on the database its UserDetails > userName this is why im stuck lol I "somehow" need it to realise "who" is logged on so it automatically uses there name for the post. The only way i see around this is an input box readonly with the value="<?=$user->userName?>" which woud look horrid

Link to comment
Share on other sites

I normally use <?$user->userName?> to display the user, but on the new creation page and comments page i want it to know who the user is and then post under that user the only way i can do that is with a textbox set to readonly i was after away around that tho seems im just gonna have to stick with the textbox tho lol

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.