PHP - Help With Getting To Execute Code From A Db
Hi Guys,
I have the following script which works fine for GoogleMaps Code: [Select] <?php require'EasyGoogleMap.class.php'; $gm = & new EasyGoogleMap("rYvyXhRFPYW5tkV_IE5hWxecUidHAYjJhBSp59xzQuNZcoxNYCiaum4_Xb66Fw"); $gm->SetMarkerIconStyle('STAR'); $gm->SetMapZoom(10); $gm->SetAddress("10 market st, san francisco"); $gm->SetInfoWindowText("This is the address # 1."); $gm->SetAddress("Manila, Philippines"); $gm->SetInfoWindowText("This is Philippine Country."); $gm->SetSideClick('Philippines'); ?> <html> <head> <title>EasyGoogleMap</title> <?php echo $gm->GmapsKey(); ?> </head> <body> <?php echo $gm->MapHolder(); ?> <?php echo $gm->InitJs(); ?> <?php echo $gm->GetSideClick(); ?> <?php echo $gm->UnloadMap(); ?> </body> </html> I've now coded that static page to take the following, and within the GoogleMaps database field entered in exactly the following $gm->SetAddress("10 market st, san francisco"); $gm->SetInfoWindowText("This is the address # 1."); $gm->SetAddress("Manila, Philippines"); $gm->SetInfoWindowText("This is Philippine Country."); $gm->SetSideClick('Philippines'); Code: [Select] <?php $maps_find = $OO_Open->newFindCommand('Maps'); $maps_find->AddFindCriterion('AccountName','xx'); $maps_result = $maps_find->execute(); $maps_row = current($maps_result->getRecords()); $Gdata = $maps_row->getField('GoogleMaps'); //echo $Gdata; //exit; ?> <?php require'EasyGoogleMap.class.php'; $gm = & new EasyGoogleMap("my key"); $gm->SetMarkerIconStyle('GT_FLAT'); $gm->SetMapZoom(10); $gm->SetMapWidth(1080); # default = 300 $gm->SetMapHeight(550); # default = 300 echo $maps_row->getField('GoogleMaps'); //eval("\$Gdata = \"$Gdata\";"); ?> <html> <head> <title>EasyGoogleMap</title> <?php echo $gm->GmapsKey(); ?> </head> <body> <?php echo $gm->MapHolder(); ?> <?php echo $gm->InitJs(); ?> <?php echo $gm->GetSideClick(); ?> <?php echo $gm->UnloadMap(); ?> </body> </html> Is there way of getting the $maps_row->getField('GoogleMaps'); command to behave as if it was php (when I echo it, it does display the code as text). I'm not using the FileMaker db to store the code, I thought eval function was the answer but not had much luck. Many Thanks for the advice Jalz Similar Tutorialsi need this code to execute faster, is there a faster way? function all_word_combinations($all_words_unknown,$previous_string=''){ $all_words_2=array(); if(is_array($all_words_unknown)){ $all_words_array=$all_words_unknown; }else{ $all_words_array=explode(' ',trim($all_words_unknown)); } $item2remove='the'; $all_words_array=explode(' ',trim(str_replace($item2remove.' ','',str_replace(' '.$item2remove,'',(implode(' ',$all_words_array)))))); if(count($all_words_array)>1){ $previous_array=explode(' ',$previous_string); foreach($all_words_array as $one_word){ if(!in_array($previous_string.$one_word,$all_words_2) && !in_array($one_word,$previous_array)){ $all_words_2[$previous_string.$one_word]=$previous_string.$one_word; $all_words_2=array_merge($all_words_2,all_word_combinations($all_words_array,$previous_string.$one_word.' ')); } } return $all_words_2; }else{return $all_words_array;} } $one_word_combination=''; foreach(all_word_combinations('cat dog mouse turtle shark whale elephant giraffe lion tiger fish monkey') as $one_word_combination){echo str_replace(' ','-',$one_word_combination).'<br />';} How can i run this javascript command show_seasons(some_value), in php code, i mean without any action ? I have this php code: if ($sid == $s_id) { javascript:show_seasons($sid); } How to do that? Thanks.. Not sure if this is the right place for this, but I need to be able to run some PHP code before anything loads up on the server. Hi I am newish to PHP and have been thrown in at the deep end by being given an unfinished project to undertake at my office. There are various parts of the code I don't understand and I don't even know if some bits are PHP or MySQL as it is far in advance of my experience. If I give some examples I would be grateful if anyone could give me some pointers on what the code means. Example 1: $variable_name = $connection->Execute('SELECT etc, etc, etc') I have already tried to find the answers on the PHP and MySQL websites and searched on Google to no avail. Thanks in advance for any help. I am trying to get a php script on a remote server to execute on my server but im having problems getting it to work, and i am not sure if it is even feasible i have had a look on google but i cant find much information on it. This is what i have tried up to now I saved a php script as a txt file on y remote server. then used file_get_contents on my home server $curl_scraped_page = file_get_contents('http://www.remote_server.com/script.txt'); the content of the txt file was $sum = 1+1; then i tried to echo $sum on the home server but i did not work can anyone point me in the right direction or is what i am trying to do even feasible? Thanks in advanced i've got this code: Code: [Select] <script type="text/javascript" src="jquery.js"></script> <script type="text/javascript"> $(document).ready(function() { var number = 10; var url = "index.php?number=0"; function countdown() { setTimeout(countdown, 1000); $('#box').html("Selecting person in " + number + " seconds"); number --; if (number<0) { window.location = url; number = 0; } } }); </script> <center> <div id="box"> <?php error_reporting(0); $file = file('names.txt'); $rand_line = rand(0, sizeof($file) - 1); $line = $file[$rand_line]; if ($_GET['number']=="0") { echo $line; } else { ?> <script type="text/javascript"> countdown(); </script> <?php } ?> </div> it is meant to when the javascript number = 0 show a random line from file but it comes up with undefined index 'number' on line 28 Hi! I was wondering if there is a way to execute php code which is stored in mysql database using php. At the minute I am using a echo to try and run php code stored in a mysql database but this just displays the code and does not run the php code. Thanks for any help! I'm kind of a beginner in PHP and I'm not sure how complicated is this thing I need to do so I just need a little bit of help. Anyway, I have this clock counter on a few of my pages, counting down to 0 and what I need to do is execute certain code 15 minutes before a counter reaches 0. It's basically the same code but it needs to run every time one of the counters is 15 minutes away from 0. Any simple way for me to achieve this? Thanks! Hi, I am trying to create a PHP script ("repair-correct.php") in order to run some CLI commands without using PuTTy - The CLI commands are needed to repair/correct the execution of a web application named Mautic. Shared web host account with PHP 7.0 URL: https://www.myserver.com Mautic directory: https://www.myserver.com/mautic
What I want to do is:
Step1: Change ownership of files and folders To find out which user Apache is running as, I want to execute the following command and take note of the first entry in the line which is returned: ps aux | grep apache2 I want to use this information to find the groups with the following command groups apache_user (where apache_user is the user I identified from the first step above) To reset the ownership of files and folders, I want to use the following command (ensuring that I replace apache_user and apache_group with the values identified in the steps above): sudo chown -R apache_user:apache_group With this command I want to change ownership, using the -R flag which means recursively - including all files/folders within that location.
Step 2: Reset the file and folder permissions
find . -type f -not -perm 644 -exec chmod 644 {} +
Thanks so much for your help in solving this problem!
Best, Tony
I have written a Validation class that checks to see if a file being uploaded to the server meets certain conditions. That works a treat. The next step is to actually upload it to the server and I have an Upload class that can do that. Again, that works perfectly fine. Once the file uploads, I am passing the $location of that of that file to my DB class. The DB class is full of methods that prepare and then execute strings that are SQL queries that are required in other areas of my application. Nothing I have at the moment is suitable for just running an SQL file so I don't know what to do now.. My procedural code, that works, looks like this; $dbh2 = new PDO("mysql:host=localhost;dbname=DB360transfer", $login_user, $login_password); $sql = file_get_contents($path.$new_file_name); $qr = $dbh2->exec($sql);I'm not sure how to replicate this up in a PDO/OOP application. My DB Class script is attached. The run_from_file code starts on line 98. I've left in the other stuff as I suspect the answer has something to do with using the $this or the self:: - but really I have no idea. So my question is, what is the correct syntax for executing a file in OOP? Attached Files DB.php 2.92KB 6 downloads Hi, Below i have some sample code and am confused over execute(), i have the code below in a try and catch block, in the catch block i call a function i created to log any error that is caught in catch block to a .txt file. I then looked online and it seems that i should do an if statement check on execute to ensure it executed the query, the part that confuses me if the execute failed i thought it would be caught in the catch block but it seems that is not the case. To explain better i have commented the code in depth on the area that i am confused about. Any help in making me understand would be great. I have not included all code above try and catch to keep things simple Code: [Select] <?php try { // connect to database $dbh = sql_con(); // checke if username exists on users table or users banlist table $stmt = $dbh->prepare(" SELECT users.user_login FROM users WHERE users.user_login = ? UNION ALL SELECT users_banlist.user_banlist FROM users_banlist WHERE users_banlist.user_banlist = ?"); // this is the part i am confused with, why is it i would use an if statement on execute() ? // i thought using a try and catch block any errors would be caught in the catch block. // using an if statement to check if execute() worked, i thought if execute failed it would // be handled by the catch block, i mean in my exmaple code here, what could cause the execute to fail ? // and why if execute failed it would not be caught by catch block ? // i am looing at exmaple online and i am reading different things and its all confusing me // execute query if(!$stmt->execute(array($username, $username))){ echo 'something went wrong .. '; } else { // execute worked } } // if any errors found log them in my ExceptionErrorHandler() function and display friendly message catch (PDOException $e) { // this function catches an error and logs them to file ExceptionErrorHandler($e); require_once($footer_inc); exit; } } ?> Thanks or any help! Hello, I've been assigned the task of creating an internal site for our office that has links to all the websites we use as well as the applications we use. I'm very comfortable using php with mysql for handling forms and displaying database information but I'm not sure how to go about this. So my question is, is there anyway I can use php to open an exe file? Not sure if this is possible I am trying to do a multi delete: Code: [Select] <form name="form1" method="post" action=""> <table> while($rows=mysql_fetch_array($result)){ ?> <tr> <td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>"></td> <td bgcolor="#FFFFFF"><? echo $rows['id']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['name']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['lastname']; ?></td> <td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td> </tr> <?php } ?> // Check if delete button active, start this if($delete){ for($i=0;$i<$count;$i++){ $del_id = $checkbox[$i]; $sql = "DELETE FROM $tbl_name WHERE id='$del_id'"; $result = mysql_query($sql); } <tr><td> <select name="dropdown"> <option value="option1">Choose an action...</option> <option value="edit">Edit</option> <option value="delete">Delete</option> </select> <a class="button" href="#">Apply to selected</a> if($result){ echo "<meta http-equiv=\"refresh\" content=\"0;URL=nameslist.php\">"; } } mysql_close(); How can I get this form to execute? Do I need to use a hidden input or something? Code: [Select] <form action="partnerRequest.php" method="post"> <a href="" title="Become Associates" id="becomeassoc" class="mll"> <span class="f_right">Become Associates</span><img src="../assets/img/becomeassoc.jpg" class="mrs vmiddle" alt="Become Associates" /> </a> </form> I need to execute a program in the command prompt in windows using php, which php functions would be best to do this? and would i need to set any type of permissions to be able to use them? Hi,
I have a cron job that executes this script every 2 minutes:
<?php // LOAD WP-LOAD.PHP require('/opt/bitnami/apps/wordpress/htdocs/wp-load.php'); // INCLUDE AND EXECUTE SCHEDULER.PHP include('/opt/bitnami/apps/wordpress/htdocs/wp-content/themes/yeelloe/scheduler.php'); ?>When I try to include; /opt/bitnami/apps/wordpress/htdocs/wp-content/themes/yeelloe/scheduler.php: <?php // EXPLODE AND PARSE WP-CONTENT; FUNCTIONS.PHP $parse_uri = explode( '/opt/bitnami/apps/wordpress/htdocs/wp-content', $_SERVER['SCRIPT_FILENAME'] ); // LOAD WP-LOAD.PHP require_once( $parse_uri[0] . '/opt/bitnami/apps/wordpress/htdocs/wp-load.php' ); // LOAD TEMPLATE FUNCTION CheckFunction(); ?> hi, I am having problems setting a session from a SQL query, please help... here is my code: Code: [Select] $query1 = "SELECT * FROM members_copy WHERE rsUser = '$username' AND rsPass = '$password'"; $result1 = mysql_query($query1); echo "<br>".$result1['USERID']; $_SESSION['s_logged_n'] = 'true'; $_SESSION['s_username'] = $username; $_SESSION['USERID']=$result1['USERID']; $_SESSION['RSTOWN']=$result1['RSTOWN']; $_SESSION['RSEMAIL']=$result1['RSEMAIL']; $_SESSION['RSUSER']=$result1['RSUSER']; no sessions are currently being set?! Hi, Im starting to write a simple (so I thought! ) project at work, I have no problems with the HTML, CSS or even the php mysql setup, but I am struggling with a simple piece of code! I have a list box, that populates from a table column using the following code: Code: [Select] <?php function select(){ $query="SELECT appname FROM kpe_apps"; $result = mysql_query($query); echo '<select name="item" onchange="this.form.submit()">'; while($nt=mysql_fetch_array($result)){ echo '<option value="' . $nt['id'] . '">' . $nt['appname'] . '</option>'; } echo '</select>'; } ?> I then called the function on the page I needed. which works fine, now all I need is whatever is selected in the listbox other columns in the same table relating to the selected item are seen. I just cant seem to do it, loads of people are using jquery and other code, surely this can be done in php? any help would really be appreciated.. Many Thanks MOD EDIT: code tags fixed, linefeeds and indenting added. I am running Apache with the PHP module installed on Debian Linux. My goal is to launch a binary in a background process and then feed it commands via fifo. The binary I need to launch has a config file which lives in the home directory of the apache user (in my case the user name apache is started with is www-data). www-data's home dir was the web root so I changed it to /home/www-data. I also change the shell from /bin/sh to /bin/bash for www-data. Neither of these changes are present when I load a php file from a browser. This script: Code: [Select] <?php echo "User: " . exec('whoami') . "<br>"; echo "Shell: " . exec('ps -p $$ | grep sh') . "<br>"; ?> Outputs this: Code: [Select] User: www-data Shell: 9179 ? 00:00:00 sh Also if I execute the binary it does seem to read the config file which is in the www-data users directory. I have set the home dir and the web root to be owned by www-data and it's read and writeable. How do I get php to execute the binary so it has access to the users home directory and uses the bash shell? Are there any other ways to launch and control a binary on a unix system via php? Hi. I have a query that determines if user is online/offline. Works perfectly when page loads. I want to change to auto run query every X seconds. NOTES: - The query is on a .php page with multiple other queries. -IF it is possible to still run the query with-in this page? or make a separate file and include in an iframe? i would like to avoid the iframe and just $output the result of query every X seconds. Here is my $query code: $query = "SELECT `manager_id` FROM #__profiles_xref WHERE profileid = '$profid'"; $onofflineid=doSelectSql($query,1); foreach ($onofflineid as $isonoffline){ $profmanagerid=$isonoffline->manager_id; } $query = "SELECT `session_id` FROM table_session WHERE userid = '$propmanagerid'"; $onofflinestatus=doSelectSql($query,1); if (count($onofflinestatus)>0) { $output['PROPSTATUS']='Online'; } else { $output['PROPSTATUS']='Offline'; } |