
doofy
Members-
Posts
40 -
Joined
-
Last visited
-
Days Won
1
Everything posted by doofy
-
damn the code provided did work, it wasn't producing errors because there wasn't a valid http as it was in brackets. Thanks a million!
-
<?php function hyperlink ($string) { $string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string); return $string; } //connection $result = mysql_query("SELECT * FROM top_web_articles ORDER BY ID DESC"); echo "<table border='0'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".$row['Category']."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>". $row['ArticleName'] ."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".hyperlink($row['ArticleDescription'])."</td></tr>"; echo "<tr><td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'><a href='". $row['URL'] . "' target='_blank'><img src='http://www.thenewsguys.ca/images/read entire article.png' alt='' width='130' height='11' border='0' /></a></td>"; echo "</tr>"; echo "<td align='left' valign='top'> </td>"; } echo "</table>"; mysql_close($con); ?>
-
I've copied and pasted it now. It's producing no errors but the function doesn't seem to be applying.
-
Line 146 is what I put in bold. When I remove the semi colon, I get no error, but it doesn't function either. Weird!!!
-
That seemed to produce the exact same error. It's not happy with what I did at all. Thanks for the reply though, I appreciate the effort.
-
I hope I'm not being a vampire here sucking the life out of you guys, but I can't find any resources in google that explains how to properly use this function in a mysql array. All it does is add a url for any urls added in plaintext. Code: --- <?php function hyperlink ($string) { $string = preg_replace('#(^|\s)([a-z]+://([^\s\w/]?[\w/])*)#is', '\\1<a href="\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)((www|ftp)\.([^\s\w/]?[\w/])*)#is', '\\1<a href="http://\\2" target="_blank">\\2</a>', $string); $string = preg_replace('#(^|\s)(([a-z0-9._%+-]+)@(([.-]?[a-z0-9])*))#is', '\\1<a href="mailto:\\2">\\2</a>', $string); return $string; } // mysql connection $result = mysql_query("SELECT * FROM top_web_articles ORDER BY ID DESC"); echo "<table border='0'>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>".$row['Category']."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>". $row['ArticleName'] ."</td></tr>"; echo "<td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'>"hyperlink(. $row['ArticleDescription'] .);"</td></tr>"; echo "<tr><td class='newstitle' align='left' valign='top' bgcolor='#D6D6D6'><a href='". $row['URL'] . "' target='_blank'><img src='http://www.thenewsguys.ca/images/read entire article.png' alt='' width='130' height='11' border='0' /></a></td>"; echo "</tr>"; echo "<td align='left' valign='top'> </td>"; } echo "</table>"; mysql_close($con); ?> --- Error: "Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/doofyd5/public_html/trevor/playground/displayarticles.php on line 146" (Clearly an error where I'm abusing the heck out of the bolded line. Any ideas on how to properly code this?
-
newb needs help: Single quotes going into a database... err...
doofy replied to doofy's topic in PHP Coding Help
Ok, I did it section by section, and edited the debugged code. It works perfectly. Thank you all for your time, I truly appreciate the support, especially for someone as inept as me. If this were building computers or tweaking them, I'd totally help, but this programming is just over my head being only 4 days in. Thank you for your kindness and generosity. -Chris -
newb needs help: Single quotes going into a database... err...
doofy replied to doofy's topic in PHP Coding Help
ok, thanks for takingg the time to help me. I'd be screwed without this awesome community. -
newb needs help: Single quotes going into a database... err...
doofy replied to doofy's topic in PHP Coding Help
I've changed so much around now that I don't know where I'm at. I've removed the $posts in the sql query, and echoed as recommended. It works fine until I add a single quote ('), and then it display nothing in the variables if I do. --- code: // connection echo '$ArticleDescription before changes: "' . $ArticleDescription . '"<br>'; echo '$URL before changes: "' . $URL . '"<br>'; $ArticleDescription=mysql_real_escape_string(mb_convert_encoding($ArticleDescription, 'UTF-8', 'UTF-8')); $URL=mysql_real_escape_string(htmlspecialchars($URL, ENT_QUOTES)); // ENT_QUOTES converts all quotes to HTML equivalent. ENT_COMPAT converts only Double Quotes. $ArticleDescription=str_replace('\"','"',$ArticleDescription); echo '$ArticleDescription after changes: "' . $ArticleDescription . '"<br>'; echo '$URL after changes: "' . $URL . '"<br>'; $sql="INSERT INTO web_articles (ArticleDescription, URL)"; if (mysql_query($sql,$con)) { echo "Sucessfully posted"; } else { echo "An unexpected error occured."; // ADMIN ERROR MESSAGE echo mysql_error(); } mysql_close($con) ?> --- form input: --- $ArticleDescription: asdf ' asdf $URL: asdf --- output: --- $ArticleDescription before changes: "" $URL before changes: "" $ArticleDescription after changes: "" $URL after changes: "" An unexpected error occured.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1 --- Thank you for the continued patience. -
newb needs help: Single quotes going into a database... err...
doofy replied to doofy's topic in PHP Coding Help
Damn, typo when I was stripping the code. Now I'm getting "An unexpected error occured.You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'asdf','asdf')' at line 1" I'll echo the code as requested. Thanks again for all this help!!! -Chris -
newb needs help: Single quotes going into a database... err...
doofy replied to doofy's topic in PHP Coding Help
Following error message occured: "Warning: Unexpected character in input: ''' (ASCII=39) state=1 in /home/doofyd5/public_html/trevor/admin/addtop5stories.php on line 18 Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/doofyd5/public_html/trevor/admin/addtop5stories.php on line 23" Thanks again for dealing with me, you don't understand how much I appreciate this. -Chris -
newb needs help: Single quotes going into a database... err...
doofy replied to doofy's topic in PHP Coding Help
Thanks for the quick reply and bare with me. I've added "$ArticleDescription=mysql_real_escape_string($ArticleDescription);" to the code but I'm still getting the single quote error when trying to use a '. Any additional help for this dummy would be mighty appreciated. Thanks in advance for your patience! -Chris -
I have a simple form that connects to this php page. Only two variables, "ArticleDescription" & "URL". I've tried a number of things, several of which are listed below, but have had no success. I'm certain it's just my idiocy but am requesting some help with this. I KNOW it's an easy fix, it's just over my head, I'm only four days into programming, so I'm a complete newb. Your kindness is requested. ---- <?php // connection mysql_select_db("doofyd5_comments", $con); $ArticleDescription=mb_convert_encoding($ArticleDescription, 'UTF-8', 'UTF-8'); $URL=htmlspecialchars($URL, ENT_QUOTES); $ArticleDescription=str_replace('\"','"',$ArticleDescription); $sql="INSERT INTO web_articles (ArticleDescription, URL) VALUES ('$_POST[ArticleDescription]','$_POST')"; if (mysql_query($sql,$con)) { header ("location:desiredurl"); require_once('desiredurl"); exit(); } else { echo "You may have added a single quote to the article description!"; } mysql_close($con) ?> ----
-
I removed the broken while loop, and added SELECT UNIQUE. Problem solved, please close. Cheers, Doofy
-
Hi there, I'm new to this (2 days into it) but I've managed to rummage together 2 tables, and PHP to input into the database. My issue now is that I want to merge one of the two tables into the other. I've managed to do this, but for some reason I'm getting duplicate entries from the 2nd table. Code: //mysql connection $query = "SELECT ArticleDescription, URL FROM top_web_articles"or die ("query is messed up"); $result = mysql_query($query); while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { mysql_query("INSERT INTO web_articles (ArticleDescription, URL) SELECT ArticleDescription, URL FROM top_web_articles") or die ("Failed merge!"); } echo ("Successful merge!"); ?> Does anyone have any suggestions as to where I went wrong? Thanks in advance, Doofy.