This question already has an answer here:
I have this PHP written for editing records in SQL. I have an almost identical page for editing other records on another table that works just fine.
Here is my code:
<?php
$con=mysqli_connect("localhost","----","----","mitchpol_gigs");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$adds['v_venue'] = $con->/*Text-Start*/real_escape_string($_POST['v_venue']);
$adds['v_url'] = $con->real_escape_string($_POST['v_url']);
$adds['v_address'] = $con->real_escape_string($_POST['v_address']);
$sql = "
UPDATE `venues`
SET v_venue='". $adds['v_venue']. "', v_url='". $adds['v_url']. "', v_address='". $adds['v_address']. "'
WHERE v_id='$_POST[v_id]'";
if ($con->query($sql) === TRUE) {
echo "Venue edited successfully.<br><br>
Input summary:
<br>Edited: ID" . $_POST['v_id'] . "
<br>Venue: " . $_POST['v_venue'] . "
<br>URL: " . $_POST['v_url'] . "
<br>Address: " . $_POST['v_address'] . "
<br><br>";
} else {
echo 'Error: '. $con->error . '<br>';
}
include 'venueedit.php';
?>
Instead of executing the code the page returns with all the text from where I have noted in the code "Text-Start" to the end of the document.
This is the error that I get: PHP Parse error: syntax error, unexpected '$con' (T_VARIABLE) in (path)insertvenuesedit.php on line 1
It's as if the "->" is recognized as the end of the code in place of "?>".
My file is definitely a .php and not .html.
I read to make sure short_open_tag is off in my php.ini file. It is. I'm wondering if there is another php.ini variable that could cause this?
EDIT - PROBLEM SOLVED but curious about solution.
Turns out it was an issue in my editor. I'm using notepad++. I copy and pasted my code from another page and made the few edits I needed to apply it to this situation. The code was displaying as I posted it above but after closing the file and re-openeing it displayed all my code on one line. After spacing everything appropriately the code works just fine.
In other words ?php $con=mysqli_connect was posting as php$con=mysqli_connect with no space between ?php and $con.
Anybody run into that kind of thing using notepad++?
</div>
Your PHP is not being parsed. That ->
operator happens to be the first greater-than sign after the start, so the browser sees an invalid HTML tag, followed by everything that comes after it. If you had chosen to View Source in the browser, you would see all the PHP there.