Jump to content

cyberRobot

Moderators
  • Posts

    3,145
  • Joined

  • Last visited

  • Days Won

    37

Community Answers

  1. cyberRobot's post in Can connect to DB but can't extract data was marked as the answer   
    It looks like you're using MySQLi to connect, but using the old MySQL functions for the rest. Note that the old functions were removed in PHP 7.0. See the warning here:
    https://www.php.net/manual/en/function.mysql-query.php
  2. cyberRobot's post in How can I get the page height which can change after element hiding? was marked as the answer   
    One option would be to write a function that gathers the necessary height information. Then run the function to initialize your height variable(s). If something is hidden after the initialization, run the function again to update the variable(s).
    You could also check to see if there's an event listener built into JavaScript for detecting changes to the page height. If something like that is available, you could have that run the necessary code to update the height information.
    For example, the "resize" event listener might be useful when gather height information when the user changes their browser's window size. More information can be found here:
    https://developer.mozilla.org/en-US/docs/Web/API/Window/resize_event
    Additional listeners may be available for other events that impact page height.
  3. cyberRobot's post in Returning a value if blank in mysql with php was marked as the answer   
    To me it seems like the code should be this. Note that I changed $pageimg to $row["pageimg"].
    //IF IMAGE NAME IS PROVIDED, SHOW CUSTOM IMAGE if (!empty($row["pageimg"])) { $imagePageURL = '/img/'.$row["pageimg"]; //ELSE...SHOW FALLBACK IMAGE } else{ $imagePageURL = 'nouserback.jpg'; }
  4. cyberRobot's post in only first checkbox selecting was marked as the answer   
    Sorry about that, the IDs need to be enclosed in PHP tags. Here's an updated example:
    <td><input type='checkbox' name='check_list[<?= $prod_id ?>]' value='<?= $prod_id ?>' ></td> <input type='text' name='prod_id[<?= $prod_id ?>]' value='<?= $prod_id ?>' hidden> <input type='text' name='cost_price[<?= $prod_id ?>]' value='<?= $cost_price ?>' hidden> ...  
  5. cyberRobot's post in Website-menu bar, menu button and width. was marked as the answer   
    The following w3school page talks about collapsing a website navigation for smaller/mobile screens:
    https://www.w3schools.com/howto/howto_js_mobile_navbar.asp
  6. cyberRobot's post in Linking 2 arrays after successful ping in PHP was marked as the answer   
    I would switch to a multidimensional associative array for your data. For example, you could have something like this
    <?php $systems = array( array('ip'=>'192.168.9.254', 'name'=>'Item1'), array('ip'=>'192.168.9.205', 'name'=>'Item2'), //...remaining systems ); ?>  
    That way all your data is in the same place. Then your loop could use the values like this:
    <?php foreach ($systems as $currSystem) { echo $currSystem['ip']; echo $currSystem['name']; } ?>  
  7. cyberRobot's post in "include('../db.php');" doesn't work was marked as the answer   
    If I'm reading everything correct, the "create" script is under todolist_demo > public_html > todo. The "create" script isn't able to find your db.php because the following line only goes up one level.
    include('../db.php'); Basically, you're telling "create" that db.php is in your public_html folder. You either need to use "../../db.php". Or I would actually recommend switching that line so it starts at the document root. I'm guessing "public_html" is your root folder. If that's the case, you could try the following:
    include $_SERVER['DOCUMENT_ROOT'] . '/../db.php';  
  8. cyberRobot's post in Error session variable not displaying message in another php file was marked as the answer   
    Just to make sure, for benanamen's suggestion, you should replace the following line:
    if(isset($_POST["submit"])) With the line below. Note that I removed the curly / smart quotes around POST.
    if($_SERVER['REQUEST_METHOD'] == 'POST') I would also add some sort of debug code to see if the if test is working. For example,
    if($_SERVER['REQUEST_METHOD'] == 'POST') { echo '<br>form submission detected'; Does the script display "form submission detected" after submitting the form? Also, if the script still doesn't work as you expect, please post your most recent code.
  9. cyberRobot's post in comments spilling out of my comment box was marked as the answer   
    Does the box scale for normal words?
     
    If you are expecting strings like the ones shown in the screenshots, you could look into CSS' overflow property:
    https://developer.mozilla.org/en-US/docs/Web/CSS/overflow
  10. cyberRobot's post in PHP working differently in different browsers was marked as the answer   
    Are you trying to get the page to display "User Not Found" before the redirect happens? If so, you can see the example at the bottom of the following page:
    https://developer.mozilla.org/en-US/docs/Web/HTML/Element/meta
     
     
    I think the issue is with the "User Not Found" text in the content attribute. Unless I missed something in the documentation, linked above, the value before the semi-colon needs to be a number.
     
    Side note: PHP has a function for redirecting the page. More information can be found here:
    http://php.net/manual/en/function.header.php
  11. cyberRobot's post in input fields are not showing up was marked as the answer   
    It looks like your form is created within the setassign3() function. Where is the function being called?
     
    Also note that $this is used for class methods. As far as I can tell, setassign3() is just a user-defined function.
  12. cyberRobot's post in Scripting for XFA forms was marked as the answer   
    For what it's worth, the following looks promising:
    http://help.adobe.com/en_US/livecycle/9.0/LiveCycle_Designer_Scripting_Basics.pdf
  13. cyberRobot's post in How to bring existing value into dropdown was marked as the answer   
    You could try something like the following:
     
    echo "<select name='stat_id' onchange='filterContent(this);'>"; foreach ($row_stat as $r) {     echo '<option value="'.$r['statid'].'"';     if (isset($statid) && $statid==$r['statid']){ echo ' selected="selcted"'; }     echo '>'.$r['stat_name'].'</option>'; } echo "</select>";
  14. cyberRobot's post in Loop Multiple Arrays was marked as the answer   
    Looking at your code a bit closer, you probably want to run the test within the loop. Maybe something like this:
    foreach ($attributes as $name => $value) {     if(!empty($value)) {         $product_attributes[$i] = array (             'name' => htmlspecialchars( stripslashes( $name ) ), // set attribute name             'value' => $value, // set attribute value             'position' => 1,             'is_visible' => 1,             'is_variation' => 0,             'is_taxonomy' => 0,             'row' => $i         );         $i++;     } } That way one of your attributes can be empty and the loop will still execute.
  15. cyberRobot's post in Prevent undefined get variable was marked as the answer   
    What is the exact error message? Does it refer to the following line:
    $isTtex = $_GET['varname']; If so, you could change it to
    if(isset($_GET['varname'])) { $isTtex = $_GET['varname']; } However, I wonder if the undefined error refers to the code in your footer. Perhaps the code is imported in a different scope from the rest of the PHP code. If that's the case, $isTtex below will be undefined:
    <?php if (isset($isTtex)) : ?> To fix that, you could use
    <?php if (isset($_GET['varname'])) : ?>
  16. cyberRobot's post in Return null or array in function if conditions are met was marked as the answer   
    If you echo out $visitors before the if test that changes $result to NULL, you'll see that the value has been changed.
    <?php //...   echo "<div>$visitors</div>";   //If the visitors don't fit in the gap of available seats. if($visitors>$gap){     $result = NULL; }   //... ?> One way around this is to create a temporary variable which will be used in the loop.
    <?php //...   function suggestSeats($seats,$visitors){       $visitorsToProcess = $visitors;       foreach($seats as &$val){         //If available         if($val['seatAvailable'] == '1'){             //If there's no gap, start making one now:             if($gap<1){                 $gap = 1;             }             $gap++;               //IF THERE ARE STILL VISITORS TO PROCESS, MARK THE SUGGESTED SEAT             if($visitorsToProcess > 0) {                 $val['seatAvailable'] = 'x';                 $visitorsToProcess--;             }         }           //IF THERE ARE NO MORE VISITORS, EXIT LOOP         if($visitorsToProcess == 0) {             break;         }     }       echo "<div>Visitors before loop: $visitors</div>";     echo "<div>Visitors after loop: $visitorsToProcess</div>";     echo "<div>Gap: $gap</div>";       //If the visitors don't fit in the gap of available seats.     if($visitors>$gap){         $result = NULL;     }     else{         $result = $seats;     }       return $result; }   ...// ?>
  17. cyberRobot's post in Help with my first super simple "Hello World" Wordpress plugin was marked as the answer   
    For what it's worth, the plugin code worked for me.
     
    Have you tried changing the file/folder/plugin name? Perhaps the name you're using conflicts with another plugin, like Hello Dolly.
  18. cyberRobot's post in Execute a line of code, for x times was marked as the answer   
    If you output the value of $i in your for loop, you'll notice that the loop is being executed for every seat available.
    for($i=0;$i<$visitors;$i++){     echo "<div>here ($i)</div>";     $val['seatAvailable'] = 'x'; }   To only suggest seats based on the number of visitors you, could replace the for loop with something like this: <?php //...   //If available elseif($val['seatAvailable'] == '1'){     //IF THERE ARE STILL VISITORS TO PROCESS, MARK THE SUGGESTED SEAT     if($visitors > 0) {         $val['seatAvailable'] = 'x';         $visitors--;     } }   //... ?>   Then once all the $visitors have been processed, you could break out of the loop. Here is all the code in context: <?php $visitors = 2; $seats = array( array( 'seatAvailable' => '0', 'seatNumber' => '1' ),         array( 'seatAvailable' => '0', 'seatNumber' => '2' ),         array( 'seatAvailable' => '1', 'seatNumber' => '3' ),         array( 'seatAvailable' => '1', 'seatNumber' => '4' ),         array( 'seatAvailable' => '1', 'seatNumber' => '5' ),         ); echo "Visitors: ".$visitors;   echo "<ol>"; foreach($seats as &$val){     //If not available     if($val['seatAvailable'] == '0'){         //echo "<li>not available</li>";     }     //If available     elseif($val['seatAvailable'] == '1'){ //IF THERE ARE STILL VISITORS TO PROCESS, MARK THE SUGGESTED SEAT if($visitors > 0) { $val['seatAvailable'] = 'x'; $visitors--; }     }   //IF THERE ARE NO MORE VISITORS, EXIT LOOP if($visitors == 0) { break; } } echo "</ol>"; echo "<pre>"; print_r($seats); echo "</pre>"; ?>  
  19. cyberRobot's post in change the color of a word in a string was marked as the answer   
    Are you looking to create a keyword highlighter like you find in search engines? If so, you could look into using something like str_ireplace(). More information can be found here:
    http://php.net/manual/en/function.str-ireplace.php
     
    Note that there's an example keyword highlighter in the user-contributed notes here
    http://php.net/manual/en/function.str-ireplace.php#87417
  20. cyberRobot's post in Add Separator to Wordpress Function was marked as the answer   
    Since get_the_category() returns an array, you could use implode(). More information can be found here:
    http://php.net/manual/en/function.implode.php
  21. cyberRobot's post in Fitering an array was marked as the answer   
    You could try something like this:
    $matchingIndex = ''; foreach($yourArray as $currIndex => $subArray) {     if($subArray[1] == 'Zurich Life') {         $matchingIndex = $currIndex;         break;  //break out of the loop, since you found Zurich Life     } }
  22. cyberRobot's post in Warning: Cannot modify header information was marked as the answer   
    As mac_gyver mentioned, nothing can be outputted to the screen before calling header(). Since you're just redirecting the user, the header() call can be moved to the top of your script.
    <?php  //lets check the user is authorised to be here! if ($userLevel > 3){     echo "you are authorised to be here!"; } else {     header('Location: ../index.php');     exit; }     //this is going to be the main section for reporting   include('../header.php'); ?>   Note that I added the "exit" statement after the header() call to prevent the script from doing any further processing.   If you want to display a message before the page is redirects, you could look into using header() and "refresh". An example can be found here: http://php.net/manual/en/function.header.php#97114
  23. cyberRobot's post in PHP Selection not showing on selction on dropbox was marked as the answer   
    You're using "SymptomId" here:
    <select name="Symptom" id="SymptomId" onchange="Symselect()"> And "Symptomid" here:
     var x = document.getElementById("Symptomid").value; Those values need to match. Note: the values are case sensitive.
     
     
    Note that I moved the topic to the JavaScript forum. 
  24. cyberRobot's post in HTML select and option work with PHP database was marked as the answer   
    How is the "birthdate" field stored in your database? If it is stored as a string and only contains the month, you would need to add quotes around the value from $select.
    $birthdate = "SELECT CONCAT(FirstName,' ',LastName) AS Birth FROM Members WHERE birthdate = '" . $select . "'"; Side note: you'll want to look into using prepared queries...or use mysqli_real_escape_string() to protect yourself from SQL injection attacks.
  25. cyberRobot's post in php and html contact form help was marked as the answer   
    One thing that I noticed is that the email entered through the form is being saved to $email.
    $email = $_POST['email']; But the if test uses $email_from.
    if(!preg_match($email_exp,$email_from)) {
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.