Dreamweaver PHP problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
marcusreed
Forum Newbie
Posts: 7
Joined: Sat Oct 10, 2009 12:11 pm

Dreamweaver PHP problems

Post by marcusreed »

Okay...I have a page to delete a record. Heres the code:

Code: Select all

<?php require_once('Connections/tester.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
 
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($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;
}
}
 
if ((isset($_GET['TripID'])) && ($_GET['TripID'] != "")) {
$deleteSQL = sprintf("DELETE FROM tripdata WHERE TripID=%s",
GetSQLValueString($_GET['TripID'], "int"));
 
mysql_select_db($database_tester, $tester);
$Result1 = mysql_query($deleteSQL, $tester) or die(mysql_error());
 
$deleteGoTo = "trip_data.php?VehicleID=<?php echo $row_Recordset1['VehicleID']; ?>";
if (isset($_SERVER['QUERY_STRING'])) {
$deleteGoTo .= (strpos($deleteGoTo, '?')) ? "&" : "?";
$deleteGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $deleteGoTo));
}
 
$colname_Recordset1 = "-1";
if (isset($_GET['TripID'])) {
$colname_Recordset1 = $_GET['TripID'];
}
mysql_select_db($database_tester, $tester);
$query_Recordset1 = sprintf("SELECT * FROM tripdata WHERE TripID = %s", GetSQLValueString($colname_Recordset1, "int"));
$Recordset1 = mysql_query($query_Recordset1, $tester) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 
mysql_free_result($Recordset1);
?>
My problem is that when I hit my delete link, the dynamic data is not being added to the url properly. I just get an error that says: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/a/d/v/advemark/html/delete_trip_data.php on line 39

Line 39 is: $deleteGoTo = "trip_data.php?VehicleID=<?php echo $row_Recordset1['VehicleID']; ?>";


What is wrong here?
Last edited by califdon on Sat Oct 10, 2009 2:00 pm, edited 1 time in total.
Reason: added [php] and [/php] tags surrounding your code to highlight the syntax. please do likewise in future posts. thank you.
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Dreamweaver PHP problems

Post by califdon »

When the syntax is highlighted, the error is obvious. Where you think you are switching to the PHP parser ( <?php ) in line 39, it's inside quotation marks, so it is being interpreted as literal characters and ignored by the parser. Change that line to:

Code: Select all

$deleteGoTo = "trip_data.php?VehicleID=".<?php echo $row_Recordset1['VehicleID']; ?>;
Or you could assign the value to a variable, since a variable will be parsed inside double quotes (but not functions, indexed arrays, or other language constructs):

Code: Select all

$tmp=$row_Recordset1['VehicleID'];
$deleteGoTo = "trip_data.php?VehicleID=$tmp";
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Dreamweaver PHP problems

Post by Mirge »

In addition, you should start indenting for readability.
marcusreed
Forum Newbie
Posts: 7
Joined: Sat Oct 10, 2009 12:11 pm

Re: Dreamweaver PHP problems

Post by marcusreed »

I edited the code and this is what I get.

Parse error: syntax error, unexpected '<' in /home/content/a/d/v/advemark/html/delete_trip_data.php on line 39
User avatar
Mirge
Forum Contributor
Posts: 298
Joined: Thu Sep 03, 2009 11:39 pm

Re: Dreamweaver PHP problems

Post by Mirge »

marcusreed wrote:I edited the code and this is what I get.

Parse error: syntax error, unexpected '<' in /home/content/a/d/v/advemark/html/delete_trip_data.php on line 39
new code is?
User avatar
markusn00b
Forum Contributor
Posts: 298
Joined: Sat Oct 20, 2007 2:16 pm
Location: York, England

Re: Dreamweaver PHP problems

Post by markusn00b »

califdon wrote:When the syntax is highlighted, the error is obvious. Where you think you are switching to the PHP parser ( <?php ) in line 39, it's inside quotation marks, so it is being interpreted as literal characters and ignored by the parser. Change that line to:

Code: Select all

$deleteGoTo = "trip_data.php?VehicleID=".<?php echo $row_Recordset1['VehicleID']; ?>;
That should be: $deleteGoTo = "trip_data.php?VehicleID=". $row_Recordset1['VehicleID'];
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: Dreamweaver PHP problems

Post by califdon »

Oops! :oops: Absolutely right, of course. Already in PHP. I wasn't thinking clearly.
Post Reply