Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
It depends on what type of field is used int he database to store the time value. Depending on that you would probably need to use strtotime() along with date() to display the appropriate value.
-
Hmm, I really don't understand what you are trying to accomplish or the logic you are applying. If 10:00am = 10, and 10:30am = 20, etc. (i.e. every 30 minutes is 10 units). Then does 8:00am = -30? Also, what type of field is the data stored in the database?
-
This topic has been moved to PHP Freelancing. http://www.phpfreaks.com/forums/index.php?topic=330064.0
-
Accessing individual values of an array in a foreach loop?
Psycho replied to Conjurer's topic in PHP Coding Help
Correct, but your syntax is incorrect. First you should use double equal signs to compare two values. Second, you should not enclose the zero in quote marks since you want to compare to the numeric value of zero and not a string with the zero character elseif(mysql_num_rows($directoryResult)==0) { $output = "<tr><td>There are no records to display.</td></tr>"; } -
if(!isset($products['pro_install']) || !isset($products['custom_install'])) { //redirect code }
-
Do NOT rely upon values calculated by JavaScript. They are fine for displaying the total to the user, but if you hide/disable/mare readonly, a user can still manipulate the value that is sent to the processing page.
-
http://lmgtfy.com/?q=php+tutorial+zip
-
The hard option would be to create the two export files and put them in a zip archive and then download that to the user. A better option, in my opinion, is to simply have two links on the page (i.e. no form/button). Each link will have a target of "_blank" and the href will point to the exportexiting.php page, each with an additional parameter on the URL to specify which report to generate. Then the user simply has to click each link to download the report(s) they need.
-
If it is ALWAYS the first link then you could do this $newstring = preg_replace("#<a[^>]*>.*?<\/a>#", '', $textstring, 1);
-
Retaining selected item from option list, when form re-displays
Psycho replied to killdozer's topic in PHP Coding Help
foreach($state_province as $state) { $selected = ($state_province==$_POST['state']) ? ' selected="selected"' : ''; echo "<option value='($state_province)'{$selected} />{$state}</option>\n"; } -
Allowing user to change (variable) mysql variable by a radio button
Psycho replied to ryandward's topic in PHP Coding Help
It's really difficult to follow your code as it is poorly structured - plus you have no error handling in your code. If you did you would have seen the error in your UPDATE query. mysql_query(" UPDATE cars SET '$_POST[getchanged]'='$_POST[tochange]' where id = '$_POST[id]' "); You have the field name enclosed in single quote marks. If you enclose a field name in quote marks, you have to use back quotes. There are also several other problems in that code: No escaping of user input (i.e. preventing SQL injection), not referencing POST data correctly (no quote marks around index name), etc. Here is a rewrite of your code in a more logical format with error handling and other corrections. <?php require('connect.php'); $confirmMsg = ''; if(isset($_POST['submit'])) { //Parse user input $id = (isset($_POST['id'])) ? (int) $_POST['id'] : false; $field = (isset($_POST['value'])) ? mysql_real_escape_string(trim($_POST['value'])) : false; $value = (isset($_POST['value'])) ? mysql_real_escape_string(trim($_POST['value'])) : false; //Create and run query $query = "UPDATE cars SET `{$field}` = '{$value}' WHERE id = '$id'" $result = mysql_query($query); //Check results if(!$result) { $confirmMsg = "There was a problem updating the record."; } elseif(mysql_affected_rows()==0) { $confirmMsg = "There was no record to update."; } else { $confirmMsg = "The record was successfully updated."; } } //Create the select list options $recordOptions = ''; $query = "SELECT * FROM cars"; $result = mysql_query($query); if(!$result) { $recordOptions = "<option>Error Retrieving Records</option>\n";; } else { while($row=mysql_fetch_assoc($extract)) { $recordOptions .= "<option value=\"{$row['id']}\">"; $recordOptions .= "{$row['color']} {$row['make']} {$row['model']} {$row['year']}"; $recordOptions .= "</option>\n"; } } ?> <html> <body> <?php echo $confirmMsg; ?><br /> <form action ='' method='post'> <select name="id"> <?php echo $recordOptions; ?> </select> Which attribute would you like to change?<br /> <input type="radio" name="field" value="make"/>Make<br /> <input type="radio" name="field" value="model"/>Model<br /> <input type="radio" name="field" value="year" />Year<br /> <input type="radio" name="field" value="color" />Color<br /><br /> <br /><input type='text' value='' name='value'> <input type='submit' value='Change' name='submit'> </form> </body> </html> -
After you move the file to one location, copy it to the second location using copy(): http://php.net/manual/en/function.copy.php
-
I don't think there are any built-in functions to accomplish this. There are third party solutions. Here is one: http://www.acasystems.com/en/web-thumb-activex/faq-php-convert-html-to-image.htm
-
how to cross reference $_POST array 'checkboxes[]' with mysql field
Psycho replied to jason310771's topic in PHP Coding Help
OK, the form that submits to the 2nd page has a field called 'request_id', but your code is referencing the field as $_POST['request'] -
how to cross reference $_POST array 'checkboxes[]' with mysql field
Psycho replied to jason310771's topic in PHP Coding Help
There are no input fields on that form. What is the user supposed to be selecting? -
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=329438.0
-
how to cross reference $_POST array 'checkboxes[]' with mysql field
Psycho replied to jason310771's topic in PHP Coding Help
You are doing it the hard way. Instead of querying for all the records and then filter out the ones you don't want - simply query for only the records you need using the $_POST[request] value as a parameter in the SELECT query. //Clean the POST data array for query purposes $requestIDs = implode(',', array_map('intval', $_POST['request'])); //Create/run query to get only the records needed $query = "SELECT * FROM requests WHERE `customer_email`='{$_SESSION['FM_user']}' AND `request_id` IN ({$requestIDs})" $getRequests = mysql_query($query); //Display the valid results while($request = mysql_fetch_assoc($getRequests)) { echo "<li style=\"font-size:10px; border-bottom: 0.1em solid #D0D0D0\">\n"; echo " <div class=\"leftfloat\"> <input type=\"checkbox\" name=\"request[]\" value=\"{$request['request_id']}\"></div>"; echo " <div class=\"leftfloat\"> <em>{$request['request_id']}</em> </div><div class=\"leftfloat\"> | </div>\n"; echo " <div class=\"leftfloat\"> <em>{$request['customer_name']}</em> </div>\n"; echo " <div class=\"leftfloat\"> | </div>\n"; echo " <br style=\"clear:both\">\n"; echo "</li>\n"; } -
when user clicks checkbox, it's not captured in php array
Psycho replied to johnmerlino's topic in PHP Coding Help
EDIT: Pikachu2000 beat me to it, but I'll post this anyway since I provided some sample code If you want a 1 to be passed, then yes. As Pikachu2000 stated only checkboxes that are checked are passed in the post data. However, looking at your code, I think I see what you are trying to do and will propose an alternative. It looks like you are naming the checkboxes as an array with the index being an ID value of some sort. You are then checking the POST data and finding which "approved[id]" are checked. There is an easier way. It seems all you really need to know is what IDs were checked. Just create your checkbox array names with NO ID and use the ID as the value. <input type="checkbox" name="approved[]" value="1" checked="checked" /> <input type="checkbox" name="approved[]" value="3" /> <input type="checkbox" name="approved[]" value="4" /> Then in your post data, $_POST['approved'] will contain an array of all the record IDs that were checked. -
What is not simple/smart about checking if a user is logged in before displaying pages that require the user to be logged in? If you are storing a flag in the $_SESSION variable it is a simple task to check. Just include a file at the top of every page that requires the user to be logged in. That file would check if the user is logged in. If not, that file will redirect them to the login page and cancel execution of the rest of the script (which would have displayed the page requiring the user to be logged in).
-
You need to provide more information. You don't say HOW the user will select how many fields to display. Is the user going to make a selection and submit a form or are you expecting this to happen dynamically? If the latter, then you need JavaScript and you have posted this in the wrong forum. I'm also a little confused by the code you posted. It seems you are alternating back and forth between a select field for year and another for month. So, if the user selects "3" do you want to show two year selections and one month selection or do you want to show three "sets" of year and month selections? I would think the latter, but your naming convention of the fields is odd.
-
This topic has been moved to JavaScript Help. http://www.phpfreaks.com/forums/index.php?topic=329374.0
-
Accessing individual values of an array in a foreach loop?
Psycho replied to Conjurer's topic in PHP Coding Help
I would really suggest being more explicit in your code. Instead of using a foreach() loop on the individual fields, explicitly list the fields and the code you want. It makes debugging and modification much easier. Sometimes trying to make your code "simple" causes more trouble than it is worth. The function do_query is written in such a way that you are apparently using it to run/output many different queries. If you take that approach and start implementing if/else statements for each and every possible query it is going to be a nightmare to manage. Just create a function/process for each query/output you want to run. It's better to have more code that is logically structured. Note: I used mysql instead of mysqli functions in the code below because I have them remembered by heart. Modify them as needed. PHP code: <?php function db_connect() { $conn = new mysqli("localhost", "username", "password", "databasename");\ } function do_query($conn, $query) { return mysqli_query($conn, $query); } //connect to database $conn = db_connect(); $query = "Select member_image, member_name, city, phone, email FROM directory"; //call function do_query to run the query and output the table $directoryResult = do_query($conn, $querey); if(!$directoryResult) { $output = "<tr><td>There was a problem running the query.</td></tr>"; } elseif(mysql_num_rows($directoryResult)) { $output = "<tr><td>There are no records to display.</td></tr>"; } else { $imgPath = "images/"; $output = "<tr>\n"; $output .= "<th>Image</th>\n"; $output .= "<th>Name</th>\n"; $output .= "<th>City</th>\n"; $output .= "<th>Phone</th>\n"; $output .= "<th>Email</th>\n"; $output .= "</tr>\n"; while($record) { $output .= "<tr>\n"; $output .= "<td><img src=\"{$imgPath}{$record['member_image']}\" /></td>\n"; $output .= "<td>{$record['member_name']}</td>\n"; $output .= "<td>{$record['city']}</td>\n"; $output .= "<td>{$record['phone']}</td>\n"; $output .= "<td><a href=\"mailto:{$record['email']}\">{$record['email']}</td>\n"; $output .= "</tr>\n"; } } Then in the HTML code <table> <?php echo $output; ?> </table> -
That won't work. PHP is executed server-side and JavaScript is executed client-side. Once the page is delivered to the user (i.e. is displayed in their browser) you can't dynamically execute more code in that same PHP file. You have to do a new request to the server. So, you can "submit" the page when the user changes the selection so you can recreate the form with the appropriate data populated in the 2nd form OR you can use AJAX to dynamically do a server call to get the data and populate the data with JavaScript. Take a look at some tutorials to get started.
-
It really depends on EXACTLY what you are checking for. If you want to ensure the value is not an empty string, then the code you posted is appropriate. The empty() function returns true on several different values. http://php.net/manual/en/function.empty.php
-
mysql_fetch_array() gets the next (i.e. one) record from the result set. You are only retrieving one field, "email", so the count() for any one record would only be 1. If you want the number of records in the query result set you would use $logs = mysql_num_rows($loginsq);