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
https://forums.phpfreaks.com/topic/141270-setting-variable-problem-please-help/
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.