Jump to content

code not working in v 5.4.16 works in v 5.3.8


Go to solution Solved by boompa,

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,

 

 

  • Solution

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.

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.