Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   Web design and Programming (https://novahq.net/forum/forumdisplay.php?f=32)
-   -   Continued news script, confused (https://novahq.net/forum/showthread.php?t=20930)

Stu 11-28-2004 11:42 AM

Continued news script, confused
 
Hey all, i'm still working on the news script, i'v aquired help from Blackbelt, and all is good... well sort of.
------------------------
What I've done so far:
- Succesfully create MySQL tables.
- Connect to the database.
- Make a form to submit news
Problems:
- So far i have submitted 2 news items, which have been submitted to the database, and confirmed.
- The to items appear on the news page, but the text doesn't.
------------------------
The url to the script is www.members.lycos.co.uk/sc20032004/bb-t2-news/ . Please treat the script with respect, and dont download or use this script without my permission(thnx). Does anyone know what i'm doing wrong? I would like to thank BlackBelt for helping me here, i'v learnt alot whilst making this script :)
- Warm regards

JonM 11-28-2004 11:57 AM

perhaps i could see a script...it could kind of help > :) lol , but if you don't want to cuz of some people who may "steal" your script i understand. :) i made a news script a while back, there not as easy as i thought it would be...

Stu 11-28-2004 12:01 PM

elite, shall i PM you the code? :)

katana*GFR* 11-28-2004 12:04 PM

first of all get .htacces orso in it, or delete the install php form the directory,
It seems like the script echo's the $news_title Author: $news_author
$news_content

$news_title Author: $news_author
$news_content

instead of the text you entered. So i think you have to look at the code again m8

JonM 11-28-2004 12:04 PM

sure/i won't steal it lol :)

Stu 11-28-2004 12:22 PM

Ok, i might aswell put the code here, it has a copyright towards it anyway. :)
And apperntly your PM inbox is full, so this is the easy way round i guess.
Config.php
PHP Code:

<? 
// Database info !! Important for host changes !!
$host 'localhost'// Always keep as this
$username 'sc2003-2004'// MySql username
$password ''// MySql username's password
$databasename'sc20032004_uk_db'// MySql DB to connect to
//connect to mysql
$connect=mysql_connect("$host""$username""$password");
mysql_select_db("$databasename"$connect);
// Print headers and footers
$header '<img src="/images/news-head.gif"><p>';
$footer '<center><b>Powered by <a href="http://www.fleabib-php.tk"> FleabibPHP-News</a></b><center>';
// Process any errors
error_reporting(1); 
?>

install.php
PHP Code:

<?php
include('config.php');
$sql 'CREATE TABLE news ( 
     id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, 
     news_title TEXT,
     news_content TEXT, 
     news_date DATE NOT NULL 
   )'

if (@
mysql_query($sql)) { 
 echo 
'<p>News table sucessfully created!</p>'
} else { 
 exit(
'<p>Error creating tables: ' 
     
mysql_error() . '</p>'); 
}
?>

news_submit.php
PHP Code:

<?

include("config.php");    //All the config stuff.


If ($_POST['postnews']) {    //If the have sunmitted a form whose name is postnews
    
$news_title=$_POST["Title"];        //What this does is take the data entered into the form and turn it into a variable we can manipulate
$news_author=$_POST["Author"];
$newstext=$_POST["Text"];    

mysql_query("INSERT INTO news VALUES ('NULL', '$news_title', '$news_author', '$news_text')");

Echo(
"Data entered into database");
    
} ELSE {
Echo(
"<form method=\"POST\" action=\"news_submit.php\">");
Echo(
"<p><input type=\"text\" name=\"Title\" size=\"31\" value=\"Tecoma2\">Title of News Article<br>");
Echo(
"<input type=\"text\" name=\"Author\" size=\"31\">Author<br>");
Echo(
"<textarea rows=\"5\" name=\"Text\" cols=\"26\"></textarea>News as you want it displayed.<br>");
Echo(
"<input type=\"submit\" value=\"Submit\" name=\"postnews\"><input type=\"reset\" value=\"Reset\" name=\"B2\"></p>");
Echo(
"</form>");

}

?>

