Jump to content

[SOLVED] Help with Parse error - unexpected T_ENCAPSED_AND_WHITESPACE


snteran

Recommended Posts

I have created a form and after the user completes the form I have the ticket that was created displayed.  I have posted the mysql query and the redirect.  I am fairly new to php and most of my code is from a previous application that I am redoing.

 

here is the code.

mysql_select_db($database_itc_admin, $itc_admin);
$max_query = "SELECT max(ticket_nbr) FROM itc_tickets";
$max_row = mysql_query($max_query, $itc_admin) or die(mysql_error());
$max_ticket = mysql_fetch_assoc($max_row);
$totalRows_max = mysql_num_rows($max_row);

  $insertGoTo = "view_ticket.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= "?" . "ticket_nbr='$max_ticket['ticket_nbr']'"; << receive error here
  }
  header(sprintf("Location: %s", $insertGoTo));

 

Thanks

Link to comment
Share on other sites

Thanks for the fast reply.  I did try the code and it did not bring up the page correctly.  For the new URL you get: view_ticket.php?ticket_nbr=''

Perhaps there is something wrong with my select query?

 

I'm not sure if it is needed, but here is the whole section of this entry.

 

<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "newticket")) {
  $insertSQL = sprintf("INSERT INTO itc_tickets (ticket_status, ticket_category, ticket_category_other, ticket_priority, issued_by, assetid, description, assigned_to, create_usr, lastupdt_usr, create_date) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, NOW())",
                       GetSQLValueString($_POST['ticket_status'], "text"),
                       GetSQLValueString($_POST['ticket_category'], "text"),
                       GetSQLValueString($_POST['ticket_category_other'], "text"),
                       GetSQLValueString($_POST['ticket_priority'], "text"),
                       GetSQLValueString($_POST['issued_by'], "text"),
                       GetSQLValueString($_POST['assetid'], "int"),
                       GetSQLValueString($_POST['description'], "text"),
                       GetSQLValueString($_POST['assigned_to'], "text"),
                       GetSQLValueString($_POST['current_usr'], "text"),
                       GetSQLValueString($_POST['current_usr'], "text"));

  mysql_select_db($database_itc_admin, $itc_admin);
  $Result1 = mysql_query($insertSQL, $itc_admin) or die(mysql_error());
  
mysql_select_db($database_itc_admin, $itc_admin);
$max_query = "SELECT max(ticket_nbr) FROM itc_tickets";
$max_row = mysql_query($max_query, $itc_admin) or die(mysql_error());
$max_ticket = mysql_fetch_assoc($max_row);
$totalRows_max = mysql_num_rows($max_row);

  $insertGoTo = "view_ticket.php";
  if (isset($_SERVER['QUERY_STRING'])) {
  $insertGoTo .= "?" . "ticket_nbr={$max_ticket['ticket_nbr']}";    
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>

Link to comment
Share on other sites

I have created a form and after the user completes the form I have the ticket that was created displayed.  I have posted the mysql query and the redirect.  I am fairly new to php and most of my code is from a previous application that I am redoing.

 

here is the code.

//this line below I don't know if you can have two sets of single quotes nested within each other like that

    $insertGoTo .= "?" . "ticket_nbr='$max_ticket['ticket_nbr']'"; << receive error here

//try this way

$insertGoTo .= "?" . "ticket_nbr=$max_ticket['ticket_nbr']"; << receive error here

  }
  header(sprintf("Location: %s", $insertGoTo));

 

Thanks

Link to comment
Share on other sites

Thanks for the replys.  I did try the last two pieces of code and both did not work.  They bring up the url but no ticket #.  Perhaps I need to change the mysql query.  I'll try somethings, but again, I'm new so any help would be great.

 

Thanks

Link to comment
Share on other sites

Here could be your problem, maybe I am missing something, look closely.

 

"ticket_nbr=$max_ticket['ticket_nbr']

 

is "ticket_nbr" supposed to be a variable integer, if so you should put in the "$"

 

It seems like you are looking for a ticket number that has the number "ticket_nbr"

 

Could be me.

 

 

 

Link to comment
Share on other sites

Well, I was able to change the query to get it to work.  Thank you everyone for your help, especially sasa.  Your idea for finding it in an array got me to thinking that it would be best to setup my query that way.  I am new to PHP and do not have much experience with Arrays so after some research I was able to find a method to setup the query to pull data as an array.

 

<?php
mysql_select_db($database_itc_admin, $itc_admin);
$max_query = "SELECT max(ticket_nbr) as tkt FROM itc_tickets";
$max_res = mysql_query($max_query, $itc_admin) or die(mysql_error());
$max_row = mysql_fetch_array($max_res);


if (isset($_SERVER['QUERY_STRING'])) {
  header("Location:view_ticket.php?ticket_nbr={$max_row['tkt']}");
  }
  
}
?>

 

Now my only issue is that it works fine on my 4.1 version of MySQL but not with my 5.0 version of MySQL.  I get the following error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1.

 

This might be for another forum.

 

I seriously would like to thank everyone for helping with this issue.  It's nice to have a forum where you can ask a question and actually get help.  An excellent place to learn, share and develop.

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.