optikalefx Posted August 5, 2007 Share Posted August 5, 2007 i have a text box that saves to a database. www.4tenproductions.com/jrpass.php i also have pictures on a server, that each have a unique number. www.4tenproductions.com/ir/uploadedfiles/picture1.png then there is a website that grabs all the info and uses it www.robbertlaw.com i want to be able to type in the text box <include picture# 15> Or something easy like that and then when i load robbertlaw.com it translates it into this: <? $con = mysql_connect("xxxx","xxxx","xxxx"); mysql_select_db("update1", $con); $sql = mysql_query("SELECT pic FROM pics WHERE num ='15'"); while($row = mysql_fetch_array($sql)) { echo "<img src='http://www.4tenproductions.com/ir/uploadedfiles2/" . $row['pic'] . "'></td></tr>"; } ?> but i also want to make sure if u go back to the text box, it shows up as <include picture: 15> and still when you go to robbertlaw.com it uses that code to actually generate the picture. is this possible at all? just a note, when you submit the textbox to the database this is the code: $myText = mysql_real_escape_string($_POST["teampage"]); so its escaping, and the reason for that is so that you can use single quotes without messing the code up. Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/ Share on other sites More sharing options...
wildteen88 Posted August 5, 2007 Share Posted August 5, 2007 What you'll want to do is create a function call getImages which parses the text in $myText to translate <include picture# 15> into the appropriate image. <?php $con = mysql_connect("xxxx", "xxxx", "xxxx"); mysql_select_db("update1", $con); // this function gets called which returns the appripitate image function getImage($img) { $query = "SELECT pic FROM pics WHERE num ='$img'"; $result = mysql_query($query); // check there was one result from the query if(mysql_num_rows($result) == 1) { // get the result $row = mysql_fetch_assoc($result); // return the html for the html return '<img src="http://www.4tenproductions.com/ir/uploadedfiles2/' . $row['pic'] . '">'; } else { // image not found in database return '[img#' . $img' Not found]'; } } // dummy text $txt = 'Hello world! <include picture# 1> Welcome to my site! <include picture# 6>'; // use regex to replace <include picture# 123> with the appropiate image // this will call the getImage function. $new_txt = preg_replace('/<include picture# ([0-9]+)>/ise', "getImage($1)", $txt); echo $txt . '<hr />' . $new_txt; ?> You're best of running this code when you get the page data out of the database. Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316146 Share on other sites More sharing options...
optikalefx Posted August 5, 2007 Author Share Posted August 5, 2007 I really think this is gonna work great. but i just uploaded with the right sql connect info as testing.php and it shows nothing.. im trying to review the code and see if there are errors, but why wouldnt it echo anything? Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316150 Share on other sites More sharing options...
optikalefx Posted August 5, 2007 Author Share Posted August 5, 2007 yea i just tried it on my page that shows to the public too, and its blank...something isnt right and i just cant put my finger on it Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316157 Share on other sites More sharing options...
wildteen88 Posted August 5, 2007 Share Posted August 5, 2007 I had a slight typo. Try this: <?php $con = mysql_connect("xxxx", "xxxx", "xxxx"); mysql_select_db("update1", $con); // this function gets called which returns the appripitate image function getImage($img) { $query = "SELECT pic FROM pics WHERE num ='$img'"; $result = mysql_query($query); // check there was one result from the query if(mysql_num_rows($result) == 1) { // get the result $row = mysql_fetch_assoc($result); // return the html for the html return '<img src="http://www.4tenproductions.com/ir/uploadedfiles2/' . $row['pic'] . '">'; } else { // image not found in database return '[img#' . $img . ' Not found]'; } } // dummy text $txt = 'Hello world! <include picture# 1> Welcome to my site! <include picture# 6>'; // use regex to replace <include picture# 123> with the appropiate image // this will call the getImage function. $new_txt = preg_replace('/<include picture# ([0-9]+)>/ise', "getImage($1)", $txt); echo $txt . '<hr />' . $new_txt; ?> Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316281 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 I really wished that worked, i see what you changed, but to no avail. can i email you and trust you with the database login info to test it out and see if it works? Ill keep going thru and see whats wrong but, let me know if we can talk that way. my email is sean@4tenonline.com Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316396 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 Iv tried everything i can think of i made your code over again, changing the database stuff to the exact same codes that i tested and worked i basically connected, ran a query and echoed the picture, and that worked great. so heres the new code that still shows up not working... <?php $con = mysql_connect("xxxx","xxxx","xxxx"); mysql_select_db("update1", $con); // this function gets called which returns the appripitate image function getImage($img) { $sql = mysql_query("SELECT pic FROM pics WHERE num='$img'"); while($row = mysql_fetch_array($sql)) { $url1 = "<img src='http://www.4tenproductions.com/ir/uploadedfiles2/" . $row['pic'] . "'>"; } // return the html for the html return $url1; } // dummy text $txt = 'Hello world! <include picture# 1> Welcome to my site! <include picture# 6>'; // use regex to replace <include picture# 123> with the appropiate image // this will call the getImage function. $new_txt = preg_replace('/<include picture# ([0-9]+)>/ise', "getImage($1)", $txt); echo $txt . '<hr />' . $new_txt; ?> Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316408 Share on other sites More sharing options...
teng84 Posted August 6, 2007 Share Posted August 6, 2007 can you tell us the prob with that and what do you want with that Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316411 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 the problem is that the page is blank, and it should be showing text then a picture, then text, then another picture. i updated with a diff code, and basically a new solution/problem, but smaller in a new thread. i used what i learned here, and im close, i just need to figure out one last thing, so i i figure it was a different topic Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316438 Share on other sites More sharing options...
teng84 Posted August 6, 2007 Share Posted August 6, 2007 you have to call the function getImage($img) did you do that Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316443 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 getImage is called in the pregReplace line $new_txt = preg_replace('/<include picture# ([0-9]+)>/ise', "getImage($1)", $txt); Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316455 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 My code should be working fine. I even tested it before I posted it and it worked no probs. Do you have access to your php.ini? If you do turn a setting called display_errors on and make sure error_reporting is set to E_ALL. Save the php.ini and then restart your server (Apache, IIS etc). re run your script. if you get any errors post them here in full. I have now added in a status messages. if the script is failing a specifc place you'll now know where it is failing: <?php echo 'Connecting to MySQL...<br />'; $con = mysql_connect('localhost', 'root'); mysql_select_db('test', $con); echo 'Connection established....<br /><br />'; $getImageLog = null; // this function gets called which returns the appripitate image function getImage($img) { global $getImageLog; $getImageLog .= 'Defining $query'; $query = "SELECT pic FROM pics WHERE num ='$img'"; $getImageLog .= ' - (' . $query . ') - Running query...<br />'; $result = mysql_query($query); $getImageLog .= 'Query has ran with no errors<br />Getting the image<br />'; // check there was one result from the query if(mysql_num_rows($result) == 1) { // get the result $row = mysql_fetch_assoc($result); $getImageLog .= 'Image recieved (' . $row['pic'] . ' for img#' . $img . ')<br /><br />'; // return the html for the html return '<img src="http://www.4tenproductions.com/ir/uploadedfiles2/' . $row['pic'] . '">'; } else { $getImageLog .= 'img#' . $img . ' not found<br /><br />'; // image not found in database return '[img#' . $img . ' Not found]'; } } echo 'Defining $txt variable...<br />'; // dummy text $txt = 'Hello world! <include picture# 1> Welcome to my site! <include picture# 6>'; echo '$txt variable defined. Now to parse $txt...<br />'; // use regex to replace <include picture# 123> with the appropiate image // this will call the getImage function. $new_txt = preg_replace('/<include picture# ([0-9]+)>/ise', "getImage($1)", $txt); echo 'getImage() log:<div style="padding:20px;">' . $getImageLog . '</div><br />Result....<br /><br />'; echo htmlentities($txt) . '<hr />' . $new_txt; ?> Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316747 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /hermes/web04/b1609/pow.4ten/htdocs/testing.php on line 3 Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316832 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /hermes/web04/b1609/pow.4ten/htdocs/testing.php on line 3 You getting that error with the code I provided above? Strange... I get no errors at all! Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316856 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 yea thats the error i get. all i did was take out: $con = mysql_connect('localhost', 'root'); mysql_select_db('test', $con); and put in mine. Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316864 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 What was yours? Just change localhost, root and test to your database values. Prehaps you have deleted a quote somewhere and is causing the error. Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316865 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 im using $con = mysql_connect("mysql14.powweb.com","updates","password"); mysql_select_db("update1", $con); Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316866 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 Which is line3? Seems like a strange error when there is nothing wrong with the syntax. The result of the script will be this. Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316867 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 ok your file works fine, and it even grabs the pictures from my database... could u just send me the text file of that code, idk whats wrong with mine how could you have been able to get those pictures? wihtout having my db info? Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316876 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 I'm using my own database. I'm not using yours. I have a havea table setup like so just to test my script +------+--------------+ | num | pic | +------+--------------+ | 1 | 4log.png | | 3 | Picture 4.png | +-------+-------------+ The images show because I am using your websites url. my source code Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316886 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 now im clueless. if yours works and mine doesnt... PHP Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /hermes/web04/b1609/pow.4ten/htdocs/testing.php on line 3 thats what im getting. and my sql info cant be wrong because i copy and pasted from a working script. any ideas what could be causing this? Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316938 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 attach testing.php here. There is something there that PHP doesn't like. Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-316979 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 here u go Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-317006 Share on other sites More sharing options...
wildteen88 Posted August 6, 2007 Share Posted August 6, 2007 Looks like your code gets corrupt when you upload it to your site and is causing that error. Make sure when you save the PHP file the file encoding is set to ANSI. Most Text editors should save in this format. Other encodings such as UTF-8 can cause problems. Download the attached file edit it and then upload. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-317020 Share on other sites More sharing options...
optikalefx Posted August 6, 2007 Author Share Posted August 6, 2007 it worked except you cant see picture 1 all the other numbers work. ne idea bout why picture 1 wouldnt show up? Quote Link to comment https://forums.phpfreaks.com/topic/63435-solved-interesting-create-your-own-tag/#findComment-317036 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.