snteran Posted July 9, 2007 Share Posted July 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
pocobueno1388 Posted July 9, 2007 Share Posted July 9, 2007 Change the line you got the error on to this: $insertGoTo .= "?" . "ticket_nbr='{$max_ticket['ticket_nbr']}'"; Quote Link to comment Share on other sites More sharing options...
snteran Posted July 9, 2007 Author Share Posted July 9, 2007 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)); } ?> Quote Link to comment Share on other sites More sharing options...
calabiyau Posted July 9, 2007 Share Posted July 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
snteran Posted July 9, 2007 Author Share Posted July 9, 2007 I get the same error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING Quote Link to comment Share on other sites More sharing options...
per1os Posted July 9, 2007 Share Posted July 9, 2007 $insertGoTo .= "?ticket_nbr=" . $max_ticket['ticket_nbr']; Try that out. Quote Link to comment Share on other sites More sharing options...
sasa Posted July 9, 2007 Share Posted July 9, 2007 try $insertGoTo .= "?" . "ticket_nbr=".$max_ticket[0]; Quote Link to comment Share on other sites More sharing options...
snteran Posted July 9, 2007 Author Share Posted July 9, 2007 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 Quote Link to comment Share on other sites More sharing options...
clearstatcache Posted July 10, 2007 Share Posted July 10, 2007 $insertGoTo .= "?ticket_nbr=" . $max_ticket['ticket_nbr']; this should work.....make sure $max_ticket['ticket_nbr'] really has a value... Quote Link to comment Share on other sites More sharing options...
rcorlew Posted July 10, 2007 Share Posted July 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
snteran Posted July 10, 2007 Author Share Posted July 10, 2007 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.