Jump to content

code not working in v 5.4.16 works in v 5.3.8


groengoen

Recommended Posts

The following code works in v 5.3.8 but not in v 5.4.16. I get the error: Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\autoroller\php\delete_customer.php on line 57

This is the code:

 

 

<?php

session_start();
// if session variable not set, redirect to login page
if (!isset($_SESSION['authenticated'])) {
exit;
// Old code
//include("dbinfo.inc.php");
//mysql_connect("localhost","$username","$password") or die("Error: ".mysqlerror());
//mysql_select_db("$database"); 
// End Old code
 
// New mysqli code
// connect to the database
include('connect-db.php');
// End new code
//get the variables we transmitted from the form
$refno = $_POST[refno];
$sql = "DELETE FROM customer WHERE refno = ".$refno;
 
 
// New code for mysqli delete
// delete record from database
if ($stmt = $mysqli->prepare("DELETE FROM customer WHERE refno = ? LIMIT 1"))
{
$stmt->bind_param("i",$refno);     
$stmt->execute();
if ($stmt->affected_rows > 0) {
$deleted = true;
} else {
$deleted = false;
if ($stmt->errno == 1451) {
$error = ' has dependent project records and cannot be deleted.';
} else {
$error = 'There was a problem deleting the client.';
}
}
$stmt->close();
}
else
{
echo "ERROR: could not prepare SQL statement.";
}
$mysqli->close();
 
// redirect user after delete is successful
 
// Old code
//mysql_query($sql) or die ("Error: ".mysql_error());
// End Old code
if ($deleted == true) {
echo "Client " .$refno . " deleted." ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
} else {
echo "Client " .$refno . $error ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
}    
?>

 

I have checked that mysqli is installed on the latter.

 

Any advice would be most welcome,

 

 

Please use code tags (not quote tags) and indent your code.

 

 

<?php
session_start();
// if session variable not set, redirect to login page
if (!isset($_SESSION['authenticated'])) {
    header('Location: http://crm.autorolle...er/index.php');
    exit;
}
// Old code
//include("dbinfo.inc.php");
//mysql_connect("localhost","$username","$password") or die("Error: ".mysqlerror());
//mysql_select_db("$database");
// End Old code

// New mysqli code
// connect to the database
include('connect-db.php');
// End new code
//get the variables we transmitted from the form
$refno = $_POST[refno];
$sql = "DELETE FROM customer WHERE refno = ".$refno;


// New code for mysqli delete
// delete record from database
if ($stmt = $mysqli->prepare("DELETE FROM customer WHERE refno = ? LIMIT 1"))
{
    $stmt->bind_param("i",$refno);     
    $stmt->execute();
    if ($stmt->affected_rows > 0) {
        $deleted = true;
    } else {
        $deleted = false;
        if ($stmt->errno == 1451) {
            $error = ' has dependent project records and cannot be deleted.';
        } else {
            $error = 'There was a problem deleting the client.';
        }
    }
    $stmt->close();
}
else
{
    echo "ERROR: could not prepare SQL statement.";
}
$mysqli->close();

// redirect user after delete is successful

// Old code
//mysql_query($sql) or die ("Error: ".mysql_error());
// End Old code
if ($deleted == true) {
    echo "Client " .$refno . " deleted." ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
} else {
    echo "Client " .$refno . $error ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
}    
?>

 

The syntax here

 

 

if ($deleted == true) {
    echo "Client " .$refno . " deleted." ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
} else {
    echo "Client " .$refno . $error ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
}  

 

is a bit bizarre, and I'm guessing the problem may be that short_tags are not enabled, so the <? is not recognized.

Sorry boompa about the quotes, the code is :

<?php
session_start();
	// if session variable not set, redirect to login page
	if (!isset($_SESSION['authenticated'])) {
		header('Location: http://crm.autoroller.ie/autoroller/index.php');
		exit;
	} 
// Old code
//include("dbinfo.inc.php");
//mysql_connect("localhost","$username","$password") or die("Error: ".mysqlerror());
//mysql_select_db("$database"); 
// End Old code

// New mysqli code
// connect to the database
include('connect-db.php');
// End new code
//get the variables we transmitted from the form
$refno = $_POST[refno];
$sql = "DELETE FROM customer WHERE refno = ".$refno;


// New code for mysqli delete
// delete record from database
if ($stmt = $mysqli->prepare("DELETE FROM customer WHERE refno = ? LIMIT 1"))
{
		$stmt->bind_param("i",$refno);     
		$stmt->execute();
		if ($stmt->affected_rows > 0) {
			$deleted = true;
		} else {
			$deleted = false;
			if ($stmt->errno == 1451) {
				$error = ' has dependent project records and cannot be deleted.';
			} else {
				$error = 'There was a problem deleting the client.';
			}
		}
		$stmt->close();
}
else
{
		echo "ERROR: could not prepare SQL statement.";
}
$mysqli->close();

// redirect user after delete is successful

// Old code
//mysql_query($sql) or die ("Error: ".mysql_error());
// End Old code
if ($deleted == true) {
	echo "Client " .$refno . " deleted." ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
} else {
	echo "Client " .$refno . $error ?> <a href='view_customers.php'>Return to View/Edit customer</a> <?  ;
}    
?>

I don't get what you mean by short_tags.

 

Actually, Cracka,  the ; is at what I thought was the end of the echo statement. Maybe I'm wrong.

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.