show-news.php
PHP Code:


<?php
require('config.php');
// Print news
$result=mysql_query("SELECT * FROM news") or die ("<br /><br />There's an error in the MySQL-query: ".mysql_error());
while(
$r=mysql_fetch_array($result)) {
$news_title= [$r'news_title'];
$news_author= [$r'news_author'];
$news_content=[$r'news_content'];
// Html Layout
include('layout.html');
}
?>

layout.html
<html>
<body>

<table width="358" border="1" cellpadding="0" cellspacing="0">

<tr>
<td width="358" height="17" valign="top">$news_title Author: news_author</td>
</tr>
<tr>
<td height="92" valign="top">$news_content</td>
</tr>

</table>

<br>
</body>
</html>
__________________________________
do u think u can help me here m8? I would be most greatful if u could.
- warm regards;)

Stu 11-28-2004 12:54 PM

ooo, now its not showing atall :|

JonM 11-28-2004 01:01 PM

it can't be in html make it like this <td height="92" valign="top"><? echo"$news_content"; ?></td>
</tr> except do that for everything ...

JonM 11-28-2004 01:24 PM

o wait hey on this whole layout.html ... i didn't realize it was a different page lolz anywayz instead of including it go ... :
PHP Code:

<?php 
require('config.php'); 
// Print news 
$result=mysql_query("SELECT * FROM news") or die ("<br /><br />There's an error in the MySQL-query: ".mysql_error()); 
while(
$r=mysql_fetch_array($result)) { 
$news_title= [$r'news_title']; 
$news_author= [$r'news_author']; 
$news_content=[$r'news_content']; 

?> 

<html>
<body>

<table width="358" border="1" cellpadding="0" cellspacing="0">

<tr>
<td width="358" height="17" valign="top"><? echo"$news_title"Author: echo"news_author";</td>
</
tr>
<
tr>
<
td height="92" valign="top"><? echo"$news_content"?> </td>
</tr>

</table>

<br>
</body>
</html>


katana*GFR* 11-28-2004 02:11 PM

i dont know much PHP but isnt HTML embedded into the PHP code? so the php close tag ( ?>) comes at the end of the html part here?

JonM 11-28-2004 03:08 PM

html is not embedded in php, but it can be ... but then things like <border="0"> would have to be echo"<border=\"0\">"; so sometimes with large html scripts it's easier to keep it not intergrated into php.

Stu 11-28-2004 03:08 PM

no katana m8, you can save a php file as a .php file if it has html in it, but the html either needs to be in echo() array or outside the <?php ?> tags :).
P.s. Thnx elite :)... but it didn't do much atall LOL it isn't showing all the news anymore.
http://www.members.lycos.co.uk/sc200.../show_news.php
:*( Panther can you help us?

JonM 11-28-2004 03:15 PM

lol :) i guess i can't do it...ahhhhhhhh bak to sitting bak... :)

Stu 11-28-2004 03:19 PM

lol sorry elite, refresh that post i just posted lol

JonM 11-28-2004 03:32 PM

here is the script i would dO:::

PHP Code:

<?
require('config.php'); 
// Print news 
$result=mysql_query("SELECT * FROM news") or die ("<br /><br />There's an error in the MySQL-query: ".mysql_error()); 
while(
$myrow=mysql_fetch_array($result)) { 
printf("<table border=\"1\" cellpadding=\"0\" cellspacing=\"0\" style=\"border-collapse: collapse\" bordercolor=\"#111111\" width=\"100%\" id=\"AutoNumber1\" height=\"96\">
  <tr>
    <td width=\"100%\" height=\"19\">
$myrow[newstitle] :: Posted by $myrow[news_author]</td>
  </tr>

  <tr>
    <td width=\"100%\" height=\"76\" valign=\"top\">
$myrow[news_content]</td>
  </tr>
</table>
}
?>


JonM 11-28-2004 03:37 PM

give that one a try, it is a lil different but is basically the same ... if it doesn't work that's my last try we'll just let a pro come in lol


All times are GMT -5. The time now is 09:24 PM.

Powered by vBulletin®