Having trouble with this section of code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
james595832
Forum Newbie
Posts: 4
Joined: Wed Mar 29, 2006 3:34 am

Having trouble with this section of code

Post by james595832 »

Pimptastic | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]


Hi everyone,

I am trying to set up a little news management system and all is fine except for this one error I get in add.php:

The Code:

Code: Select all

<?php
//The following code is the PHP form handling application.
//Connecting to the MySQL database
require('http://www.jayreilly.net/dbconnect.php');

//The current date.
$today = date('n/j/y');

if($_POST['submit']) {
//Simplifying the variables.
$title = $_POST['title'];
$author = $_POST['author'];
$date = $_POST['date'];
//trim() strips white space from the beginning and end of a line.
$date = trim($date);
$content = $_POST['content'];

//Checks for empty fields or invalid date.
if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) {
echo "<center><strong>Please fill in all fields!</strong></center>

} else {
//explode() separates the date by the '/' character and outputs it to an array.
$explode_date = explode('/', $date);
//checkdate() returns FALSE if the date is invalid.
$check_date = checkdate($explode_date[0], $explode_date[1], $explode_date[2]);
if($check_date == false) {
echo "<center><strong>Invalid date entered!</strong></center>";
} else {
//htmlspecialchars() converts special characters into HTML entities.
$title = htmlspecialchars($title);
$author = htmlspecialchars($author);
//The MySQL query which will insert content into the table.
$query = "INSERT INTO news (ID, title, author, date, content) VALUES ('', '$title', '$author', '$date', '$content')";
//Executing the query with mysql_query().
mysql_query($query) or die(mysql_error());
echo "<center><strong>News item added!</strong></center>";
}
}
}

//Closing the connection.
mysql_close($connection);
?>


<form method="post" action="http://www.jayreilly.net/add.php">
<table align="center">
<tr><td align="right">Title:</td><td><input type="text" name="title" maxlength="250" /></td></tr>
<tr><td align="right">Author:</td><td><input type="text" name="author" maxlength="250" /></td></tr>
<tr><td align="right">Date:</td><td><input type="text" name="date" value="<?php echo "$today"; ?>" maxlength="10" /></td></tr>
<tr><td align="right">Content:</td><td><textarea name="content" cols="50" rows="10"></textarea></td></tr>
<tr><td> </td><td><input type="submit" name="submit" value="Submit" /><input type="reset" name="reset" value="Reset" /></td></tr>
</table>
</form>

The error:

Parse error: syntax error, unexpected '>' in /hsphere/local/home/james595/jayreilly.net/add.php on line 28


Could anyone shed any light on this as I cannot see the parse error myself!


Pimptastic | Please use

Code: Select all

and

Code: Select all

tags where appropriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

Code: Select all

if((empty($title)) OR (empty($author)) OR (empty($date)) OR (empty($content))) { 
echo "<center><strong>Please fill in all fields!</strong></center>
needs a closing "; after </center>
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
james595832
Forum Newbie
Posts: 4
Joined: Wed Mar 29, 2006 3:34 am

Thanks

Post by james595832 »

I actually thought I had that included obviously not!

Thanks
Post Reply