Jump to content

Why am I getting this error?


MySQL_Narb

Recommended Posts

Error:

Parse error: syntax error, unexpected T_STRING in /home/a5488351/public_html/index.php on line 131

 

Code:

<?php

require "global_settings.php";

//connecting to the database
$connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
mysql_select_db("$db") or die("Database fail!");

//max displayed per page
$per_page = 8;

//get start variable
$start = $_GET['start'];

//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM posts"));

//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal

if (!$start)
   $start = 0;
   
//display data
$get = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$id = $row['id'];
$name = $row['name'];
$message = $row['message'];

if ($name =="$owner")
     $name = "<img src='$acrown'></img><a href='master.htm'><b> Master</a><br /></b>";

if ($name =="Palace")
     $name = "<img src='$mcrown'></img><a href='palace.htm'><b> Palace</a><br /></b>";

if ($name =="Soulze")
     $name = "<img src='$acrown'></img><a href='soulze.htm'><b> Soulze</a><br /></b>"; 

$patterns[0] = '/:)/';
$patterns[1] = '/:p/';
$patterns[2] = '/fox/';
$replacements[2] = '<img src='smileys/happy.gif'></img>';
$replacements[1] = '<img src='smileys/p.gif'></img>';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $message);

Link to comment
Share on other sites

the error message says line 131 in the file index.php .. what you have provided doesn't have 131 lines, so how about providing relevant code, ie. line 131 from index.php for starters.

 

you're going to want to change these lines:

 

$replacements[2] = '<img src='smileys/happy.gif'></img>';
$replacements[1] = '<img src='smileys/p.gif'></img>';

to...

$replacements[2] = '<img src="smileys/happy.gif" /></img>';
$replacements[1] = '<img src="smileys/p.gif" /></img>';

note the change in single-quotes to double-quotes.

 

no idea if that's line 131, but it's a start.

Link to comment
Share on other sites

When I added what you added, I got this error:

Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in /home/a5488351/public_html/index.php on line 133

 

Full index.php code:

 

<?php require "global_settings.php"; ?>
<title><?php echo $sitetitle; ?></title>
<?php session_start(); ?>
<center><font face='arial' size='2'>
<style>
a:link {
color:#24374C;
text-decoration:bold;
}

a:visited {
color:#24374C;
text-decoration:bold;
}

a:active {
outline: none;
color:#24374C;
text-decoration:bold;
}

body {background-color:#b0c4de}

div.box {
width:250px;
padding:10px;
border:3px double #000000;
margin:10px;
background-color:#74AFF2;
}

p
{
border-top-style:dotted;
border-right-style:solid;
border-bottom-style:dotted;
border-left-style:solid;
}

div.menu-blue {
BORDER-RIGHT: #333366 1px solid;
BORDER-LEFT: #6699cc 1px solid;
BORDER-TOP: #6699cc 1px solid;
BORDER-BOTTOM: #333366 1px solid;

FONT-WEIGHT: normal;
FONT-SIZE: 2px;
COLOR: #ffffff;
FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif;
BACKGROUND-COLOR: #23559C;
TEXT-DECORATION: none;
font-stretch : condensed;
}

.menu-top  {
BORDER-RIGHT: 1px solid #333366; BORDER-TOP: 1px solid #6699CC; FONT-WEIGHT: normal; FONT-SIZE: 11px; BORDER-LEFT: 1px solid #6699CC; COLOR: #FFFFFF; BORDER-BOTTOM: 1px solid #333366; FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif; BACKGROUND-COLOR: #23559C; TEXT-DECORATION: none;
font-stretch : condensed
}
</style>
<center>
<div class='menu-blue'>
<div align="center"> 
<table width="600" cellspacing="1" cellpadding="5" style="background-color:#23559C"> 
<tr> 
<td style="background-color:#FFFFFF"> 


    <div align="center"> 
    <table border="0"> 
    
    </form> 
    </table>

<p><a href="register.php"><b>Register</a> - <a href="login.php">Login</a> - <a href="logout.php">Logout</a> - <a href='search_input.php'>Search</a> - <a href='/forums/index.php'>Forums</a></b></p>

<br />
<form action="post.php" method="POST">
<span style='color:blue'><div class="box"><input type="hidden" name="name" value="<?php echo $_SESSION['username']; ?>"><br><br>
Message: <br><br><textarea name="message" rows="10">

</textarea><br><br>
<input type="submit" value="Post it!">
</form></center></span><hr>
<br>

<?php

require "global_settings.php";

//connecting to the database
$connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!");
mysql_select_db("$db") or die("Database fail!");

//max displayed per page
$per_page = 8;

//get start variable
$start = $_GET['start'];

//count records
$record_count = mysql_num_rows(mysql_query("SELECT * FROM posts"));

//count max pages
$max_pages = $record_count / $per_page; //may come out as decimal

if (!$start)
   $start = 0;
   
//display data
$get = mysql_query("SELECT * FROM posts ORDER BY id DESC LIMIT $start, $per_page");
while ($row = mysql_fetch_assoc($get))
{
// get data
$id = $row['id'];
$name = $row['name'];
$message = $row['message'];

if ($name =="$owner")
     $name = "<img src='$acrown'></img><a href='master.htm'><b> Master</a><br /></b>";

if ($name =="Palace")
     $name = "<img src='$mcrown'></img><a href='palace.htm'><b> Palace</a><br /></b>";

if ($name =="Soulze")
     $name = "<img src='$acrown'></img><a href='soulze.htm'><b> Soulze</a><br /></b>"; 

$patterns[0] = '/:)/';
$patterns[1] = '/:p/';
$patterns[2] = '/fox/';
$replacements[2] = '<img src="smileys/happy.gif" /></img>';
$replacements[1] = '<img src="smileys/p.gif" /></img>';
$replacements[0] = 'slow';
echo preg_replace($patterns, $replacements, $message);

echo "<center><b>($id)Posted by:</b> ".$name."<br /><b>".$message."<hr></b>";

}

//setup prev and next variables
$prev = $start - $per_page;
$next = $start + $per_page;

//show prev button
if (!($start<=0))
       echo "<a href='index.php?start=$prev'>Prev</a> ";

//show page numbers

//set variable for first page
$i=1;

for ($x=0;$x<$record_count;$x=$x+$per_page)
{
if ($start!=$x)
    echo " <a href='index.php?start=$x'>$i</a> ";
else
    echo " <a href='index.php?start=$x'><b>$i</b></a> ";
$i++;
}

//show next button
if (!($start>=$record_count-$per_page))
       echo " <a href='index.php?start=$next'>Next</a>";

?>

Link to comment
Share on other sites

$patterns[0] = '/:)/';

$patterns[1] = '/:p/';

$patterns[2] = '/fox/';

$replacements[2] = '<img src="smileys/happy.gif" /></img>';

$replacements[1] = '<img src="smileys/p.gif" /></img>';

$replacements[0] = 'slow';

echo preg_replace($patterns, $replacements, $message);

 

The line in bold is the line it points out.

 

Link to comment
Share on other sites

Because $patterns[0] is not a valid regular expression. The closing bracket (or parentheses if you prefer) used in the smilie, has a special meaning in regex so you need to escape it.

 

$patterns[0] = '/:\)/';

Link to comment
Share on other sites

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.