MySQL_Narb Posted October 15, 2009 Share Posted October 15, 2009 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 https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/ Share on other sites More sharing options...
mrMarcus Posted October 15, 2009 Share Posted October 15, 2009 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 https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937179 Share on other sites More sharing options...
MySQL_Narb Posted October 15, 2009 Author Share Posted October 15, 2009 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 https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937183 Share on other sites More sharing options...
MySQL_Narb Posted October 15, 2009 Author Share Posted October 15, 2009 ?........... Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937187 Share on other sites More sharing options...
slyte33 Posted October 15, 2009 Share Posted October 15, 2009 I've just copied your index.php to my site, and i did not get 1 error about a t_string Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937190 Share on other sites More sharing options...
Gayner Posted October 15, 2009 Share Posted October 15, 2009 133: $connect = mysql_connect("$dbhost","$dbuser","$dbpassword") or die("Connection failed!"); tcheck variable settings Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937197 Share on other sites More sharing options...
MySQL_Narb Posted October 15, 2009 Author Share Posted October 15, 2009 It has nothing to do with that, M8. Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937198 Share on other sites More sharing options...
MySQL_Narb Posted October 15, 2009 Author Share Posted October 15, 2009 ANYONE?! Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937202 Share on other sites More sharing options...
Gayner Posted October 15, 2009 Share Posted October 15, 2009 well then why 133 is like that and it's no error? can u giv us the line again.. # Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937208 Share on other sites More sharing options...
MySQL_Narb Posted October 15, 2009 Author Share Posted October 15, 2009 Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in /home/a5488351/public_html/index.php on line 134 Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937211 Share on other sites More sharing options...
Gayner Posted October 15, 2009 Share Posted October 15, 2009 Warning: preg_replace() [function.preg-replace]: Compilation failed: unmatched parentheses at offset 1 in /home/a5488351/public_html/index.php on line 134 Please supply us with the exact same code in ur Notepad or text editor... Link to comment https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937218 Share on other sites More sharing options...
MySQL_Narb Posted October 15, 2009 Author Share Posted October 15, 2009 $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 https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937223 Share on other sites More sharing options...
cags Posted October 15, 2009 Share Posted October 15, 2009 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 https://forums.phpfreaks.com/topic/177740-why-am-i-getting-this-error/#findComment-937274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.