PHP - Simple Eval Question
Basically I am making a class which displays a set of data.
Now sometimes the data returned from the database will be a unix time stamp so this needs to be displayed in a correct form. For this I use str_replace $replace - below this will contain a way of converting the data Replace is defined by: $replace = 'date(\'d-m-y\',$row_data[\'lastupdate\'])'; $row.= str_replace('{data}',eval($replace),'<td>{data}</td>'); This just gives me Parse error: syntax error, unexpected $end in C:\xampp\htdocs\z\src\lib\lib.table.php(348) : eval()'d code on line 1 Is this possible at all? Similar TutorialsWell from the fantastic response on my last post (0 replies, 80+ views), I've decided to browse A LOT of articles on how to do what I need to do. And, well I got it down to the function in PHP as Eval. I have my code set up like this: Code: [Select] $query="SELECT * FROM info"; $results = mysql_query($query); while ($row = mysql_fetch_assoc($results)) { $x = $row['pointtext']; echo $x; } As you can see this, this is a simple query to grab all the rows under pointtxt. I have only 1 at the moment which is to text it, and it echo's it fine! It echo's this: Code: [Select] Imagettftext($im, 12, 0, $start_x, $start_y, $black, 'verdana.ttf', "text to write"); This is a PHP script for TEXT-TO-IMAGE. SO then considering the echo worked, I used this code: Code: [Select] $query="SELECT * FROM info"; $results = mysql_query($query); while ($row = mysql_fetch_assoc($results)) { $x = $row['pointtext']; header("Content-Type: image/jpeg"); $im = ImageCreateFromPng("test.png"); $black = ImageColorAllocate($im, 255, 255, 255); $start_x = 10; $start_y = 20; eval($x); Imagejpeg($im, '', 100); ImageDestroy($im); } And as you can imagine, it doesn't work. As I said in my 2 day old topic, I want it to have the ability to put more text onto the image and save it. So, do I get help this time? PLEASE. Does the eval function not support the TEXT TO IMAGE got an error in the script. What, please at least answer this time. _______ Also forgot to mention that how the script doesn't work, is it displays the picture fine, but it doesn't place any text onto it. Or any I can see with the set coords. Hello there, I have a issue. My issue is that I parse PHP code executed by people via a command like so !php echo("hello there"); would output "hello there". Here is my command: case ':!php': $message = ""; for($i=4; $i <= (count($this->ex)); $i++) { $message .= $this->ex[$i]." "; } ob_start(); @eval($message); $output = ob_get_contents(); fputs($this->socket,"PRIVMSG #volt :{$output}\r\n"); ob_end_flush(); break; $message contains the code to be executed. But the problem is it won't return more than one line. I really want it to be able to output multiple lights from eval E.G if someone where to output a item that is split up into multiple lines. Does anybody know how to accomplish this? im got php code witch is there Code: [Select] <?php /* Hello World (helloworld.php) */ //Required for Active Members / Last 24 Active Members Plugins define('SCRIPTNAME', 'test.php'); //Load templates for this page to avoid extra usage of SQL queries. $LoadTemplatelist = array('test'); //Init require('./library/init/init.php'); //Set Page Title $Page_Title = get_phrase('test'); //Create & Add Breadcrumb AddBreadcrumb(array ( get_phrase('navigation_home') => $TSUE['TSUE_Settings']->settings['global_settings']['website_url'].'/?p=home&pid=1', get_phrase('test_home') => $TSUE['TSUE_Settings']->settings['global_settings']['website_url'].'/?p=test&pid='.PAGEID )); //Get Page Template $test = ''; $query = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS, MYSQL_DB); $sql = mysqli_query($query, "SELECT `filename`, `tid`, `info_hash`, `name`, `description`, `cid`, `size`, `added`, `leechers`, `seeders`, `times_completed`, `owner`, `options`, `nfo`, `sticky`, `flags`, `mtime`, `ctime`, `download_multiplier`, `upload_multiplier` FROM `tsue_torrents`, `tsue_attachments` WHERE `content_type`='torrent_images' AND `content_id` = `tid` LIMIT 0, 10"); while ($row = mysqli_fetch_array($sql)) { $test_row = ''; $description= $row['description']; $name= $row['name']; $leechers= $row['leechers']; $owner= $row['owner']; $filename= $row['filename']; $nunx= $row['tid']; $seeders= $row['seeders']; eval("\$test_row = \"".$TSUE['TSUE_Template']->LoadTemplate('test_row')."\";"); $test .= $test_row; } eval("\$test = \"".$TSUE['TSUE_Template']->LoadTemplate('test')."\";"); //Print HTML Output PrintOutput($test, $Page_Title); ?> any chance to call that code to other template? Code: [Select] <!DOCTYPE html> <html id="TSUE" lang="{$TSUE['TSUE_Language']->content_language}"> <head> <noscript><meta http-equiv=refresh content="0; URL={$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/?noscript=1" /></noscript> <base href="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/" /> <title>{$Page_Title}</title> <meta charset="{$TSUE['TSUE_Language']->charset}" /> <meta name="description" content="{$TSUE['TSUE_Settings']->settings['global_settings']['website_description']}" /> <meta name="viewport" content="width=device-width, initial-scale=0.9, maximum-scale=3.0, user-scalable=1" /> <link rel="stylesheet" href="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/style.php?l=style,fancybox,jqueryTools,forums,fileuploader,tinymce_ui,thread_prefixes,comments,downloads,image_gallery" type="text/css" media="screen" /> <link rel="Shortcut Icon" href="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/favicon.ico" type="image/x-icon" /> </head> <body> {$newAnnouncement} <!-- start #wrap --> <div id="wrap"> <div class="over_header"> <div id="header"><div class="content">{$languageSelect}</div> {$Navigation} </div> </div> <!-- start #inner --> <div id="inner"> {$test} {$breadcrumb} {$SubNavigation} <div id="plugins"> {$sidebar} <div id="content" class="mainContent {$contentWidthClass}">{$warningHTML} {$PluginsHTML} {$Output}</div> </div> </div> <!-- end #inner --> <!-- start #footer --> <div id="footer"> <div class="footer_top"></div> <div class="footer_mid"> <div id="panel"> <p> None of the files shown here are actually hosted on this server. The links are provided solely by this site\'s users. The administrator of this site cannot be held responsible for what its users post, or any other actions of its users. You may not use this site ({1}) to distribute or download any material when you do not have the legal rights to do so. It is your own responsibility to adhere to these terms.', This site is best viewed with <a href="https://www.mozilla.com/en-US/firefox/" title="Get Firefox - The Browser, Reloaded."><b>FireFox</b></a> and with 1280*1024 in resolution. Recommended BitTorrent client\'s: <a href="https://www.utorrent.com/download.php" title="Get uTorrent"><b>uTorrent</b></a> - <a href="http://pingpong-abc.sourceforge.net/download.php" title="Get ABC"><b>ABC</b></a> </p> </div> <p class="slide"><a href="#" class="btn-slide">Disclaimer</a></p> </div> <div class="footer_btm"> <div class="wrap"> <!-- Warning: Please note that you are not permitted to remove the TSUE branding / copyright unless you have purchased the branding-free option: htt://templateshares-ue.net/purchase/ --> <p>Powered by Templateshares Ultimate Edition {$TSUE['TSUE_Settings']->settings['global_settings']['tsue_version']} © Copyright 2011 <a href="http://www.templateshares-ue.net">www.templateshares-ue.net</a></p> <!-- Warning: Please note that you are not permitted to remove the TSUE branding / copyright unless you have purchased the branding-free option: htt://templateshares-ue.net/purchase/ --> </div> </div> </div> <!-- end #footer --> </div> <!-- end #wrap --> <script type="text/javascript"> //<![CDATA[ {$main_javascript} //]]> </script> {$loadjavascriptsCache} <script type="text/javascript" src="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/js/tiny_mce/tiny_mce_gzip.js"></script> <script type="text/javascript"> tinyMCE_GZ.init ({ plugins : '-inlinepopups,-smilies,-quote,-tsuecode,-autoresize', themes : 'tsue', languages : '', disk_cache : true, debug : false }); </script> <script type="text/javascript"> //<![CDATA[ {$tinymce_init} //]]> </script> <img src="{$TSUE['TSUE_Settings']->settings['global_settings']['website_url']}/cron.php?rq={$TIMENOW}" alt="" width="1" height="1" /> <script type="text/javascript"> jQuery(document).ready(function(){ jQuery(".btn-slide").click(function(){ jQuery("#panel").slideToggle("slow"); jQuery(this).toggleClass("active"); return false; }); }); </script> </body> </html> as u see im trying to call it {$test} but its dont work im get error Code: [Select] [29-Jan-2012 13:43:46] PHP Notice: Undefined variable: test in /home/admincom/public_html/tsue/library/functions/functions_global.php(0) : eval()'d code on line 24 Thanks Hello to everyone I would like to ask for this simple question.. Im trying to put if and else condition on my php code. However this condition is not working.. Code: [Select] if($file == #3#){ echo "No results found"; }else{ echo "results has been found"; } This variable $file is the result after i used an API.. If the API does not see any results they would return #3# as the result. This means they returned a transaction code of 3 which you can see here http://developer.textapp.net/WebService/TransactionCodes.aspx means that there was nothing to return. The condition does not function well even if i make 3 or #3# as part of the condition. Can you help me guys? thanks Hello everyone! I am a new user and I have a simple question. How do I set a password for a user to log in to my site with PHP? I have no MySQL database just a iOS code/host app. I know this isn’t secure but only me and my friends are on the site. Any help is appreciated. what does the # symbol do in php(e.x index.php?cat=1#privacy)? How can i use it? From what i 've seen you use it for changing a whole div without reloading the page like tabs.. I've seen this, Code: [Select] <?php } ?> in a lot of scripts at the very end of the script. What does this piece of code do? Lets say I have: $var=5; What would an output look like to get me: 1<br> 2<br> 3<br> 4<br> 5<br> Im at a complete loss! Thanks! Hey! I have a drop down field for my "register" form, but this is clearly easy to edit, I just used tamperdata for firefox and yeah...pretty easy, is there any way that you could prevent tampering with the values when submitting this form!? Hello there fellow programmers, I was just wondering if there was any difference between doing this: Code: [Select] echo "Say Something Here"; and this Code: [Select] echo "Say "; echo "Something "; echo "Here"; Thank you in advance. Notice: I am aware of the fact that they will output the same thing, my question is regarding resources. if someone can help me out with this, its quite simple but I can't seem to get it to work.. Basically, this is the code I have for now, the issue is if I have 0 product or items, I don't want the sorting option to show up on the page, from the code below, what line can I add tosay that if there is no products in a category, not to show the SORT feature. thanks in advance if anyone can help. {if isset($orderby) AND isset($orderway)} <!-- Sort products --> {if isset($smarty.get.id_category) && $smarty.get.id_category} {assign var='request' value=$link->getPaginationLink('category', $category, false, true)} {elseif isset($smarty.get.id_manufacturer) && $smarty.get.id_manufacturer} {assign var='request' value=$link->getPaginationLink('manufacturer', $manufacturer, false, true)} {elseif isset($smarty.get.id_supplier) && $smarty.get.id_supplier} {assign var='request' value=$link->getPaginationLink('supplier', $supplier, false, true)} {else} {assign var='request' value=$link->getPaginationLink(false, false, false, true)} {/if} <form id="productsSortForm" action="{$request|escape:'htmlall':'UTF-8'}"> <select id="selectPrductSort" onchange="document.location.href = $(this).val();"> <option value="{$link->addSortDetails($request, $orderbydefault, $orderwaydefault)|escape:'htmlall':'UTF-8'}" {if $orderby eq $orderbydefault}selected="selected"{/if}>{l s='--'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'price', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Price: lowest first'}</option> <option value="{$link->addSortDetails($request, 'price', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'price' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Price: highest first'}</option> {/if} <option value="{$link->addSortDetails($request, 'name', 'asc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'asc'}selected="selected"{/if}>{l s='Product Name: A to Z'}</option> <option value="{$link->addSortDetails($request, 'name', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'name' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='Product Name: Z to A'}</option> {if !$PS_CATALOG_MODE} <option value="{$link->addSortDetails($request, 'quantity', 'desc')|escape:'htmlall':'UTF-8'}" {if $orderby eq 'quantity' AND $orderway eq 'desc'}selected="selected"{/if}>{l s='In-stock first'}</option> {/if} </select> <label for="selectPrductSort">{l s='Sort by'}</label> </form> <!-- /Sort products --> {/if} I can't figure out why im getting an error with this code. if ($notif = mysql_query("SELECT * FROM notifications_1 WHERE recieverid='". $_SESSION['id']."' ORDER BY read ASC, id DESC") or die (mysql_error())); { Code: [Select] 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 'read ASC, id DESC' at line 1 I'm teaching myself php and mysql -- and my coding is a little rough. But what i'm trying to do is display information from a mysql table in another table on a website. I can do this just fine simply displaying the table, but i want a little something different. I am only displaying one column of the table, instead of displaying it all in one column, i want to display the information in 5 columns. for example..... the table from mysql has names scott, john, james, mary, simon. with the code I have i can make it display like this: scott scott scott scott scott john john john john john james james james james james mary mary mary mary mary simon simon simon simon simon i want it to diplay like this: scott john james mary simon new names will continue down here is my code: <?php require ("connectigb.php"); $result = mysql_query ("SELECT pledgeName FROM pledgewall"); $fields_num = mysql_num_fields($result); echo "<center> <h1>TSA It Gets Better Pledge Wall</h1>"; echo "<table border='1' align='center' style='width:960px;'><tr>"; while($row = mysql_fetch_row($result)) { echo "<tr>"; // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row as $cell) if ($cell != "") { for ($j=0; $j<5; $j++) { echo "<td>$cell</td>"; } } echo "</tr>\n"; } mysql_free_result($result); echo "</table></center>"; ?> any ideas on what i can do here, i'm sure this is a simply fix. i just haven't come across it yet. thanks for the help in advance. Hi. I have an ID in md5 format but in the database its not. I pass the md5 ID to a page and then I am trying to load the correct record via a look up in the database of that ID. Im wondering is this code possible? <?php $query = mysql_query("SELECT * FROM table WHERE ".md5(tableID)." = $ID"); ?> Thanks Hi,
I am trying to convert a php function into perl and need to understand the following line in red :
function pagination($query, $per_page = 10,$page = 1, $url = '?'){ $query = "SELECT COUNT(*) as `num` FROM {$query}"; $row = mysql_fetch_array(mysql_query($query)); $total = $row['num']; $adjacents = "2"; $page = ($page == 0 ? 1 : $page); $start = ($page - 1) * $per_page; $prev = $page - 1; $next = $page + 1; $lastpage = ceil($total/$per_page); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1) { ......................................... What will be the output of this line above in red. Thank you very much. Regards. Tonya Hi, I'm working on a product page and I got it to list all the products in one column of a table, but when I add a second column it just duplicates the first column. What do I need to change? Code: [Select] <?php require_once("functions.php"); ?> <!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 http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <style type="text/css"> td { border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: #30C; border-right-color: #30C; border-bottom-color: #30C; border-left-color: #30C; } </style> </head> <body> <form action="" method="post" name="catalog"> <?php DatabaseConnection(); $query = "SELECT * FROM treats"; $result_set = mysql_query($query) or die(mysql_error()); $output = "<table>"; while ($row = mysql_fetch_array($result_set)) { $output .= (" <tr> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> <td width=\"400px\">" . $row['product_title']."<br /> ".$row['product_Description']."<br />" .$row['price'] . "<br /> Quantity: <input name=\"quantity\" type=\"text\" size=\"2\" /> </td> </tr> "); } $output .= "</table>"; echo $output; ?> </form> </body> </html> Hi guys, this function below is for card validation, however anycard i enter i get the invalid card number, this is not connected to any gateways, this is just an Luhn card validation demonstration. can you tell me please why i get that? <?php if ($_POST['pay']) { $cardNo = addslashes(strip_tags($_POST['cardNo'])); function luhnCheck($cardNo) { $cardNo = str_replace(" ", "", trim($cardNo)); if(!is_numeric($cardNo) or strlen($cardNo)>19) return false; $skip = $newNum = $total = 0; for($i=0;$i<=(strlen($cardNo)-1);$i++) { if($skip ==0) { $tmpNum = ($cardNo[$i]*2); $total += (strlen($tmpNum)==2 ? (substr($tmpNum, 0, 1)+substr($tmpNum, 1)) : $tmpNum); $skip = 1; }else{ $total += $cardNo[$i]; $skip = 0; } } return (($total % 10) == 0); } /* Example Usage */ if(luhnCheck($_GET['cc'])) { echo("Valid Number."); }else{ echo("Invalid Number."); } } ?> <form name="confirm" method="post" action=""> <input type="text" name="cardNo"> <input type="submit" name="pay" value="Pay Now"> </form> I know it could be a issue with this line if(luhnCheck($_GET['cc'])) { but im wondering where should and how put this cc in my form? regards hello all I'm VERY new to php and I just have a simple question how do I bold the output text of this string echo $row['name']."<BR>"; i saw this in a php function page he http://php.net/manual/en/function.stristr.php the line is if(stristr($string, 'earth') === FALSE) { specifically this this code <?php $string = 'Hello World!'; if(stristr($string, 'earth') === FALSE) { echo '"earth" not found in string'; } // outputs: "earth" not found in string ?> what is the significance of the '===' in there does it mean something? is there any difference from the '==' or the '=' ? SELECT * FROM `table1` VS SELECT * FROM table1 Which one is the best one to be used? n what is the difference? Is using backticks can prevent me from sql injection which means better to use?? thanks in advance |