-
Posts
3,404 -
Joined
-
Last visited
-
Days Won
55
Everything posted by Ch0cu3r
-
Storing selection from dynamic listbox into database.
Ch0cu3r replied to HarryAdney's topic in PHP Coding Help
You can retrieve the selected option from the country dropdown list using $_POST['country_list'] -
Most likely. Yes. When you see urls like this you know the page is being dynamically generated. Here is a simple demo app index.php <?php $page = isset($_GET['page']) ? $_GET['page'] : 'home'; switch($page) { case 'home': // serve the homepage echo '<h1>Home Page</h1>'; break; case 'portfolio': // serve the portfolio page echo '<h1>Portfolio Page</h1>'; break; case 'contact': // serve the contact page echo '<h1>Contact Page</h1>'; break; default: header('HTTP/1.0 404 Not Found'); echo "404 $page Not Found"; } ?> <hr /> <ul> <li><a href="site.com/?page=home">Home</a></li> <li><a href="site.com/?page=portfolio">Portfolio</a></li> <li><a href="site.com/?page=contact">Contact Me</a></li> </ul> Nope they are not mapping folders to files. This is something called mod_rewrite, what this means is that this url phpfreaks.com/topic/290016-my-php-questions/ is most likely being mapped to a url like phpfreaks.com/topic.php?topicid=290016 To demonstrate this with the demo app above. Create a .htaccess file in the same folder as the demo App index.php and add the following code to it RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ([a-z0-9]+) index.php?page=$1 [NC,L] Now change the links in index.hpp <ul> <li><a href="site.com/home">Home</a></li> <li><a href="site.com/portfolio">Portfolio</a></li> <li><a href="site.com/contact">Contact Me</a></li> </ul>
-
Your problem is nothing to do with PHP. You are most likely using JavaScript to toggle your panels visibility. You need to alter your JavaScript do so it only changes the visibility for the panel you have click on, example - http://jsfiddle.net/STnRc/
-
What I was getting at was you can just change the the else/elseif block of code that I had quoted with this else block } else { $pin = intval($_GET['pin']); // get the pin id $setting = ($_GET['action'] == "turnOn") ? 1 : 0; // decide the new pinStatus value, eg If action is 'turnOn' set pinStatus to 1 otherwise set pinStatus to 0 ('turnOff') mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber=$pin"); // update the pinStatus value where pinNumber matches $_GET['pin'] } I never said to separate your code into separate files. I am only posting suggestions for how to improve your code. Currently we do not know what that problem is as you have not told us. I would recommend that explain what is it is you are trying to do and then explain what the code is not doing.
-
What exactly? You need to explain what you are wanting to inserting, when and where in the code you need this to take place. Before you do this though you code needs optimizing. First there is no need for you to have separate MySQL users for different tables in your database. It is ok to have different MySQL users if your script deals with multiple mysql servers but not when the two users are for the same server and database. This just adds unneeded complexity. So refactor your code so you only have to deal with one mysql user instance. Next there is no need to open/close a connection to the mysql database before/after every query. You should open the connection once at the very beginning of the script and leave the connection open for remainder of your script. PHP will automatically close the connection to mysql after script execution. Connecting/disconnecting multiple times to the mysql server just wastes server resources. What is going on here? ... } else { $now = new DateTime(); $action = $_GET['action']; $pin = mysql_real_escape_string($_GET['pin']); if ($action == "turnOn"){ $setting = "1"; mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='4';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('1', 'Red LED', $now, '')"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='17';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('2', 'Blue LED', $now, '')"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='18';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('3', 'Green LED', $now, '')"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='21';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('4', 'LED', $now, '')"); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='22';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('5', 'LED', $now, '')"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='23';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('6', 'LED', $now, '')"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='24';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('7', 'LED', $now, '')"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='25';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('8', 'LED', $now, '')"); mysql_close(); header('Location: control.php'); } else If ($action == "turnOff"){ $setting = "0"; mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='4';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('1', 'Red LED', '', $now)"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='17';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('2', 'Blue LED', '', $now)"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='18';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('3', 'Green LED', '', $now)"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='21';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('4', 'LED', '', $now)"); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='22';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('5', 'LED', '', $now)"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='23';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('6', 'LED', '', $now)"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='24';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('7', 'LED', '', $now)"); mysql_close(); mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber='25';"); $dbConnectionSensor = mysql_connect($MySQLHost, $MySQLUserSensor, $MySQLPassword); mysql_select_db($MySQLDBSensor, $dbConnectionSensor); mysql_query("INSERT INTO sensor('8', 'LED', '', $now)"); mysql_close(); header('Location: control.php'); } In this part aren't you supposed to be toggling the pinStatus (between 1 and 0) where $_GET['pin'] matches pinNumber. Ie you click the Tun On button from the Sessions table for GPIO Pin #4 the code will then set its pinSatus to 1. Clicking the Turn Off button again for this pin will set its pinStatus value to 0. With your code at it is, any button you press from your Sensors table will set all the pins statuses to the same values! Not each one being updated individually. To have the pins update individually you need to the change the above code to something like ... } else { $pin = intval($_GET['pin']); // get the pin id $setting = ($_GET['action'] == "turnOn") ? 1 : 0; // decide the new pinStatus value, eg If action is 'turnOn' set pinStatus to 1 otherwise set pinStatus to 0 ('turnOff') mysql_query("UPDATE pinStatus SET pinStatus='$setting' WHERE pinNumber=$pin"); // update the pinStatus value where pinNumber matches $_GET['pin'] } The next issue you have is ideally you'd should have your forms submit their data via POST not GET. Also you should ideally use MYSQLi or PDO as the mysql_* functions are deprecated, which means they are no longer supported and could be removed from future versions of PHP.
-
Why dont you just use php-fpm with WEMPServer? The php-fpm exe is most likely compiled to the PHP version bundled with WEMPServer, which means you cannot just copy it from one installation of PHP to another. Commands to use WEMPSever are here
-
convert input text into images based on alphabet
Ch0cu3r replied to ajrocha81's topic in PHP Coding Help
for ($i=0; $i<strlen($string); $i++) { $string should be $char -
Because the following is trying to call the variable variable, which you have not defined it ${$row['privilege']}; If you are to do variable variables, you'd code it like so: while($row = mysql_fetch_assoc($permission_query)) { ${$row['privilege']} = $row['privilege']; } What is the purpose of doing this? Not to be rude but it seems lazy to me
-
You need to give the ss_name input field a name attribute in order to retrieve the selected value when the form is submitted. <input id="ss_name" name="ss_name" list="oecs_systems"/> <br>
-
If you are only chosing a random filename defined in the banner table you could handle this with MySQL. $sql = 'SELECT `filename` FROM banner ORDER BY RAND() LIMIT 1'; // randomise the order of the table and return the first row $result = $mysqli->query($sql) or die(mysqli_error()); list($chosenFilename) = $result->fetch_row(); $selectedImage = "images/$chosenFilename"; if (file_exists($selectedImage) && is_readable($selectedImage)) { $imageSize = getimagesize($selectedImage); }
-
Yes you would need to loop over each user in the array and check that the value of the type index is set to staff $json_string = '[{"user":"RD32","time":"14:00","type":"staff"}, {"user":"XC12","time":"21:00","type":"management"}, {"user":"YG89","time":"09:00","type":"staff"}]'; $users = json_decode($json_string,1); $staffUsers = array(); foreach($users as $user) { if(isset($user['type']) && $user['type'] == 'staff') { $staffUsers[] = $user; } } print_r($staffUsers); /* Returns Array ( [0] => Array ( [user] => RD32 [time] => 14:00 [type] => staff ) [1] => Array ( [user] => YG89 [time] => 09:00 [type] => staff ) ) */
-
How can I add a MYSQL TRUNCATE TABLE query to my PHP script?
Ch0cu3r replied to Nickmadd's topic in PHP Coding Help
Do you mean want to ignore the first line of the csv file? If so then No You need add IGNORE 1 LINES as part of the LOAD DATA INFILE directive like so $affectedRows = $pdo->exec(" LOAD DATA LOCAL INFILE ".$pdo->quote($csvfile)." REPLACE INTO TABLE `$databasetable` FIELDS TERMINATED BY ".$pdo->quote($fieldseparator)." LINES TERMINATED BY ".$pdo->quote($lineseparator)." IGNORE 1 LINES"); -
How can I add a MYSQL TRUNCATE TABLE query to my PHP script?
Ch0cu3r replied to Nickmadd's topic in PHP Coding Help
You need to specify the table you are wanting to truncate $pdo->exec("TRUNCATE TABLE `$databasetable`"); -
How can I add a MYSQL TRUNCATE TABLE query to my PHP script?
Ch0cu3r replied to Nickmadd's topic in PHP Coding Help
The code uses PDO to interact with the database. To truncate table run your query using PDO::exec -
Why are you using mysqli_fetch_assoc when you're using Joomla's database library? The only time you'd use mysqli_fetch_*() function would be if you had ran a query using mysqli_query(). Quote from Joomla's documentation on the use of loadObjectList From that I'd hazard a guess this would be the correct way for looping over the results returned by that method. <?php echo "<table><tr><th>Name</th><th>Department</th></tr>"; // loop over results return from loadObjectList() foreach($results as $row) { echo "<tr>"; echo "<td>".$row->last_name."</td>"; echo "<td>".$row->dept."</td>"; echo "</tr>"; } echo "</table>"; ?>
-
No need for regex. What you have retrieved is a data object encoded in JSON. PHP has a function called json_decode which will transform the json data back into a object. Example usage $json_string = file_get_contents(...); $data = json_decode($json_string); // output the cmd property echo 'CMD: '.$data->cmd.'<br />'; // output the name property echo 'NAME: '.$data->name.'<br />'; // output last_heard value from the coreInfo property echo 'LAST HEARD: '.$data->coreInfo->last_heard;
-
Yes, copy all the text highlighted in green (the text between url(" and ") ) from your post and paste it into your web browsers address bar. Now can right click and save the image to your computer and apply what ever edits want to apply.
-
<?= is shorthand syntax for <?php echo There is also another form of short tag which is <? this is shorthand syntax for the full open tag <?php When using short tag syntax be-careful as these are controlled by a PHP directive called short_open_tag . Not all server configurations has this directive enabled. If this directive is not enabled on a server then your PHP code will be completely ignored and will be output to the browser! NOTE: As of PHP 5.4+ <?= is always available regardless of the short_open_tag directive status. For older versions of PHP the above warning still applies! I only recommend using the short tags in template files only. For all other cases always use the full php tags syntax. As for ++$a it is shorthand syntax for $a = $a + 1;
-
Best way to Import multiple tables with PHPMyAdmin
Ch0cu3r replied to davidannis's topic in MySQL Help
When exporting databases/tables PHPMyAdmin does provide a wide range of options. Make sure you have unchecked any options which could end up truncating/dropping the table on import.- 1 reply
-
- phpmyadmin
- import
-
(and 1 more)
Tagged with:
-
@slj90 what your posted is the binary contents of the actual image encoded in base64. To be able to use the image in your webpage, apply that code to a background: property in your stylesheet. Then manipulate the background-position co-ordinates to display the required icon from the image sprite. Example usuage
-
check db if a phone number was added to db less than 31 days ago?
Ch0cu3r replied to lovephp's topic in MySQL Help
You'd use the date_sub() aggregate function to take 31 days off of the current timestamp. SELECT * FROM table WHERE honePhone='$homePhone' AND Your_Datetime_Column_Name_HERE < DATE_SUB(NOW(), INTERVAL 31 DAYS) -
Why are all the double quotes escaped? Where is this code placed in your PHP?
-
You need to be running a query which returns the row in the products table that matches the product id that is passed in the url. Example <?php // connect to databae $pdo = new PDO($dsn..., $user..., $password...); // get the product id from url if(isset($_GET['id']) && ctype_digit($_GET['id'])) { // run prepared query, returne the row where the product_id matches $stmt = $pdo->prepare('SELECT * FROM products WHERE product_id = ?'); $stmt->execute(array(intval($_GET['id']))); // get the product data if(($product = $stmt->fetch(PDO::FETCH_ASSOC)) === false) { // product requested not found header('Location: inventory.php'); exit(); } // output the product information ?> <div id="singprod"> <img src="<?php echo $product["picc"];?>" > </div> <div id="productid"> <?php echo "id"."$space" .":". $product["id"]; ?></div> <div id="productname"> <?php echo "info" ."$space" .":". $product["product"];?></div> <div id="productinfo"><?php echo "Description". "$space". "Description" .":". $product["description"];?></div> <div id="productprice"><?php echo "Product Price" ."$space".":". $product["price"];?></div> <?php } ?> That is the basic code you need for your second page.
-
That is not how mod_rewrite works. It does not change links for you. You need to change all links in your code to view/inventory.php to product/ <a href="/product/">View Inventory</a> mod_rewite will then map site.com/product/ to site.com/view/inventory.php