PHP - Values Not Going In Db A Further Step
Okay,
I have moved on a few more steps and now starting to add, edit and delete records. The first issues I encountered before have been fixed as I read up on the prepare statement. I had to rewrite most of the code though. With this issue I am having trouble get the script to update or add new records. It produces no error messages: My DB: Column Type Null Default id int(11) No Autoincrement page varchar(255) Yes NULL title varchar(255) Yes NULL description varchar(255) Yes NULL keywords varchar(255) Yes NULL The code: view.php <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>View Records</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> </head> <body> <h1>View Records</h1> <p><b>View All</b> | <a href="paginated.php">View Paginated</a></p> <?php // connect to the database include('connect.php'); // get the records from the database if ($result = $mysqli->query("SELECT * FROM URL ORDER BY id")) { // display records if there are records to display if ($result->num_rows > 0) { // display records in a table echo "<table border='1' cellpadding='10'>"; // set table headers echo " <tr> <th>ID</th> <th>Page</th> <th>Title</th> <th>Description</th> <th>Keywords</th> <th>Edit</th> <th>Delete</th></tr></tr>"; while ($row = $result->fetch_object()) { // set up a row for each record echo "<tr>"; echo "<td>" . $row->id . "</td>"; echo "<td>" . $row->page . "</td>"; echo "<td>" . $row->title . "</td>"; echo "<td>" . $row->description . "</td>"; echo "<td>" . $row->keywords . "</td>"; echo "<td><a href='records.php?id=" . $row->id . "'>Edit</a></td>"; echo "<td><a href='delete.php?id=" . $row->id . "'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } // if there are no records in the database, display an alert message else { echo "No results to display!"; } } // show an error if there is an issue with the database query else { echo "Error: " . $mysqli->error; } // close database connection $mysqli->close(); ?> <a href="records.php">Add New Record</a> </body> </html> connect.php // connect to the database $mysqli = new mysqli($server, $user, $pass, $db); // show errors mysqli_report(MYSQLI_REPORT_ERROR); Similar Tutorials
Table Issue - Multiple Location Values For User Pushes Values Out Of Row Instead Of Wrapping In Cell
i made a quick example of the problem im having. at step 5 i dont get the data for some reason. and its weird because when i resend the data it usually works by clicking refresh page. is very frustrating and makes no sense. please help Code: [Select] <?php if(!isset($_GET['step'])){ ?> <form method="post" action="form.php?step=2"> <input type="text" name="text" id="text"> <input type="submit"> </form> <?php } else if($_GET['step'] == 2){ ?> <form method="post" action="form.php?step=3"> <input type="hidden" name="text" id="text" value="<?php echo $_POST['text']; ?>"> <input type="text" name="text2" id="text2"> <input type="submit"> </form> <?php } else if($_GET['step'] == 3){ ?> <form method="post" action="form.php?step=4"> <input type="hidden" name="text" id="text" value="<?php echo $_POST['text']; ?>"> <input type="hidden" name="text2" id="text2" value="<?php echo $_POST['text2']; ?>"> <input type="text" name="text3" id="text3"> <input type="submit"> </form> <?php } else if($_GET['step'] == 4){ ?> <form method="post" action="form.php?step=5"> <input type="hidden" name="text" id="text" value="<?php echo $_POST['text']; ?>"> <input type="hidden" name="text2" id="text2" value="<?php echo $_POST['text2']; ?>"> <input type="hidden" name="text3" id="text3" value="<?php echo $_POST['text3']; ?>"> <input type="text" name="text4" id="text4"> <input type="submit"> </form> <?php } else if($_GET['step'] == 5){ echo $_POST['text']; echo $_POST['text2']; echo $_POST['text3']; echo $_POST['text4']; } ?> I'm trying to create an application where the admin is able to add mutiple goals. For example, - Goal 1 - Goal 2 - Goal 3 Once the goals have been set, he then can generate a task for users to follow the goals for a specific users.
For example USER A Goal 3, Goal 2, Goal 1
USER B Goal 2, Goal 1, Goal 3
USER C Goal 1, Goal 2, Goal 3
The user have to follow the goal as set and can only proceed to the next goal one the previous one has been completed. The goals will defer everyday. Anyone can guide me to the right direction?
Edited September 11, 2020 by ZulfadlyAshBurn Grammer I have just recently began learning PHP. I have a pretty solid foundation in general programming and PHP. As my first major PHP project I am trying to make myself an autobuyer for Fifa 15 using curt2008 Fifa API. He basically has everything there for me to use and I know that I have enough knowkledge to get a basic autobuyer going if I could just figure out how to log in. I have come to realize that the problem is that I have no idea what he is doing when he connects to the Fifa Web App. He has the code there for me, but I don't know what it is actually doing. I was hoping someone can point me to some documentation, a tutorial, or even exercises so that I may learn more about... logining into a web application? I don't even know what to call it.
Looking at connect.php he has a bunch of functions. Login, getSessionID, Phishing, getNucleusID, getShards, and all of them do a bunch a requests and use a bunch of headers. I don't know what this terminology is or how it all works together, but I would like to learn about it. Thats why I wanted to start learning PHP, for stuff like this. I just don't know where to look.
Thank You
I have a DB It gets records from a sensor every 5 min This is then displayed on a Chart When I request 4 Hrs I get 48 records x 12 Sensors, Not a issue When I request 12 Hrs I get 144 records x 12 Sensors, A little Slower but Still OK But as I start to request longer periods Like 7 Days I start getting larger and Larger data sets causing time out issues with the AJAX Calls (4-30MB per sensor downloads of data) When looking at 4 weeks I really cant see the fine detail so is there a way to request records from MYSQL that drops some records in between Kinda like the Step function in a For loop If I request a period that has 2048 records but only want 204 records is there a way to say give me From -> To dates Step 10 and only return every 10th Record in the data set Thanks Hi all, I've been trying to create a page whereby a user enters a few details which is then emailed, but I'm seriously stuck on one issue. First page - console type Second page - serial number Only two steps at the moment as I need to figure it out. I'm passing everything into a variable from a post(ed) form. It appears on the next page fine, as I've been testing, but the details entered on the first page don't show on the third, however, the details from the second page do! Here is the code I have: Code: [Select] <?php switch ($step) { case "1": ?> <table width="75%" align="center"> <tr> <td colspan="2" valign="top"> <form action="?step=2" method="post" id="consoletype">Please select your console type<br /></td></tr> <tr><td align="center" valign="top" width="50%"> <label>Xbox 360 Original (Beige or Black)<br /><img src="images/xbox360orig.gif" width="250" height="250"><br /><input class="button" type="radio" name="console" value="xboxorig" /></label></td> <td align="center" valign="top" width="50%"><label>Xbox 360 Slim<br /><img src="images/xbox360slim.gif" width="250" height="250"><br /><input type="radio" name="console" value="xboxslim" /></label></td> </tr> <tr> <td colspan="2"> <input type="submit" value="Next"> </form> </td> </tr> </table> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; case "2": $console = $_POST['console']; echo $console; ?> Please enter your Xbox 360 Serial Number:<br /> <form action="?step=3" method="post"> <input name="serialno" type="text" size="20" maxlength="20"> <input type="submit" value="Next"> </form> <?php echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; case "3": echo "<br />"; $serialno = $_POST['serialno']; echo $serialno; echo $console; echo $code; include("footer.php"); echo $code2; include("compat.php"); echo $code3; } ?> I do understand it's messy at the moment but I don't see much point beautifying everything until I can solve this problem! Cheers! Hey guys, I have checked in google and on this forum for answers to my question but haven't found anything regarding validating each step of a multipage form, hence my post! I wonder if anyone can help me, or rather provide me with advice.... I am trying to create a multipage form, which so far i have done a basic one which i have done using my php cookbook by O'Reilly which is a very basic version, without any validations or anything.... My multipage has 3 steps: Step1: user details - takes users name, email etc Step 2: House details - Takes users address, house type, no of rooms, descriptions of rooms etc Step 3: Image upload - Allows user to upload 3 images max to display (using my original file upload script) As i said, my basic multipage form works, storing all posted values into sessions which can then be outputted at the end in a review page, which will be at the end of the form. In previous forms i have created, i always have an html form, which when posted or submitted, has an action of a separate php script which processes the form and validates it, sends email, updates database etc, and all errors are then stored in sessions and appear back on the form page until there are no errors displayed and then a success page is shown.... so the code i have taken from my cookbook doesn't seem to be able to allow me to validate EACH STEP of the form? it can validate at the end, when the user reviews and then the form is processed all in one go. But i want to be able to validate form entries at each step, rather than in one go. For example if a user leaves their 'town' field empty, an error message will be displayed before going to the next step... If you see the code i have done so fare below: Code: [Select] <?php //Figure out what stage to use if (($_SERVER['REQUEST_METHOD'] == 'GET') || (! isset($_POST['stage']))) { $stage = 1; } else { $stage = (int) $_POST['stage']; } //Save any submitted data if ($stage > 1) { foreach ($_POST as $key => $value) { $_SESSION[$key] = $value; } } if ($stage ==1) {?> <div id="submitCustomerForm"> <FORM ACTION='<?php echo $_SERVER['SCRIPT_NAME'] ?>' method='post'> <h7>Your details</h7> <br /> <div id="inputfield"> <label class="textleft" for="forename">forename:</label> <input class="fade" name="forename" type=text size="30" align="right" maxlength="15" id="forename" value="<?php echo $_SESSION['forename']?>"> </div> <div id="inputfield"> <label class="textleft" for="surname">surname:</label> <input class="fade" name="surname" type=text size="30" maxlength="15" id="surname" align="right" value="<?php echo $_SESSION['surname']?>"> </div> <div id="inputfield"> <label class="textleft" for="email">email:</label> <input class="fade" name="email" type=text size="30" maxlength="30" align="right" id="email" value="<?php echo $_SESSION['email']?>"> </div> <br /> <h7>Your property Address</h7> <br /> <div id="inputfield"> <label class="textleft" for="address1">Address Line 1:</label> <input class="fade" name="address1" type=text size="30" maxlength="30" id="address1" value="<?php echo $_SESSION['address1'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="address2">Address Line 2:</label> <input class="fade" name="address2" type=text size="30" maxlength="30" id="address2" value="<?php echo $_SESSION['address2'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="town">Town/City:</label> <input class="fade" name="town" type=text size="30" maxlength="30" id="town" value="<?php echo $_SESSION['town'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="county">County:</label> <input class="fade" name="county" type=text size="30" maxlength="30" id="county" value="<?php echo $_SESSION['county'];?>" /> </div> <div id="inputfield"> <label class="textleft" for="postcode">Post Code:<span class="asterix">*</span></label> <input class="fade" name="postcode" type=text size="30" maxlength="30" id="postcode" value="<?php echo $_SESSION['postcode'];?>" /> </div> <input type='hidden' name='stage' value='<?php echo $stage + 1 ?>'/> <input name="Next" class="submit" type="image" align ="right" src="Images/updateButton.png" /> </FORM> </div> <?php } else if ($stage == 2) { ?> <div id="submitCustomerForm"> <FORM ENCTYPE="multipart/form-data" action="<?php echo $_SERVER['SCRIPT_NAME']?>" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="1000000" /> <div id="divinputfile"> <input name="userfile" type="file" size="30" id="userfile" onchange="document.getElementById('fakeuserfile').value = this.value;"/> <div id="fakeinputfile"><input name="fakeuserfile" type="text" id="fakeuserfile" /></div> </div> <br /> <input type='hidden' name='stage' value='<?php echo $stage + 1 ?>'/> <input type="image" src="Images/upload.png" align="right" name="Send File" /> <br /> <br /> </FORM> </div> <?php } else if ($stage == 3) {?> <p class="largeblue"> hello there <?php echo $_SESSION['forename']; echo $_SESSION['surname'];?> <br /> the first line of your address is: <?php echo $_SESSION['address1'];?> <br /> the second line of your address is: <?php echo $_SESSION['address2'];?> </p> <?php } ?> For the 'form action' it uses Quote <?php echo $_SERVER['SCRIPT_NAME'] ?> meaning that the form reloads the page, upon which the stage number has changed and therefore loads next step. Where as normally, i have the path for my process script which would handle validation etc and then send them to a success screen or back to the form displaying errors. I propose a few ideas that i could do to get around this, which i just wanted to get a bit of insight on, as to which way of going about this is the right one!! My first idea would be to treat each step of the form as a separate form almost. Doing a form as i normally do, where the form is on one page, then the completed form is sent to a processing page, which processes the entries, sends user back to the form page with errors if there are any, or if it is all ok, increase the 'stage number' in a session and then use a header to go to next page(the next step of the form. at the top of each page is a check to whether the stage number is the same as the step number of the form. OR would i put all my validation in one page, with all the steps of the form as i have at the moment? OR is there a way to send each step of the form to a process script, which then sends the user back to the original form displaying errors if there are any or then moves them to the next step?? Just a little confused with which method to do this, i dont want to start working on it and find out i have done it completely the wrong way!! any help would be greatly received, thanks guys!! Craig I'm stuck at trying to figure out out to complete the 3 Step scripts to accomplish passing $variables between 2 different servers. Since there will actually be 12 Non-POST $variables involved in the SERVER #1 to SERVER #2 transfer , it doesn't appear that trying to put these all in a URL string and going the 'GET' route is practical.
I'm just using 3 short test variables in the examples. My eyeballs started rolling within I ran across something about 'CURL' that might be a necessary part of the solution?
The code I have been able to hammer out so far is below as STEP 1, STEP 2 and STEP 3.
STEP 1
<?php // submit.php // STEP 1 // On (LOCAL) SERVER #1 TO relay $variables to 'process.php' on (REMOTE) SERVER #2 // To submit $variables to directly another destination server script // NOTE: The $variable are NOT the result of Form Input !!! // For login Authenticaion ALL 3 must match db entries on SERVER #2 // NOTE: (Again) The $variables are NOT the result of Form Input !!! $userid = "adam"; $passwd = "eve"; $pscode = "peterpan"; // NOTE: (Again) The $variable are NOT the result of Form Input !!! // These $variables are needed for MySQL db INSERT on the destination URL server // For testing simplicity (actual data will be 12 $variables) $a = "apple"; $b = "banana"; $u = "1234567; // // Not sure if something called 'CURL' is needed here ??? // $submit_to_url = http://www.blahblah.com/process.php"; ?>STEP 2 <?php // processor.php // STEP 2 // ON SERVER #2 TO RECEIVE DATA DIRECTLY FROM SERVER #1 'submit.php' // To receive and process the $variables into a MySQL db on SERVER #2 // NOTE: The $variables are NOT the result of Form Input !!! // First validate $userid, $passwd & $pscode against `verify` table MySQL records require '/SERVER_2_securelocation_for_database_connection/secret_mysqli.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // // Not sure if something called 'CURL' is needed here ??? // // These login $variables are from submit.php on SERVER #1 $userid $passwd $pscode $sql="SELECT `userid`, `passwd`, `pscode` FROM `verify` WHERE `userid` = '$userid'" AND `passwd` = '$passwd` AND `pscode` = '$pscode'; $result = mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } // // Then some Authentication code if ALL 3 components match // // If Authentication = true then $passed = "YES" must sent // be sent back to the 'finalstep.php' script on SERVER #1 // If Authentication (or connection) = false ... $passed = "NO" $return_to_url = http://www.blahblah.com/finalstep.php"; // These $variables are from submit.php on SERVER #1 $a = "apple"; $b = "banana"; $u = "1234567"; $sql="INSERT INTO `data` (`a`, `b`, `u`) VALUES ('$a', '$b', '$u')"; if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } // If $SQL INSERT into `data` on SERVER #2 works ... // $status = "Pending" must be sent back to the 'finalstep.php' // script on SERVER #1 for MySQL db Table insertion // If $SQL INSERT into `data` = false, then $status = "Error" // NOTE: The '$u' $variable also needs send back to finalstep.php !!! $return_to_url = http://www.blahblah.com/finalstep.php"; mysqli_close($con); ?>STEP 3 <?php // finalstep.php // STEP 3 // ON SERVER #1 TO RECEIVE DATA DIRECTLY BACK FROM SERVER #2 process.php // To receive the $passed, $status and $u $variables for final step action // NOTE: The $variable are NOT the result of Form Input !!! require '/SERVER_1_securelocation_for_database_connection/secret_mysqli.php'; if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // These $variables are from process.php on SERVER #2 $passed $status $u $sql="UPDATE `tracking` SET `passed` = '$passed', `status` = '$status' WHERE `uniqueid` = '$u' "; $result = mysqli_query($con,$sql); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } mysqli_close($con); ?>Thanks very much for any assistance and guidance. -freakingOUT I can add and delete data from my table. Now I need to be able to change one or more fields in an entry. So I want to retrieve a row from the db, display that data on a form where the user can change any field and then pass the changed data to an update.php program. I know how to go from form to php. But how do I pass the data from retrieve.php to a form so it will display? Do I use a URL and Get? Can I put the retrieve and form in the same program? Dear All Members here is my table data.. (4 Columns/1row in mysql table)
id order_no order_date miles How to split(miles) single column into (state, miles) two columns and output like following 5 columns /4rows in mysql using php code.
(5 Columns in mysql table) id order_no order_date state miles 310 001 02-15-2020 MI 108.53 310 001 02-15-2020 Oh 194.57 310 001 02-15-2020 PA 182.22
310 001 02-15-2020 WA 238.57 ------------------my php code -----------
<?php
if(isset($_POST["add"]))
$miles = explode("\r\n", $_POST["miles"]);
$query = $dbh->prepare($sql);
$lastInsertId = $dbh->lastInsertId(); if($query->execute()) {
$sql = "update tis_invoice set flag='1' where order_no=:order_no"; $query->execute();
} ----------------- my form code ------------------
<?php -- Can any one help how to correct my code..present nothing inserted on table
Thank You Edited February 8, 2020 by karthicbabuHi, My company has 240+ locations and as such some users (general managers) cover multiple sites. When I run a query to pull user information, when the user has multiple sites to his or her name, its adds the second / third sites to the next columns, rather than wrapping it inside the same table cell. It also works the opposite way, if a piece of data is missing in the database and is blank, its pull the following columns in. Both cases mess up the table and formatting. I'm extremely new to any kind of programming and maybe this isn't the forum for this question but figured I'd give it a chance since I'm stuck. The HTML/PHP code is below: <table id="datatables-column-search-select-inputs" class="table table-striped" style="width:100%"> <thead> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> <th>Actions</th> </tr> </thead> <tbody> <?php //QUERY TO SELECT ALL USERS FROM DATABASE $query = "SELECT * FROM users"; $select_users = mysqli_query($connection,$query);
// SET VARIABLE TO ARRAY FROM QUERY while($row = mysqli_fetch_assoc($select_users)) { $user_id = $row['user_id']; $user_firstname = $row['user_firstname']; $user_lastname = $row['user_lastname']; $username = $row['username']; $user_phone = $row['user_phone']; $user_image = $row['user_image']; $user_title_id = $row['user_title_id']; $user_role_id = $row['user_role_id'];
// POPULATES DATA INTO THE TABLE echo "<tr>"; echo "<td>{$user_id}</td>"; echo "<td>{$user_firstname}</td>"; echo "<td>{$user_lastname}</td>"; echo "<td>{$username}</td>"; echo "<td>{$user_phone}</td>";
//PULL SITE STATUS BASED ON SITE STATUS ID $query = "SELECT * FROM sites WHERE site_manager_id = {$user_id} "; $select_site = mysqli_query($connection, $query); while($row = mysqli_fetch_assoc($select_site)) { $site_name = $row['site_name']; echo "<td>{$site_name}</td>"; } echo "<td>{$user_title_id}</td>"; echo "<td>{$user_role_id}</td>"; echo "<td class='table-action'> <a href='#'><i class='align-middle' data-feather='edit-2'></i></a> <a href='#'><i class='align-middle' data-feather='trash'></i></a> </td>"; //echo "<td><a href='users.php?source=edit_user&p_id={$user_id}'>Edit</a></td>"; echo "</tr>"; } ?>
<tr> <td>ID</td> <td>FirstName</td> <td>LastName</td> <td>Username</td> <td>Phone #</td> <td>Location</td> <td>Title</td> <td>Role</td> <td class="table-action"> <a href="#"><i class="align-middle" data-feather="edit-2"></i></a> <a href="#"><i class="align-middle" data-feather="trash"></i></a> </td> </tr> </tbody> <tfoot> <tr> <th>ID</th> <th>FirstName</th> <th>LastName</th> <th>Username</th> <th>Phone #</th> <th>Location</th> <th>Title</th> <th>Role</th> </tr> </tfoot> </table>
Hi all, Just curious why this works: Code: [Select] while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values('$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]')"; } And this does not: $headdata_1 = "'$data[0]','$data[1]','$data[2]','$data[3]','$data[4]','$data[5]','$data[6]'"; while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){ $import="INSERT into $prodtblname ($csvheaders1) values($headdata_1)"; }it puts $data[#'s] in the database fields instead of the actual data that '$data[0]','$data[1]'... relates to. I wrote a script to create the values in $headdata_1 based on the number of headers in $csvheaders1 but can't seem to get it working in the sql statement. Thanks Hi all, I'm a first time poster here and I would really appreciate some guidance with my latest php challenge! I've spent the entire day googling and reading and to be honest I think I'm really over my head and need the assistance of someone experienced to advise the best way to go! I have a multi dimensional array that looks like (see below); the array is created by CodeIgniter's database library (the rows returned from a select query) but I think this is a generic PHP question as opposed to having anything to do with CI because it related to working with arrays. I'm wondering how I might go about searching the array below for the key problem_id and a value equal to a variable which I would provide. Then, when it finds an array with a the matching key and variable, it outputs the other values in that part of the array too. For example, using the sample data below. How would you recommend that I search the array for all the arrays that have the key problem_id and the value 3 and then have it output the value of the key problem_update_date and the value of the key problem_update_text. Then keep searching to find the next occurrence? Thanks in advance, as above, I've been searching really hard for the answer and believe i'm over my head! Output of print_r($updates); CI_DB_mysql_result Object ( [conn_id] => Resource id #30 [result_id] => Resource id #35 [result_array] => Array ( ) [result_object] => Array ( ) [current_row] => 0 [num_rows] => 5 [row_data] => ) Output of print_r($updates->result_array()); Array ( [0] => Array ( [problem_update_id] => 1 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Some details about a paricular issue [problem_update_active] => 1 ) [1] => Array ( [problem_update_id] => 4 [problem_id] => 3 [problem_update_date] => 2010-10-01 [problem_update_text] => Another update about the problem with an ID of 3 [problem_update_active] => 1 ) [2] => Array ( [problem_update_id] => 5 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of four [problem_update_active] => 1 ) [3] => Array ( [problem_update_id] => 6 [problem_id] => 4 [problem_update_date] => 2010-10-12 [problem_update_text] => An update about the problem with an ID of 6 [problem_update_active] => 1 ) [4] => Array ( [problem_update_id] => 7 [problem_id] => 3 [problem_update_date] => 2010-10-12 [problem_update_text] => Some new update about the problem with the ID of 3 [problem_update_active] => 1 ) ) Hello, I have read tutorials, searched forums for 2 weeks, and not found the assistance I require. I now jump in to ask my questions with the assistance from those much wiser then I... I am new to this arena, so I honor your understanding to my situation. I have 2 Solar Inverters that I have at my home, and I have a RS232 data port on each that is now connected to my home network via an IP converter to upload the data of the power they make each hour to a simple website I made, so I can see what is going on durring the hours I am at work. The information goes to my FTP site and the data falls into the MySQL table perfectly. I am trying to get the PHP and MySQL code to list the data into the forms/tables on the web page. For this project I have set up Dreamweaver CS5 and a test server on my home PC, to get this working. All the data on the web host MySQL table is the same as in the test server (other then the host, name, and password but it works fine). I have a very basic MySQL Named "inverters", and the table below named "feed"... +---------+----------+------------+---------+------------+----------+ | Unit ID | Date | Time | Power | Volts | Current | +---------+----------+------------+---------+------------+----------+ | 1 |YYYY-MM-DD| 12:00:00 | 560 | XXXX | XXXX | +---------+----------+------------+---------+------------+----------+ | 1 |YYYY-MM-DD| 13:00:00 | 565 | XXXX | XXXX | +---------+----------+------------+---------+------------+----------+ | 1 |YYYY-MM-DD| 14:00:00 | 890 | XXXX | XXXX | +~~~~~~+~~~~~~+~~~~~~~~+~~~~~~+~~~~~~~+~~~~~~~+ Etc.... The 'Time' has 24 rows for each day, each 'Date" shows the same date for each of the 24 rows of 'Time". The 'Power', is assigned as double the Volts and Current are "float". I am able to SUM the Total "Power" of all the "Power" Rows with... <? $con = mysql_connect("localhost","NAME","PASWORD"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("inverters", $con); $qry = mysql_query(" SELECT SUM(Power) AS total FROM feed "); $row = mysql_fetch_assoc($qry); echo $row['total']; mysql_close($con); ?> I have been trying for weeks to get "the CURRENT DAY power", Week Power, the month power etc to show the data on the webpage with no luck. A very simple table on the website... As seen on the website. +-----------+----------------+-----------------+-----------------+ | Today | This Month | This Year | Lifetime Power | +-----------+----------------+-----------------+-----------------+ |????????| ??????????|???????????|----working----| +-----------+----------------+-----------------+-----------------+ For the Current Day, I have tried this, but it does not work... $query = mysql_query("SELECT(date), SUM(Power) AS 'day_total' FROM feed WHERE (date) = CURDATE() GROUP BY (date) ORDER BY (date) "); $result = mysql_fetch_array($query); $daytotal = $result["day_total"]; echo $row['day_total']; mysql_close($con); For the Month, I have tried this, but it does not work... $query = mysql_query("SELECT MONTH(date), SUM(Power) AS month_total FROM feed GROUP BY Month(date)"); $result = mysql_fetch_array($query); echo $row['month_total']; mysql_close($con); For the YEAR, I have tried this, but it does not work... $query = mysql_query("SELECT date, SUM(Power) AS total FROM feed GROUP BY date"); $result = mysql_fetch_array($query); echo $row['year_total']; mysql_close($con); I am reading and reading. Online I see how to get user names, and the time they register, and how many 'visitor' hits per year or month etc, but none have been informative to my situation. I think the more I read on the PHP and MySQL website manual, the more stupid I have become... Using Google to seach "how to get the SUM of Current Date" only showes me how to enter the current date on a webpage or in a table row, not how to SUM the values of a table of the current day. I also want to have a PHP graph (I have PHPgraphLIB now) on another page, and control the graph images by using a simple "Date Picker" or calendar, but that ran into the same type of issues as anything I write does not generate or show the results. I spent days using Prototype.js calendars and AJAX to connect the server side to the graphs and calendar etc..., but that is a different issue... hahaha I would greatly honor any assistance to my learning and functioning of this. Thank You, Alan $name = $name . "<option value=". $row['name'] . ">" .$row['name'] . "</option>"; but the name is "Mr. Robert",it does have dot symbol...how to overcome? please help I'm trying to split a url into segments so that a url would be stored in an array. Example: A url like this http://localhost/application/blog/view/Test-Blog-Entry/1 Would look like this in an array: Code: [Select] array('blog', 'post', 'Test-Blog-Entry', '1'); It's an MVC url so 'blog' would be controller, 'post', would be method and the last two would be variables. I want to display the variable values of the array. Is there an easy way to do this? hey guys i am stuck at one part. i am coding a site where on the index page there are 5 categories. Now on click of these it takes me to a page where i can search within a particular category. i can do it by statically giving <href="localhost/xampp/abc.php">and a fixed page path. but i want the name of the category passed when i click and the search page to open when i open search. thanks This script will clear the old limit value from the URL query: <?php //remove any old limits from query $tmp = array(); foreach ($_GET as $fld => $val) if ($fld != 'limit') $tmp[] = $fld . '=' . $val; $page_name = $_SERVER['SCRIPT_NAME'] . '?' . implode('&',$tmp); ?> Code: [Select] <form> <select"> <option value="<? echo "$page_name" ?>&start=0&limit=25">25 records per page</option> <option value="<? echo "$page_name" ?>&start=0&limit=50">50 records per page</option> <option value="<? echo "$page_name" ?>&start=0&limit=100">100 records per page</option> </select> </form> How can I get it to clear BOTH the start and the limit values in the URL? Thank you. ~Wayne I have two pages of php. one is page1.php and the other is page2.php. In page1.php there is a function which dynamically creates a form of html and return the full form at the end of the function. And I want to the function to return a 2nd variable with the form. and i get that variable on page2.php. How can i do this??? I'm working on a small project that requires a user login function. There's only going to be about 10 members in the database. I've followed a tutorial of how to make a login system. I've never really worked with sessions before, but I did some research and get the general concept of them. What I want to do is store the user's username in a session when they log in, so I can run queries and such later specific to that user. How would I do that? I was able to manually set a session, but I need to set the session equal to what their username is on login. I've tried doing that below, but I don't think it's working. Either that, or I'm not calling the session correctly in the other page where I want to display their username. Here's the code for the page that checks if the login is correct: Code: [Select] // username and password sent from form $myusername=$_POST['myusername']; $mypassword=$_POST['mypassword']; $encrypted_mypassword=md5($mypassword); $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$encrypted_mypassword'"; $result=mysql_query($sql); // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername'] = $myusername; $_SESSION['password'] = $encrypted_mypassword; header("location:login_success.php"); } else { echo "Wrong Username or Password"; } ?> Thanks in advance for any replies |