Jump to content


  • Posts

  • Joined

  • Last visited

  • Days Won


Community Answers

  1. 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:
  2. 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'=>'', 'name'=>'Item1'), array('ip'=>'', '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']; } ?>  
  3. 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';  
  4. 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.
  5. cyberRobot's post in n00b - simple script to pull and show sql variable was marked as the answer   
    As Psycho was referring to, you can replace this
    $sql = "SELECT ID FROM thunderball  ORDER BY ID DESC LIMIT 1"; $rs = mysqli_query($connection,$sql); $row = mysqli_fetch_array($rs); $id =  $row['ID'];   With this $id = mysqli_insert_id($connection);   Note: that single line replaces all four lines. You don't need to run a separate query to get the ID of last record added. MySQL handles that for you.       If you output $id, you should get the ID you are looking for. And you should be able to change this $smsg = "Thunderball Event Created Successfully.";   To something like this $smsg = "Thunderball Event Created Successfully. Your ID is " . htmlentities($id);  
  6. cyberRobot's post in Making a News Website! Need help! was marked as the answer   
    Have you looked into building dynamic (aka database-driven) websites with PHP and MySQL? Basically, the information that needs to be displayed on multiple pages, like your headlines, articles, etc., would be stored in a database (eg MySQL). Then you create whatever page scripts are needed to display the information. For example, you would have one script for the home page which would query the database to pull the newest headlines. Each headline could be a clickable link that passes the article ID to another page script designed to display the article details. The details script would pull the article information from the database using the passed ID.
  7. cyberRobot's post in Why delete not working - CLASS.USER.PHP was marked as the answer   
    Have you checked the return value of $stmt->execute();? It should return true if the prepared query executes successfully.
    If it's returning false, PDO and MySQLi have methods for seeing the errors that are being thrown by MySQL.
    Side note: you'll want to look into binding variables into prepared queries. Using the raw value from variables, like $id, makes the query susceptible to SQL Injection Attacks.
  8. cyberRobot's post in Displaying multiple error messages was marked as the answer   
    You can do something like this:
    <?php if (isset($_POST['submit'])) {     function validate($key, $value)     {         $error = array();         switch ($key) {             case 'firstname':                 $error[$key] = (empty($value)) ? 'Putt Your Firstname' : '';                 break;             case 'lastname' :                 $error[$key] = (empty($value)) ? 'Putt Your Lastname'  : '';                 break;             //...         }         return $error;     }       // $arr = array('firstname', 'lastname', 'email', 'pass', 'confirmpass');       foreach ($_POST as $key => $value) {         $error = validate($key, $value);         echo $error[$key];     } } ?> The above code uses the ternary operator. More information can be found here:
    Side note: Put is spelled with one (1) "t". "Putt" is something else. 
  9. cyberRobot's post in Creating 'count' function as training - problem with multidimensional arrays was marked as the answer   
    You get that value because $b gets printed at the end of every function call. If you're looking for a running total, you would need to return $b.
  10. cyberRobot's post in Creating a link within PHP output from database was marked as the answer   
    Try changing this
    $output .= "Date: $date <br />Utility: $utility<br />Address: $address<br />Serial Number: <a href=\\'/dashboard-display?id='.$row['serialNumber'].''>$sn</a><br /><br />";   To this $output .= "Date: $date <br />Utility: $utility<br />Address: $address<br />Serial Number: <a href='/dashboard-display?id=".$row['serialNumber']."'>$sn</a><br /><br />";
  11. 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:
  12. 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:
    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:
  13. 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.
  14. cyberRobot's post in Scripting for XFA forms was marked as the answer   
    For what it's worth, the following looks promising:
  15. 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>";
  16. 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.
  17. 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'])) : ?>
  18. 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; }   ...// ?>
  19. 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.
  20. 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>"; ?>  
  21. 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:
    Note that there's an example keyword highlighter in the user-contributed notes here
  22. 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:
  23. 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     } }
  24. 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
  25. 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. 
  • 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.