Jump to content


News Script


5 replies to this topic

#1 Shifty

    Young Padawan

  • Members
  • Pip
  • 19 posts

Posted 18 August 2005 - 03:36 AM

Well i have been working on a little php news script.

I have only 1 problim, when i try to add something to the databace it wont add it to it.

Here is the source code for the form

<?php
include ('functions.php');
echo "<form name=\"form1\" method=\"post\" action=\"handle_news.php\">
<strong><font size=\"3\">Post news...<br /></font></strong>
<br />
Username:
<br />
<input name=\"user\" type=\"text\" id=\"user\" size=\"30\"><br />
News Title:
<br />
<input name=\"title\" type=\"text\" id=\"title\" size=\"40\"><br />
Mood:
<br />
<input name=\"title\" type=\"text\" id=\"mood\" size=\"40\"><br />
News:
<br />
<textarea name=\"news\" cols=\"60\" rows=\"25\" id=\"news\"></textarea>
<br />
<input type=\"submit\" name=\"Submit\" value=\"Post\">
</form>";
?>

And here is the handleing form
<?php
include ('functions.php');
$user = $_POST['user'];
$title = $_POST['title'];
$mood = $_POST['mood'];
$date = date('Y-m-d');

//change the bbcode into html using perl compatible regular expressions

$news = $_POST['news'];

$bbcode = array(
           "/\[link\](.*?)\[\/link\]/",
           "/\[url\](.*?)\[\/url\]/",
           "/\[img\](.*?)\[\/img\]/",
           "/\[b\](.*?)\[\/b\]/",
           "/\[u\](.*?)\[\/u\]/",
           "/\[i\](.*?)\[\/i\]/"
       );
$html = array(
           "<a href=\"\\1\">\\1</a>",
           "<a href=\"\\1\">\\1</a>",
           "<img src=\"\\1\">",
           "<b>\\1</b>",
           "<u>\\1</u>",
           "<i>\\1</i>"

       );
       $news1 = preg_replace($bbcode,$html, $news);

mysql_query("INSERT INTO news(user,title,news,date,mood) VALUES('$user','$title','$news1','$date','$mood',now())");
?>

And i get no mysql errors in the functions page at all

Cansomeone please help me,

+ Sh|fty

#2 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 18 August 2005 - 06:22 AM

maybe a error in your database connect file?

#3 Shifty

    Young Padawan

  • Members
  • Pip
  • 19 posts

Posted 18 August 2005 - 07:39 AM

No it was the "now" bit of the adding. Dont know why i would put that in there , hurm why would i need a unix timestamp :S.

Oh well its working now and its looking sexy :P

+ Sh|fty

#4 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 18 August 2005 - 10:31 AM

well, you could possibly want the timestamp so if at a later date you want to change the format of your "date" you can. If you still want that in there, just do something like
mysql_query("INSERT INTO news(user,title,news,date,mood,timestamp) VALUES('$user','$title','$news1','$date','$mood',".time().")");
And then add a column called "timestamp"

#5 Phyrriz

    Young Padawan

  • Members
  • Pip
  • 19 posts
  • Location:Sweden, Sundsvall
  • Interests:Doing some work in C++ or ASM, PHP/ASP.

Posted 17 September 2005 - 05:18 PM

Uhm, you've got the connection right with the MYSQL database? =)

mysql_query("INSERT INTO news(user,title,news,date,mood,timestamp) VALUES('$user','$title','$news1','$date','$mood',".time().")");


I'll think that will work out just fine, or?

Oh, didn't see rc69 posted the same :$ So'z

Edited by Phyrriz, 17 September 2005 - 05:19 PM.


#6 Shifty

    Young Padawan

  • Members
  • Pip
  • 19 posts

Posted 18 September 2005 - 01:19 AM

I fixed this ages ago, but thanks anyway.

oh and this topic is 1 month old :)

+ Sh|fty





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users