-
Posts
3,145 -
Joined
-
Last visited
-
Days Won
37
Community Answers
-
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
-
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.
-
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'; } -
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> ...
-
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
-
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']; } ?>
-
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';
-
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.
-
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);
-
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.
-
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.
-
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:
http://php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
Side note: Put is spelled with one (1) "t". "Putt" is something else.
-
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.
http://php.net/manual/en/functions.returning-values.php
-
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 />"; -
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
-
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
-
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.
-
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
-
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>"; -
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.
-
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'])) : ?> -
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; } ...// ?> -
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.
-
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>"; ?>
-
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