【发布时间】:2013-07-31 09:04:39
【问题描述】:
我已经盯着这个错误看了一个多小时了,我一辈子都看不出有什么问题。
这是我的错误:
解析错误:语法错误,第 42 行 C:\web\account.php 中出现意外的 '('
这是我在 html 中第一个 php 标记之后的代码(Line42 以“$searchstring”开头)。
<?php
include_once 'header.php';
include_once 'functions.php';
require_once 'login_users.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
if (!$db_server) die("Unable to connect to database:" . mysql_error());
mysql_select_db($db_database)
or die("Unable to find database:" . mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="en-us" http-equiv="Content-Language" />
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Weapon Build Creator</title>
<link href="styles/main.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.auto-style1 {
margin-top: 0px;
}
</style>
</head>
<body style="background-image: url('images/bg.jpg')">
<div id="form" style="left: 50%">
<div class="newsdiv">
<br />
<p class="title">MY BUILDS</p>
<?php //search result table
$searchstring = "SELECT buildname,weapon,category,id,author,buildname FROM weapons WHERE author="($_SESSION['username'])" "; // Line 42
$result = mysql_query($searchstring);
if (!$result) die ("Database access failed: " . mysql_error());
$rows = mysql_num_rows($result);
.... More code down here
如果你能看到请告诉我!
非常感谢!
【问题讨论】:
-
第 42 行是什么?清楚地标记它。
-
@SteelyDan - 你有很多答案。您确实应该将答案标记为已接受:-)
-
还没有人说过,所以我添加了强制性:php中的mysql函数是deprecated,所以请改用MySqli或PDO。请使用parameterized queries。为了您自己的安全。
-
错误信息准确地告诉您出了什么问题。它在第 42 行,在 account.php 中,意外字符 是
(。该行只有一个左括号……这是出乎意料的……它导致了错误……