Go Back   Pictual Design Forums > Webmaster > Programming
Top Posters Referers Register Members List Calendar Search Today's Posts Mark Forums Read

Programming Post any problems that you have coding or post any topics about coding here.

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 08-29-2006, 10:59 PM
xplicit xplicit is offline
Deathgod - Shinigami
Lives Here
Elite Member (500+ posts)
 
Location: U.S.
Rep Power: 0
xplicit is an unknown quantity at this point
Default CMS News posting script?

Well recently I tried to make my own CMS news posting script via php/mysql but everytime I try to make it work, my news would never show up, the installation of the tables and everything should have went together fine.

DBconnect.php
Code:
<?php $username = "brian_news";//your username $password = "changedpass";//your password $host = "localhost";//your mySQL server $database = "brian_news";//The name of the database your table is in mysql_connect($host,$username,$password) or die("Error connecting to Database!<br>" . mysql_error());//connect, but if there is a problem, display an error message telling why there is a problem mysql_select_db($database) or die("Cannot select database!<br>" . mysql_error());//Choose the database from your mySQL server, but if there is a problem, display an error telling why ?>

submit.php
Code:
<?php include("./dbconnect.php");//include the file that connects to the database if(!empty($title)) {//if the title is not empty, than do this function $title = addslashes($title); $user = addslashes($user); $message = addslashes($message); $date = date("F j, Y");//set up the date format $date2 = mktime(); $sql = "INSERT INTO mynews (id, title, user, message, date) VALUES ('NULL', '$title','$user','$message','$date')";//Insert all of your information into the mynews table in your database $query = mysql_query($sql) or die("Cannot query the database.<br>" . mysql_error()); echo "Database Updated."; } else {//However, if the title variable is empty, than do this function ?> <form name="news" method="post" action="<?php echo $PHP_SELF; ?>"> <p>Please fill out all of the following fields:</p> <table width="100%" border="0" cellpadding="0" cellspacing="0"> <tr> <td width="117"><font size="1">News Topic/Title*: </font> </td> <td width="577"> <font size="1"> <input type="text" name="title" size="50"> </font> </td> </tr> <tr> <td width="117"><font size="1">Username*:</font></td> <td width="577"> <font size="1"> <input type="text" name="user" size="50"> </font> </td> </tr> <tr> <td width="117"><font size="1">Message*:</font></td> <td width="577"> <font size="1"> <textarea name="message" rows=10 cols=43></textarea> </font> </td> </tr> </table> <p> <font size="1"> <input type="submit" name="Submit" value="Submit"></font> </p> </form> <?php }//end this function ?>

viewnews.php
Code:
<? include("dbconnect.php");//include the file to connect to the database $getnews = mysql_query("SELECT * FROM mynews ORDER BY id DESC");//query the database for all of the news while($r=mysql_fetch_array($getnews)){//while there are rows in the table extract($);//remove the $r so its just $variable echo("<hr> <font size=3>$title added on $date</font><br> <font size=1>Posted by $user</font><br> <font size=2>$message</font><p>"); } ?>

I think I CHMODed them to 777 but not in the public_html folder on my web host, might be why when I submit my news it doesnt show up?
__________________
www.BrianLeee.com - Online Portfolio
Reply With Quote
  #2  
Old 08-30-2006, 01:18 AM
Peter's Avatar
Peter Peter is offline
Administrator
HeadLancer
Advanced Member (50+ posts)
 
Rep Power: 10
Peter is on a distinguished road
Default

Most likely not working since register_globals may be disabled and you have this code:

include("./dbconnect.php");//include the file that connects to the database
if(!empty($title)) {//if the title is not empty, than do this function
$title = addslashes($title);
$user = addslashes($user);
$message = addslashes($message);

Try replacing the right portion of your code to $_REQUEST instead:

Code:
include("./dbconnect.php");//include the file that connects to the database if(!empty($_REQUEST['title'])) {//if the title is not empty, than do this function $title = addslashes($_REQUEST['title']); $user = addslashes($_REQUEST['user']); $message = addslashes($_REQUEST['message']);

Try that
Reply With Quote
  #3  
Old 08-30-2006, 01:19 AM
Peter's Avatar
Peter Peter is offline
Administrator
HeadLancer
Advanced Member (50+ posts)
 
Rep Power: 10
Peter is on a distinguished road
Default

Also, in your SQL query, don't use 'NULL' like you have. Just leave it '', and if it's auto-increment it should work fine without NULL.
Reply With Quote
  #4  
Old 08-30-2006, 05:22 AM
xplicit xplicit is offline
Deathgod - Shinigami
Lives Here
Elite Member (500+ posts)
 
Location: U.S.
Rep Power: 0
xplicit is an unknown quantity at this point
Default

Ill try those out soon, thanks peter, never thought about those when I was looking at it, and never knew leaving the sql query to '' will auto incriment. Thanks Will post the results soon.
__________________
www.BrianLeee.com - Online Portfolio
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:37 PM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
vRewrite 1.5 beta SEOed URLs completed by Tech Help Forum and Chalo Na.