Jump to content

setting variable problem, please help!


dadamssg

Recommended Posts

so im trying to set the a variable which will contain a stripped version of what my user entered into a form...im getting an error with this

 

$description = strip_tags(trim($_POST['description']);

 

it says its "Parse error: syntax error, unexpected ';' on line 52".

 

the whole code is below, i want to check three fields for blanks, return an error if there is a blank, and then im trying to set thier input to new cleaned and formatted variables to enter them into my database

 

<?php
/* Program: postit.php
* Desc: puts entered data in database
*/

Session_start();

if (@$_session['auth'] != "yes")
{
   header("Location: login.php");
   exit();
}
include("caneck.inc");
switch (@$_POST['do'])
{
     case "post":


      /*check title, description, and location for blanks*/

          if ($_POST['title'] == "")
               {
                $blanks[] = "title";
               }
          if ($_POST['description'] == "")
               {
                $blanks[] = "description";
               }
          if ($_POST['location'] == "")
               {
                $blanks[] = "location";
               }
          if(isset($blanks))
               {
                $message = "Please fill out:  ";
                foreach($blanks as $value)
	   {
	      $message .= "$value, ";
           }
	   extract($_POST);
	   include("postform.inc");
	   exit();


       /*clean data and set new variables to insert into table*/



        $cnx = mysqli_connect($host,$user,$passwd,$dbname);

        $title = strip_tags(trim($_POST['title']);

        $description = strip_tags(trim($_POST['description']);

        $location = strip_tags(trim($_POST['location']);



       /*check whether title already exists*/


        $sql = "SELECT title FROM Post WHERE title = '$title'";
        $result = mysqli_query($cnx,$sql)
                 or die("Couldn't execute select query.")
        $num = mysqli_num_rows($result);
        if ($num > 0)
         {
           $message_new = "The title, $title, is already in use. Please choose another title.";
include("postform.inc");
        exit();
         }

  /*add new event to database*/

     else
      {
         if($_POST['sampm'] == "pm")
           {
             $_POST['shour'] = $_POST['shour'] + 12;
           }

         $startDT = $_POST['syear']."-".$_POST['smonth']."-".$_POST['sday']."- ".$_POST['shour'].":".$_POST['sminute'].":00";

         $endDT = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['ehour'].":".$_POST['eminute'].":00";

         $today= date("Y-m-d h:i:s");
         
         $_SESSION['logname'] = $logname;
       
         $_POST['eventType'] = $eventType

       $sql = "INSERT INTO Post (loginName, createDate, title, description, Location, eventType, startDT, endDT)
       VALUES ('$logname', '$today', '$title', '$description', '$location', '$eventType', '$startDT', '$endDT')";

       $result = mysqli_query($cnx,$sql)
               or die("Can't execute insert query.")
       header("Location: login.php"

?>




Link to comment
Share on other sites

Here try this, I cleaned up your code.

 

Make sure you close any function parentheses

function("blahblah";

vs

function("blahblah");

 

Also make sure you properly end your lines

$var = $somevar

vs

$var = $somevar;

 

and close any open brackets.

 

Try running this

 

<?php
/* Program: postit.php
* Desc: puts entered data in database
*/

Session_start();

if (@$_session['auth'] != "yes")
{
    header("Location: login.php");
    exit();
}

include("caneck.inc");
switch ($_POST['do'])
{
    case "post":
    

    /*check title, description, and location for blanks*/

    if ($_POST['title'] == "")
    {
        $blanks[] = "title";
    }
    if ($_POST['description'] == "")
    {
        $blanks[] = "description";
    }
    if ($_POST['location'] == "")
    {
        $blanks[] = "location";
    }
    
    if(isset($blanks))
    {
        $message = "Please fill out:  ";
        foreach($blanks as $value)
        {
            $message .= $value .", ";
        }
        
        extract($_POST);
        include("postform.inc");
        exit();
      

        /*clean data and set new variables to insert into table*/
        $cnx = mysqli_connect($host,$user,$passwd,$dbname);

        $title = strip_tags(trim($_POST['title']));

        $description = strip_tags(trim($_POST['description']));

        $location = strip_tags(trim($_POST['location']));

        /*check whether title already exists*/
        $sql = "SELECT title FROM Post WHERE title = '$title'";
        $result = mysqli_query($cnx,$sql) or die("Couldn't execute select query.");
       
        $num = mysqli_num_rows($result);
        if ($num > 0)
        {
            $message_new = "The title, $title, is already in use. Please choose another title.";
            include("postform.inc");
            exit();
        }

        /*add new event to database*/

        else
        {
            if($_POST['sampm'] == "pm")
            {
                $_POST['shour'] = $_POST['shour'] + 12;
            }

            $startDT = $_POST['syear']."-".$_POST['smonth']."-".$_POST['sday']."- ".$_POST['shour'].":".$_POST['sminute'].":00";

            $endDT = $_POST['eyear']."-".$_POST['emonth']."-".$_POST['eday']."- ".$_POST['ehour'].":".$_POST['eminute'].":00";

            $today= date("Y-m-d h:i:s");
         
            $_SESSION['logname'] = $logname;
       
            $_POST['eventType'] = $eventType;

            $sql = "INSERT INTO Post (loginName, createDate, title, description, Location, eventType, startDT, endDT)
            VALUES ('$logname', '$today', '$title', '$description', '$location', '$eventType', '$startDT', '$endDT')";

            $result = mysqli_query($cnx,$sql) or die("Can't execute insert query.");
            
            header("Location: login.php");
        }
    }
}

?>
[/code

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.