Jump to content


Help with unexpected T_VARIABLE


4 replies to this topic

#1 bsf

    Young Padawan

  • Members
  • Pip
  • 7 posts

Posted 27 March 2006 - 03:52 AM

I am trying to make my own News system and i keep getting this error on line 4
Parse error: parse error, unexpected T_VARIABLE in /home/shane/public_html/343/submit.php on line 4

The code i have is
<?php
if($_post['submit']) {
$title =$_post['title']
$user =$_post['user']
$story =$_post['story']
if((empty($title)) OR (empty($story))
{
echo<font color="#E4E4E4" face="Tahoma" size="2"><b>Error: Please fill out all forms</b></font>
} else {
//htmlspecialchars()
$title = htmlspecialchars($title);
$user = htmlspecialchars ($user);
$query = "INSERT INTO News (ID, title, user, story) VALUES ('', '$titles', '$user', '$story' mysql_query($query) or die(mysql_error());
echo "<font color="#E4E4E4" face="Tahoma" size="2"><b>News added successfully</b></font></body>
";
}
}
?>

Thanks in advance.
BSF

Edited by bsf, 27 March 2006 - 03:52 AM.


#2 high6

    Young Padawan

  • Members
  • Pip
  • 57 posts

Posted 27 March 2006 - 06:26 AM

well w/e i get that error it means i forgot a ";" at the end of a line.

#3 Mr. Matt

    Moderator

  • P2L Staff
  • PipPipPipPip
  • 1,945 posts
  • Gender:Not Telling

Posted 27 March 2006 - 06:39 AM

you need to go back and do the basics of PHP mate.... you have missed ';' on lots of lines, you have missed " ".

<?php

if($_post['submit']) {

$title = $_post['title'];
$user = $_post['user'];
$story = $_post['story'];

if (empty($_POST['title'] && $_POST['story'])) {

echo '<font color="#E4E4E4" face="Tahoma" size="2"><b>Error: Please fill out all forms</b></font>';

} else {

//htmlspecialchars()
$title = htmlspecialchars($title);
$user = htmlspecialchars($user);

$query = "INSERT INTO News (title, user, story) VALUES ('$title', '$user', '$story')";
$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);

if ($num) {

echo '<font color="#E4E4E4" face="Tahoma" size="2"><b>News added successfully</b></font></body>';

} } }

?>

i've neatened it up, if it doesnt work its because of your table, you need to make sure the id field is auto_increatment and an integer.

But like i said go back to basics before doing anything else.

#4 Av-

    I Feel Left Out

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

Posted 27 March 2006 - 10:35 AM

View Postdeadly, on Mar 27 2006, 11:39 AM, said:

<?php
if (empty($_POST['title'] && $_POST['story'])) {
?>
Will probably give you an error and if it doesnt, it wont tell the the visitor there are fields missing unless BOTH fields are empty, what we want is if either one or both fields are empty it tells them to go back.

if (empty($_POST['title']) || empty($_POST['story'])) {


#5 rc69

    PHP Master PD

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

Posted 27 March 2006 - 12:21 PM

The problem in this thread has already been solved, if you which to debate operators, please start a new thread.

p.s. Just so you guys know, or and || are the exact same thing. PHP doesn't care which you use, but i believe that one is evaluated before the other... Either way, they do accomplish the same task at the same speed, so there was no need to change that line.

Edited by rc69, 27 March 2006 - 12:23 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users