Intranet Journal

Go Back   IT Management Forum > Intranet Journal

Intranet Journal The new discussion forum for Intranet Journal readers. Leave comments and questions for IJ authors. Suggest story ideas and provide feedback.

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 07-29-2008, 05:05 AM
M@rc M@rc is offline
Registered User
 
Join Date: Jul 2008
Posts: 2
Creating a PHP CMS Part 3

Hi,

I'm having a problem creating a new article. I can view articles fine but when I open newArticle.php the browser does not seem to read the whole of the php code. If the browser reads any form of the > bracket (for instance $connector->query) it then displays the rest of the code with the HTML in the browser.

Could this be a problem with my code? or could php be setup wrong?

In desparate need of help

HTML Code:
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
// Get the PHP file containing the DbConnector class
require_once('../includes/DbConnector.php');

// Check whether a form has been submitted. If so, carry on
if ($HTTP_POST_VARS){

// Create an instance of DbConnector
$connector = new DbConnector();

// IMPORTANT!! ADD FORM VALIDATION CODE HERE - SEE THE NEXT ARTICLE

// Create an SQL query (MySQL version)
$insertQuery = "INSERT INTO cmsarticles (title,tagline,section,thearticle) VALUES (".
"'".$HTTP_POST_VARS['title']."', ".
"'".$HTTP_POST_VARS['tagline']."', ".
$HTTP_POST_VARS['section'].", ".
"'".$HTTP_POST_VARS['thearticle']."')";

// Save the form data into the database 
if ($result = $connector->query($insertQuery)){

// It worked, give confirmation
echo '<center><b>Article added to the database</b></center><br>';

}else{

// It hasn't worked so stop. Better error handling code would be good here!
exit('<center>Sorry, there was an error saving to the database</center>');

}

}
?>

<body>
<form name="form1" method="post" action="newArticle.php">
        <p>&nbsp;Title:
          <input name="title" type="text" id="title">
        </p>
        <p>&nbsp;Tagline:
          <input name="tagline" type="text" id="tagline">
        </p>
        <p>&nbsp;Section:
          <input name="section" type="text" id="section">
        </p>
        <p>&nbsp;Article:
          <textarea name="thearticle" cols="50" rows="6" id="thearticle"></textarea>
        </p>
        <p align="center">
          <input type="submit" name="Submit" value="Submit">
        </p>
</form>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old 08-06-2008, 02:26 AM
marzar00 marzar00 is offline
Registered User
 
Join Date: Jun 2008
Posts: 22
Is this a direct copy and paste? If so it should work fine. I couldn't spot any errors having a quick scan over it.

Marzar
Reply With Quote
  #3 (permalink)  
Old 08-06-2008, 03:58 AM
M@rc M@rc is offline
Registered User
 
Join Date: Jul 2008
Posts: 2
Red face

sorry I was being stupid, I was running it as a file instead of on the localhost. Its always the stupid mistakes that get me lol

thanks for checking the code though, works fine now
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




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





Acceptable Use Policy


The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.0.0