-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
the problem is because your form processing code isn't testing which form has been submitted. all you are testing is - if(isset($_POST['submit'])){ for both forms. when the second form is submitted, $_POST['linkto1'] and $_FILES["up"]["name"] don't exist, but your php code for the first form is running and updating the row WHERE id = '1' with empty values. you must detect which form has been submitted and only run the correct piece of php code. the best way of doing this is to use a hidden form field with a different name attribute for each form. you would then change the two if(isset($_POST['xxxxxxx])){ lines to test for the correct name.
-
no, you didn't mention that in this thread. you cannot assume anyone reading your thread knows anything about your previous threads or problems or how this tread relates to any previous thread or problem. have you checked with your web host to find the proper method of changing the upload file size limits on their server? you cannot set them in your .php file because php uses the settings before your php script is even executed. you can only set them in a .htaccess file when php is running as an Apache Server Module (you get a server if you try.) you can set them in a local php.ini when php is running as a cgi/fastcgi application. if your upload script is in a folder, you will likely need to have a php,ini file in the same folder where the script is at. some web hosts use a different name for the php.ini file, such as php5.ini. you must find out if your web host allows you to change the two settings at all (both post_max_size and upload_max_filesize must be change and they must be set to realistic and valid values) and where and how to change them.
-
INSERT queries don't have WHERE clauses. an INSERT query inserts a new row, using the values you supply in the query. perhaps you are thinking of an UPDATE query?
-
I need help with PHP could someone help?
mac_gyver replied to LaughingQuoll's topic in PHP Coding Help
a) you already started a thread for this, which was moved to the job offerings forum section. there's a redirect link to it in the forum section where you originally posted. b) don't post the same topic multiple times. c) don't bump your topics after 1 minute. d) locking this topic.... -
have you even confirmed that your form is submitting the fields with the names and values that you think it is - echo '<pre>',print_r($_POST,true),'</pre>'; beyond that, the problem is in your code, either with mistyped names or code that is setting the value to an empty string or completely unsettling it. in post #2 in this thread Ch0cu3r suggested setting php's error_reporting/display_errors to get php to help you. did you do that?
-
most of the functions you have in your code won't work using the http:// protocol, and even if they did, what you are doing would be uploading the file to the first server, then moving it to the second server. this would use double your file transfer bandwidth on the first server. so, what exact problem are you trying to solve.
-
because your code is only using one set of variables, the last validation test will win. a better approach would be to use an array to hold the validation messages, one array entry per message. this will let you perform all your validation tests and output a message for each one that failed. you would also use the array as the flag that indicates a success or failure. if the array is empty() there are no validation errors. if the array is not empty, loop over and output the error messages stored in it.
-
what have you tried? just posting your existing code doesn't given us anything upon which to help you with. your code above also has about the first 1/3 of the code repeated.
-
your two threads have been merged together. do not keep creating new threads for the same problem.
-
the problem's not very likely anything to do with your web host. two people have suggested the symptom is due to non-printing/white-space characters that are stored in the database table. you were even asked specifically how the data got inserted into the table and if the code doing that was validating the data -
-
you should set those settings in your php.ini on your development system so that you don't need to remember to put the settings into your code for development and remove them on a live server. those two setting being in your code won't show php parse errors in your main file because parse errors are detected before your code is even considered to be code, so the lines with those settings never run.
-
a) what debugging have you done to narrow down the problem? b) what exact output are you getting, as that would at least point a smaller portion of the code to look at?
-
you are using php datetime objects and the date_add/date_sub functions/methods are modifying the instance of the datetime object. these are not values, they are instances of a class/object. it's also a safe bet that your grid widget expects an array of literal date strings. to output or store to an array entry, the current value of your datetime object as a literal string, you need to use the date_format() function/method.
-
holy mixed html and code Batman. there's four different locations in that code that run those two update queries. at a minimum, you need to organize the logic so that the php code processing the form submission(s) comes first on the page, where those two queries would only exists once in the code. all the css, javascript and html markup should be separated from the main php logic and come at the end of the file.
-
here's a possibility, you are running that code a second time with an empty $_POST["bet"] value (or you have some other update code later in the program) and are updating the values back to the original values in $info["cash"] and $object["bank"]? at this point (i.e. a page that's doing something unexplained), seeing all the code needed to reproduce the problem would lead to the quickest solution.
-
you likely have some white-space/non-printing characters as part of the data. what does using var_dump() on each of the php variables - $info["cash"], $_POST["bet"], $info["login"], $object["bank"], and $info["land"] show (this is primary looking for the length to see if it matches the number of printing characters being displayed)?
-
you are going to need to troubleshoot the problem to narrow it down. either the data being stored in your table isn't what you think (has white-space/non-printing characters as part of it so it doesn't match what the query is using) or your code forming that query, running it, and displaying the result contains a problem. how are your email values getting inserted into the table (some type of csv import or a registration form)? is the code filtering/validating them so that you know they don't contain any extra white-space/non-printing characters? what's your full code from the point of inputting/selecting the email address (a form/dropdown menu...) through to the end of the code that is telling you the email address doesn't exist?
-
your WHERE clause is likely false or the value being updated isn't valid for the field type. which of those queries isn't working and it would be helpful if you posted the query that you echoed so that we could see it to see if there is anything obvious about it that could be causing the problem.
-
you also need to set display_errors to ON (you should set error_reporting/display_errors in your php.ini on your development system so that you don't need to remember to put the settings into your code during development and remember to remove them when you put your code onto a live server.) the reason your select menu doesn't remember the selected value is because you don't have any code to cause it to remember. as you are outputting the <option ...> tags, you must output the selected keyword in the correct <option ...> tag that you want to be selected. to do this you would test if the $_POST['value1'] isset and has the same value as the $row[0] value.
-
your posted snippets of code don't tell us the full story of what the code is doing on the page. best guess is you have some code somewhere that's using one = sign in a comparison statement, which is setting $_SESSION['loggedin'] = true, rather than testing if $_SESSION['loggedin'] == true. it's also possible that your logout script is using a different variation of your domain name in the url (one with with and the other with out the www. on it) and the session it is trying to clear isn't the same session as the one your login code created. please post all the code making up your index.php page (less any database credentials) and i would recommend echoing the session_id() value on both your index and logout web pages to see if the session being operated on is the same one.
-
if you are using Firefox, you must enable the spell check and pick the correct language. these are saved as site preferences. to do this, click on the forum's edit form and type some text (this doesn't work when the form is empty.) right click over some of the text you just typed in the form and select the Check Spelling line and under the Languages, pick a choice (there might be only one choice.)
-
Radio Buttons From MySQL & Drop-Down Menu
mac_gyver replied to SalientAnimal's topic in PHP Coding Help
the following is your posted code, rearranged as described (except for removing an extra </title> tag that is saw, i didn't fix or intentionally alter any of the code) - <?php include_once 'includes/functions.php'; include_once 'includes/register.inc.php'; include_once 'includes/session_management.php'; include_once 'includes/formatting.php'; include_once 'includes/db_connect.php'; // ---------------------------- these two functions should be in functions.php ------------------------- //FUNCTION TO CREATE HTML FOR OPTIONS LIST function createOptions($optionList, $selectedValue) { $options = ''; foreach ($optionList as $option) { $selected = ($option['value']==$selectedValue) ? ' selected="selected"' : ''; $options .= "<option value='{$option['value']}'{$selected}>{$option['label']}</option>\n"; } return $options; } function db_result_to_array($result) { for ($count=0; $row = $result->fetch_assoc(); $count++) { $res_array[$count]=$row; } return $res_array; } // ------------ these two includes apparently have something to do with producing the html document, // but you had them before the <head> tag so i don't know where they belong at on this page ------------- // INCLUDING THE TOP LOGIN / LOGOUT PANEL include 'includes/panel.php'; // INCLUDING THE NAVIGATION MENU include '/nav/menu.html'; // ----------- the following is the business logic, that determines what to do, when to do it, // and gets the data that the presentation logic needs ------------------------------------------------ //DETERMINE SELECTED OPTIONS PASSED ON QUERY STRING $shift = isset($_GET['shift']) ? intval($_GET['shift']) : false; //$agent = isset($_GET['agent']) ? intval($_GET['agent']) : false; //$tertiary_category = isset($_GET['tertiary_category']) ? intval($_GET['tertiary_category']) : false; //GENERATE OPTIONS FOR THE SHIFT OPTIONS $query = "SELECT DISTINCT id AS value, shift AS label FROM shift_structure WHERE active_status = 1 ORDER BY id"; $optionList = $db->query($query); $shift_options = createOptions($optionList, $shift); //SELECTING THE AGENTS THAT ARE SCHEDULE FOR THE MENTIONED SHIFT if($shift) { $query = "SELECT shift AS value, agent AS label FROM schedule WHERE id = $shift"; $optionList = $db->query($query); $agent_options = createOptions($optionList, $shift); } $query = "SELECT DISTINCT(agent), agent_id FROM schedule WHERE shift = $shift AND DATE(start) = curdate() "; $result = $db->query($query); $num_results = $result->num_rows; // ---------------------------- the presentation logic is below this line ---------------------------- <html> <head> <title>Agent Analysis</title> <script language="javascript"> function getSelectValue(selectID) { var optionObj = document.getElementById(selectID); return optionObj.options[optionObj.selectedIndex].value; } function reload(form) { //Adding the unselected options should work fine var locationURL = 'shift_form_schedule3.php'; locationURL += '?shift=' + getSelectValue('shift'); // locationURL += '&secondary_category=' + getSelectValue('secondary_category'); // locationURL += '&tertiary_category=' + getSelectValue('tertiary_category'); //Perform the reload self.location = locationURL; } </script> </head> <body marginheight="0" topmargin="0" marginwidth="0" leftmargin="0" style="margin:0;padding:0" bgcolor="#B0E0E6"> <div id="container"> <div id="content" style="margin-top:-45px;"> <img src="images/logo.png" alt="none"></img> <h1>Auxilium</h1> <!-- <h2>Sliding login panel with jQuery - Demo</h2> --> <div id="stylized" class="form"> <form id="form" name="form" method="post" action="process/submit_agent_analysis.php"> <h1>Agent Analysis</h1> <label>User Logged In : <span class="small">You are logged in as</span> </label> <input type="text" name="username" id="username" value="<?php echo htmlentities($_SESSION['username']);?>" readonly style="background-color: #C9C9C9"> <!-- DISPLAY THE DETAILS OF THE LOGGED IN USER <label>Form Reference Number : <span class="small">Number Reference to link queries</span> </label>--> <input type="hidden" name="voc_reference" id="voc_reference" value="<?php echo $random;?>" readonly style="background-color: #C9C9C9"> <label>Shift : <span class="small">Shift that is being updated</span> </label> <select name='shift' id='shift' onChange="reload(this.form)"> <option value=''>--- Select a Shift ---</option> <?php echo $shift_options; ?> </select> <?php $irow=0; while($row = $result->fetch_assoc()) { if($row['agent']==1) $checked=" checked='checked'"; else $checked=''; if($row['agent']==1) $checked2=" checked='checked'"; else $checked2=''; if($row['agent']==1) $checked3=" checked='checked'"; else $checked3=''; if($row['agent']==1) $checked4=" checked='checked'"; else $checked4=''; echo "<table><tr>"; echo "<td><label>".$row['agent'].":"; echo "<span class='small'>Agent's attendance status</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='1'".$checked."/>" ; echo "<span class='radiobutton'>Present</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='2'".$checked2."/>" ; echo "<span class='radiobutton'>Late</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='3'".$checked3."/>" ; echo "<span class='radiobutton'>Absent</span>"; echo "</td>"; echo "<td><input type='radio' name='".$row['agent']."[]' value='4'".$checked4."/>" ; echo "<span class='radiobutton'>AWOL</span>"; echo "</label></td>"; echo "</tr>"; $irow++; } echo "</tr></table>"; ?> </form> </body> </html> perhaps start with this, and work on getting each part of the business logic to do what you want, then get each corresponding part of the presentation logic to do what you want. -
the error is because you have closed the mysqli connection at the end of your config.php file.
-
Radio Buttons From MySQL & Drop-Down Menu
mac_gyver replied to SalientAnimal's topic in PHP Coding Help
some suggestions - 1) please, when you get an error or some other symptom in front of you when you run your code, share that information by telling us what it actually was that you saw and need help with. you have three queries and dozens of php variables. we don't have a clue what you saw in front of you that would even point to the correct section of code to look at, especially since you are not just posting the relevant section of code. 2) the organization of your code needs some help, which is also related to just posting the relevant section of code. you have your php 'business' logic mixed in with javascript and html, along with php function definitions. you are including a 'functions.php' file. why aren't the two function definitions that are scattered around in the posted code contained in the function.php file? you need to separate the code that determines what to do on the page and is responsible for getting the correct data at the correct time (i.e. the 'business logic') from the code producing/including the actual html document (i.e. the 'presentation logic'). you should be able to draw a line in your code, above which is a majority of the php code, containing no html/javascript/css markup, and below which contains your <doctype> tag and all the html/javascript/css markup, with the only php code being that which is needed to output the content that the business logic determined and got the data for. by having this separation, you can concentrate on the correct section of code (and post just the relevant section in a help forum.) -
the query error is probably because your $_SESSION['username'] value is a string and it isn't enclosed by single-quotes. some tips - 1) you should build your sql query statement in a php variable so that you can echo it to see what it actually is. 2) your form processing code needs to test if the form was submitted so that it only runs when there's some form data to use. 3) you need to validate external data before using it. 4) you need to escape string data before putting it into a query statement or you need to use prepared queries. 5) the mysql_ database functions are depreciated and will be removed from php in the future. you should be learning either mysqli or PDO functions. see this link - http://us2.php.net/manual/en/mysqlinfo.api.choosing.php