groengoen Posted July 31, 2013 Share Posted July 31, 2013 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'])) { 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 have checked that mysqli is installed on the latter. Any advice would be most welcome, Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/ Share on other sites More sharing options...
groengoen Posted July 31, 2013 Author Share Posted July 31, 2013 P.S. line 57 is the last line (i.e. "?>") Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/#findComment-1442830 Share on other sites More sharing options...
Solution boompa Posted July 31, 2013 Solution Share Posted July 31, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/#findComment-1442832 Share on other sites More sharing options...
AbraCadaver Posted July 31, 2013 Share Posted July 31, 2013 You have a ; at the end of those lines, why? They should be at the end of the echo statement. Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/#findComment-1442849 Share on other sites More sharing options...
groengoen Posted July 31, 2013 Author Share Posted July 31, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/#findComment-1442864 Share on other sites More sharing options...
groengoen Posted July 31, 2013 Author Share Posted July 31, 2013 How do you enable short_tags? Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/#findComment-1442865 Share on other sites More sharing options...
groengoen Posted July 31, 2013 Author Share Posted July 31, 2013 Oh! I see what you mean. I changed <? to <?php and got a completely different error which I will have to debug. Thanks a lot! Quote Link to comment https://forums.phpfreaks.com/topic/280684-code-not-working-in-v-5416-works-in-v-538/#findComment-1442867 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.