Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
You only run one query. Then you use PHP to format the output using PHP code. You don't state how the columns should be constructed 1 2 3 4 5 6 7 8 or 1 3 5 7 2 4 6 8 Plus, how will you display them? DIVs, in a table, or what?
-
If you want to get a result of records based upon the time that a field was updated you need to add another field to track those changes. So, if you want to pull records based upon when 'status' field was updated in the members table, then you should add a new field, e.g. 'status_update', and set its value whenever status is changed.
-
Do a check before you allow a duplicate name, I suppose. You haven't supplied any information for us to be able to help you. Where is the code you currently use to verify if the names are similar? You should be doing that check directly with a DB check. In that case, as long as you are using an appropriate collation in the DB, it won't matter if the two values have different letters capitalized. But, if you are going to do it with PH code, then you could use strcasecmp()
-
You can't do that with PHP alone. PHP code is processed on the server. So, you can't have PHP process the data without sending the data to the server. With a standard HTML form that requires you to submit the data. The only wat to do what you want is to use AJAX to submit the data via JavaScript
-
explode() I would exlode just on the semi-colon and then use trim() to remove any spaces.
-
Depending on which version of those browsers you have, I suppose it should work. Maybe you have some other problem. But, you can put those other fields inside your form and have them displayed elsewhere on the page. Just use CSS to position them accordingly.
-
Probably because that was the whole point of having opening and closing form tags. The elements between those tags represent what is in the form. The form attribute is not supported in all browsers. So, if you want to be backward compatible you will need to put everything in the form tags EDIT: http://www.w3schools.com/tags/att_input_form.asp
-
You really haven't provided enough information to give a qualified answer. But, generally speaking, if the seats are all full save new users so that you know they are "waiting". How this should be done will depend greatly on how the current system and structure is organized. You may want to store these users in the same table with some identifier to know they are on the wait list and in what order, or you might want to store them in a completely different table. Then you will want a process where people on the wait list can get added to the confirmed list. Either by a current confirmed user cancelling or an administrator making that decision (e.g. someone doesn't show up for the event).
-
cakephp - get results from jquery within controller function
Psycho replied to coderhut's topic in PHP Coding Help
Why are you wanting to have a PHP function pass variables to JavaScript to do something? Why not just make the PHP function return the odd numbers. What you are asking sounds backwards to me. It is common to pass data from JavaScript to PHP to do something since PHP operates on the back-end and has access to things such as the database. It doesn't make sense to me to pass data to JavaScript to be processed. -
A lot of problems there. For one you are trying to output the results AFTER the closing HTML tag. You are also not checking for all errors or doing it incorrectly (not passing $con to mysqli_connect_errno() ). Plus, the username value is not within quotes inside the query. Give this a try <?php $output = ''; if(isset($_POST['username']) && isset($_POST['password'])) { $con = mysqli_connect('localhost', 'root2', '', 'first_db'); //Check connection if (mysqli_connect_errno($con)) { $output .= 'Failed to connect: ' . mysqli_connect_error(); } else { //Format values for SQL query $unameSQL = mysqli_real_escape_string(trim($_POST['username'])); //$pword = mysqli_real_escape_string(trim($_POST['password'])); //Create and execute query $query = "SELECT * FROM members WHERE username = '$unameSQL'"; $result = mysqli_query($con, $query); //Check if query passed if(!$result) { $output .= "Error runing query: {$query}<br>Error: " . mysqli_error($con); } //Check if there were results elseif(!mysqli_num_rows($result)) { $output .= "There were no matching records to username '{$uname}'"; } //Process results else { while($row = mysqli_fetch_assoc($result)) { $output .= "Username: {$row['username']}<br>\n"; $output .= "Password: {$row['password']}<br>\n"; $output .= "ID: {row['id']}<br><br>\n"; } } } } ?> <html> <?php echo $output; ?> <form action="index.php" method="post"> <input type="text" name="username"><br> <input type="text" name="password"><br> <input type="submit"> </form> </html>
-
1. Never, ever use data directly from users in a query without using some process to sanitize it. 2. You are dynamically defining the table based on $speciestype = $_POST['fishtype']; That makes no sense. You are already using fishtype as one of the data values, so why would you have different tables? 3. Assuming the dynamic table name is not a problem, you have two consecutive commas at the end of the query. Don't be afraid to format the query for readability - makes debugging so much easier. 4. For debugging, echo the query out to the page so you can check the query against the error message $sql="INSERT INTO $speciestype (username, email, speciesName, commonName, scientificName, synonym1, origin, size1, environment, waterChemistry, temperature, feeding, sexing, compatability, temperament, breeding, comments, photo, rewards) VALUES ('$_POST[username]', '$_POST[email]', '$_POST[fishtype]', '$_POST[speciesCommon]', '$_POST[speciesScientific]', '$_POST[speciesSynonym]', '$_POST[origin]', '$_POST[size]', '$_POST[environment]', '$_POST[waterChemistry]', '$_POST[temperature]', '$_POST[feeding]', '$_POST[sexing]', '$_POST[compatability]', '$_POST[temperament]', '$_POST[breeding]', '$_POST[comments]', '$_POST[photo]', '$_POST[rewards]')"; if (!mysqli_query($con,$sql)) { die("Query: {$query}<br>Error: " . mysqli_error($con)); }
-
Not sure I understand what you are talking about. The value is already available in the text area - why do you need to "mirror" it (whatever that means) into a text box? Why can't you use the value from the text area?
-
Yep, as mac_gyver states, you are simply doing it wrong. I previously stated . . . which is exactly what you are doing. You have multiple guests and you want to indicate which ones have had which meals. This is a very simple problem - you just need to name the fields appropriately. In this case you are entering records for each GUEST, so the values should be constructed to make that processing easy. But, you still have the problem that if no boxes are checked for a guest then you don't have any data in the POST data to insert a record with 0 values. The solution is easy - create a hidden field on the form for each guest ID. Here is an example of how the input fields could be constructed for a single guest: Guest ID5: <input type="hidden" name="guests[]" value="5" /> <input type="checkbox" name="breakfast[5]" value="1" /> <input type="checkbox" name="lunch[5]" value="1" /> <input type="checkbox" name="dinner[5]" value="1" /> <input type="checkbox" name="midnight[5]" value="1" /> Then to process ALL the guests (even those that did not have any meals) you could do something like this: foreach($_POST['guests'] as $guestID) { $breakfast = (isset($_POST['breakfast'][$guestID])) ? 1 : 0; $lunch = (isset($_POST['lunch'][$guestID])) ? 1 : 0; $dinner = (isset($_POST['dinner'][$guestID])) ? 1 : 0; $midnight = (isset($_POST['midnight'][$guestID])) ? 1 : 0; //Run query to insert record }
-
As already stated only CHECKED checkboxes are passed in the form data. This has been the behavior for decades. You do not need an array of a bunch of yes/no values. You are trying to fix a problem that doesn't exist. There are better solutions than what you are trying to do. You should never try to associate data based upon its position in a list. The problem is in how you are creating the form fields and how you are processing the data. Second, you shouldn't be storing string values of On and Off and should instead be storing the logical value of o and 1 that can be interpreted as Boolean values. I can't really make heads or tails of your form since it is dynamically created. But, a simple solution to what you should be doing is something like this: $lunch = (isset($_POST['lunch'])) ? 1 : 0; If 'lunch' is set in the POST data (in other words it was checked) it will set the value to 1, else the value will be 0.
-
For what purpose? You already have a list of the checked options, so you know all the others were unchecked. Depending on how you are using the data, there are different solutions for what you need.
-
Where did this line come from? sortMyArray($tempData[$nameColumn], SORT_REGULAR); You already have the usort() function with is calling the sortMyArray() function, so why are you calling it separately? It wouldn't even do anything in that context. Plus, the loop is messed up now since it will only process data if $headerRow = false! Instead, you need to put a test at the start of the code within the loop to test if $headerRow equals false or not. If it does, then it should set $headerRow to the contents of the current row of data being processed and then "continue" with the loop. Then put all the processing logic AFTER that if() condition and code block. if($headerRow == FALSE) { $headerRow = $dataRow; continue; //Start next iteration of the loop } //Code to process normal $dataRow records continues here Then, after the while() loop completes you should have two variables: $headerRow: Contains the unprocessed array from the header row $tempData: The array of all the processed data records Then, go ahead and sort the $tempData as you need it. Lastly, write the $headerRow to the output file and then run a loop over the $tempData to write all the processes/sorted data to the output file.
-
query to display identical data from two columns in one table?
Psycho replied to gerryf19's topic in MySQL Help
OK, well, if you haven't already figured out how you are going to solve this, I would suggest the following: 1. Update the import process to trim the values before inserting into the database. 2. Run a query to correct all the current values UPDATE `SCHEDULE` SET `Home` = TRIM(`Home`), `Away` = TRIM(`Away`) -
query to display identical data from two columns in one table?
Psycho replied to gerryf19's topic in MySQL Help
No, you shouldn't even be getting ANY result with that query because none of the records have Team1 as the Home team AND the Away team. That would only occur if Team1 was playing themselves! So, I am confused as to why you are even getting a result. There must be some other problem causing that. You should be using an OR condition. -
@neil, Based on his request, I'm not sure he even needs AJAX. Unless he a LOT of possible options for the functionality, it sounds as if it could all be done client-side.
-
The same also holds for a select field that uses the multiselect parameter. You need to name the field with a [] at the end for the multiple values to be passed as an array. <select name="customerID[]"> Also, I prefer to use double quotes when defining strings with variables echo "<option value='{$row['ID']}'>{$row['LastName']}, {$row['FirstName']}</option>"; Whether you use a select list or a checkbox is a personal decision. I prefer using checkboxes since many users don't know how to make multiple selections in a select field.
-
OK, you can't do a foreach() loop on a string, which is why you are getting the error. Are you allowing the user to make multiple customerID selections/entries? Did you name the fields appropriately so it will be sent as an array? E.g. <input type="checkbox" name="customerID[]" value="33" /> Note the [] at the end of the input name
-
Sounds to me like you are wanting functionality that requires JavaScript. If you want these changes to be applied dynamically as the user interacts with the form then you need JavaScript. To do this only with PHP, the user must make their entries then submit the form to the server.
-
What do you get with this var_dump($_POST['customerID']);
-
Actually, look at the third user contribution that has a more efficient solution.
-
I think the function is poorly defined in the manual. The function preg_grep() returns an array of the keys where the VALUE of the array matches the regular expression. Take a look at the second user note in the manual where someone submitted a function to do a search using the keys. http://php.net/manual/en/function.preg-grep.php