xoligy Posted June 5, 2008 Share Posted June 5, 2008 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 https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/ Share on other sites More sharing options...
jesushax Posted June 5, 2008 Share Posted June 5, 2008 1. you need to retrrive the name from the form e.g. $name = $_POST["name"]; add that near the $title variable for ease 2. header("Location: /redirecturl.php"); 3. i dont understand what your doing here... Link to comment https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558127 Share on other sites More sharing options...
xoligy Posted June 5, 2008 Author Share Posted June 5, 2008 Thanks jesushax, i'll givre the $name = $_POST["name"]; ago canna do the header yet thats for another day but i'll remember what i have to do as for #3 i'll figure that out at a later date i guess Link to comment https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558132 Share on other sites More sharing options...
xoligy Posted June 5, 2008 Author Share Posted June 5, 2008 The name thing didnt work, you see what i have is all the functions in one file i have then called for the name to be displayed on the page by using <?=$user->userName?> (probably not the right way to do it). Link to comment https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558134 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Share Posted June 5, 2008 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 https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558163 Share on other sites More sharing options...
xoligy Posted June 5, 2008 Author Share Posted June 5, 2008 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 https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558166 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Share Posted June 5, 2008 post your whole page code... Link to comment https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558167 Share on other sites More sharing options...
xoligy Posted June 5, 2008 Author Share Posted June 5, 2008 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 https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558170 Share on other sites More sharing options...
jesushax Posted June 5, 2008 Share Posted June 5, 2008 where are you getting the $name from? Link to comment https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558172 Share on other sites More sharing options...
xoligy Posted June 5, 2008 Author Share Posted June 5, 2008 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 https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558179 Share on other sites More sharing options...
DarkWater Posted June 5, 2008 Share Posted June 5, 2008 It's because $user is an object, and you just tried to echo $user, not $user->userName. Link to comment https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558180 Share on other sites More sharing options...
xoligy Posted June 5, 2008 Author Share Posted June 5, 2008 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 https://forums.phpfreaks.com/topic/108807-news-page-nearly-done-just-stuck-a-little-lol/#findComment-558185 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.