dongwei2983 2013-04-15 21:43
浏览 37

PHP对象操作符“ - >”被读作PHP结束“?>”[复制]

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>
  • 写回答

1条回答 默认 最新

  • dq05304 2013-04-15 23:34
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)