-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
Conditional statements in middle of string concatenation
mac_gyver replied to JamesKoash's topic in PHP Coding Help
use the following, with the () around it, so that it is treated as an expression and it won't try to use parts of the concatenated strings - (isset($nameerror) ? $nameerror : "") -
Need Help Controlling Output from Query and Sub-Query
mac_gyver replied to spock9458's topic in PHP Coding Help
as a continuation of the above reply, since you will be using the code that produces the correctly formatted output in two different places, inside the loop and a final time after the end of the loop, you should probably make it a function. once you have this function, you will notice how similar it is to your main block of code and it would only take a little work to convert it into a recursive function and use it in place of the main block of code. -
Need Help Controlling Output from Query and Sub-Query
mac_gyver replied to spock9458's topic in PHP Coding Help
your pseudo logic would need to be - $lastCompany = ''; while($row = mysql_fetch_array( $result )) { if ($lastCompany != $row['company_id']) { // the company changed, is there a previous company section to close if($lastCompany != ''){ // close out the previous company section here... // your code to output branch infomration for the previous company, in $lastCompany, would go here... } $lastCompany = $row['company_id']; # Track the "last" company we processed // start a new company section here... } // output the data under each company section here... } // close out any previous/last company section here... i cannot think a a good (clear, straightforward code) way of just joining all the tables in one query, so i would recommend, to avoid running any queries inside of loops, that you pre-proecess the data from the first query (storing it into an array, using the company_id as the main array key.) you can then get all the company_id's out of that array and run one query to get all the branch information at one time. pre-process this branch information and store it into another array using the company_id as the main array key.) in the pseudo code, the while(){} loop would become a foreach(){} loop over the first pre-processed array of data - foreach($company_array as $row) { at the point of needed to loop over the branch information, you would take the correct company_id and use it to test if there is any branch information in the second pre-processed array and then to access and loop over that branch information. -
How do you access to a variable in a class from another class?
mac_gyver replied to JongMin's topic in PHP Coding Help
something like a user ID (or an instance of a user class) wouldn't be "I need to hold a value globally". it would be an input value that you pass into a class/class-method as a call time parameter. what happens when an administrator needs to manage a list of other user ID's or one user is viewing the profile information of another user? the user id that any code operates on, could come from a session variable, a form/url submission, the result of another function/method, ... your classes/class-methods need to be general purpose enough so that the input data values they use are determined at call time, not hard-coded into them. something like a DB object, that provides the method(s) needed to interfacing to the underlying data layer, that classes are dependent on to function, should be passed into the class, again as a call time parameter, either in the constructor or in a specific setter method, for the same reason as given above (general purpose code that operates on different input data/data layer based on how you use/call it, not not what's hard-coded into it.) -
$this->_inindus is empty resulting in the syntax - and GROUP BY also, GROUP BY some_term performs an ORDER BY some_term (the query needs to get the same rows being grouped, adjacent to each other before it can consolidate them.). so, you don't need ORDER BY unless you want a different order than what the GROUP BY resulted in.
-
you also already have a current thread for this, don't start another thread for the same problem.
-
one way to do this is to run the script on a development system and see what database related errors there are, this of course assumes your database logic is testing for errors and reporting/logging them. references in the php code to the columns would produce php undefined variable/undefined array index errors. if your code isn't testing for query errors, you could write your own database query function that does do this and simply do a global search/replace for what ever query function you are currently using and rename it to call the function you wrote. your script shouldn't have a lot of different points where queries are being performed at. if you do, it might be time to simplify the code. BTW - if you are using the mysql_ functions and are going through your code anyway, it might be a good time to update to the mysqli_ or PDO database libraries as the mysql_ functions are depreciated as of php5.5.
-
the current code doesn't have the debugging logic in it that has been suggested (and in the case of adding $conDB to the mysql_error($conDB) statements, this is a requirement to insure that the error being displayed is for the query that was just ran on that connection.) why did you take the debugging logic out, you are not finished debugging the problems in the code. here's some more suggestions - 1. make sure php's error_reporting/display_errors are set as suggested and actually working. 2. remove ALL the @ error suppressors in the code. all they are doing is hiding the problems that would provide an answer to 'why did this code work on the previous host and not on the current one?' i even noticed some @'s in code where there will never be an error.
- 29 replies
-
- sql injection
- mysql server version
-
(and 1 more)
Tagged with:
-
the time you got the 'query was empty' error is the only thing i believe in this thread. that the error message changed back to the original, indicates your code where the error is occurring at isn't what you have been posting (it's likely that one of the other queries is failing now and reporting a previous mysql_error because another mysql_error() statement doesn't have the $conDB in it.) post the complete current code for the page, showing the <?php ?> tags it it as well (less any database credentials). there's something going on in your code on that page and to save time just post the whole thing. the reason your code worked on one server and not another is because your code is dependent on some server specific setting or feature. it's also dreamweaver produced code and the DW code is crappy. one of the reasons the error reporting setting didn't work is the E_ALL defined constant doesn't exist in the .htaccess file. you need to use php_value error_reporting -1
- 29 replies
-
- sql injection
- mysql server version
-
(and 1 more)
Tagged with:
-
there's really no way that the posted code would not display something for $updateSQL in the error output. are you 100% sure the posted code is what is actually running on the server? also, since the mysql_query() statements, in question, are using the $conDB connection variable, you must use that in the mysql_error() statements to insure that the error message corresponds to the last query that was executed on that connection. i'm thinking the mysql_error message you are seeing is left over from some login code or similar that is using a different connection. i would also recommend that you set php's error_reporting to E_ALL and display_errors to ON to get php to help you by reporting and displaying all the errors it detects.
- 29 replies
-
- sql injection
- mysql server version
-
(and 1 more)
Tagged with:
-
rather than just dumping the errors on a forum somewhere, how about reading them and trying to solve this yourself? one of the error messages gives a HUGE HINT - Please verify that the current setting of session.save_path is correct (/var/php_sessions)
-
remove your existing error_reporting() statements and add the following two lines, immediately after the <?php tag, before the session_start() statements to see any php detected errors - ini_set("display_errors", "1"); error_reporting(-1);
-
the unexpected t_sl is referring to a shift left operator <<. somehow the <<< is being seen as unexpected. post about 5 lines leading up to what you posted above, there's probably something missing, like a quote or a ;
-
assuming you are using the mysqli database library, the following should (untested) be equivalent to what you posted above - $query = "INSERT IGNORE INTO $table_projects (project_name,author,status,timestamp) VALUES('$project_name','".USER_EMAIL."','active','$ts')"; if($db_connect->query($query)){ // INSERT IGNORE ... query ran without any errors, check number of affected rows if($db_connect->affected_rows == 0){ // not inserted header('Location: ../project_new.php?msg_raw=pna'); } else { // row was inserted $project_id = $db_connect->insert_id; // if users were added if(!empty($u_emails)){ // split textarea into separate email addresses $array_u_emails = explode("\n", $u_emails); $values = array(); foreach( $array_u_emails as $address ){ $address = trim($address); $values[] = "($project_id,'$address')"; } $query = "INSERT INTO $table_project_members (project_id,user_email) VALUES " . implode(',',$values); $db_connect->query($query); // execute the query } // unset NEW PROJECT SESSION vars unset( $_SESSION['np_project_name'] ); unset( $_SESSION['np_u_emails'] ); header( 'Location: ../thankyou.php?status=np&&arg=' . $project_name ); } } else { error( 30001 ); // an actual query error }
-
edit: basically says the same as trq's post above (why wasn't that there when i viewed the thread?) You would use a tag in the content, like a custom bbcode tag, that when the output is processed and sent to the browser, the tag would be replaced with the actual content. only the tag would be stored in the database. the actual php code that does the work would be part of your application code.
-
provided the project_name column is a unique key (it should be anyway), the first SELECT query is not needed. you can just attempt to run the INSERT query and it won't insert if the project_name is already in use. depending on the mode your database server is set to, you will either get a duplicate key error (you can test for the specific error number that would be returned for a duplicate key) or you will get a warning (some of the database libraries have a function/method to get the last warning that was returned.) you can also use the IGNORE keyword in the INSERT query, then after you test if the query ran without any errors, you can test if the affected rows value is a one (inserted the row) or zero (did not insert the row.) after the INSERT query, you don't need a separate SELECT query to get the last insert id. just about all database libraries have a function/method to get the last inserted id as this information is automatically returned to the client and simply must be accessed. your final insert query in the loop for the email records can and should be replaced by a single multi-value insert query.
-
all the echoing of test strings was preventing the headers from working (after the original problems were corrected.) if you had php's error_reporting/display_errors turned full on, you would have known this hours ago.
-
the <img tag doesn't work because the src=' ... ' attribute must be the actual url of the file so that the browser can fetch the file. the files are not stored using the id as their name. the id is the upload_id value in the database table that corresponds to the actual filename.ext the file is stored as. the <img tag syntax is also missing quotes in the html around the src=' ... ' attribute.
-
kids, seriously, it's the readfile() statement that is reading and outputting the gibberish/actual file contents. the only thing that is being output by the var_dump() statement is the int(108).
-
why did you put the ini_set("display_errors", "1"); statement, that would have turned on the display of php errors, after the point where you are running the php code in question?
-
microsoft's notepad isn't a programming editor. notepad++ is this - http://notepad-plus-plus.org/
-
How to resolve problem of session_start on Linux
mac_gyver replied to Vidyadhar's topic in PHP Coding Help
if you post the important part of the error message (the line number where the output is occurring at), it will help someone to help you with what is causing the problem. -
if your programming editor doesn't display line numbers, use something like notepad++ the following is a lesson in data driven design. as far as i can tell, this is what you code is trying to do (untested) - // define the data needed by the code for each output file/data type $data['topas.txt'] = array('type'=>'field','n'=>0,'value'=>3); // field [0] > 3 $data['topex.txt'] = array('type'=>'field','n'=>3,'value'=>1); // field [3] > 1 $data['topgy.txt'] = array('type'=>'field','n'=>5,'value'=>10); // field [5] > 10 $data['toppa.txt'] = array('type'=>'field','n'=>6,'value'=>1); // field [6] > 1 $data['topext.txt'] = array('type'=>'miners','n'=>15,'value'=>1); // field [15] in miners/$nyy.txt > 1 $data['topje.txt'] = array('type'=>'miners','n'=>16,'value'=>1); // field [16] in miners/$nyy.txt > 1 $data['toppin.txt'] = array('type'=>'field','n'=>7,'value'=>1); // field [7] > 1 $data['topkov.txt'] = array('type'=>'field','n'=>8,'value'=>1); // field [8] > 1 $data['topkrd.txt'] = array('type'=>'kreditai','value'=>1); // contents in kreditai/$nyy.txt > 1 $link="users/"; $dira=glob($link."*") or die('error'); // clear all output/data files foreach($data as $file=>$not_used){ file_put_contents($file,''); // clear file } foreach($dira as $user_file){ // loop over each user file $bkl = file_get_contents($user_file); $hj = explode("|",$bkl); // loop over each output file/data type foreach($data as $file=>$arr){ $nyy = $hj[2]; $stt = $hj[16]; switch($arr['type']){ case 'field'; $lygg = $hj[$arr['n']]; break; case 'miners': $bkll = file_get_contents("miners/$nyy.txt"); $hjj = explode("|",$bkll); $lygg = $hjj[$arr['n']]; break; case 'kreditai': $lygg = file_get_contents("kreditai/$nyy.txt"); break; } if($lygg > $arr['value']){ if ($stt == "Narys"){$vrdll = "$nyy";} if ($stt == "Adminas"){$vrdll = "@$nyy";} if ($stt == "Moderatorius"){$vrdll = "*$nyy";} file_put_contents($file,"$lygg|$vrdll|\n",FILE_APPEND); } } }
-
PHP Session problem only on one page throughout the website
mac_gyver replied to thedevilinu's topic in PHP Coding Help
we cannot really help you without the code that reproduces the problem, to pin down the many different possibilities to just the one that is actually causing the problem. by seeing what your code is doing (redirecting, including, setting/testing variables/cookies, trying - successful or not - to remove cookies), lets us know which direction to look. best guess is you actually have two different sessions, due to different host-names (www. vs no-www.) in the URL's and the session cookie domain setting is only matching the host-name where the session was created and you are visiting the signup page using a different host-name from where the session was destroyed at and you are seeing the second session data. second best guess, you are passing the session id in the url (intentionally/unintentionally) and resuming the session (are you also destroying the session data file?) -
How to resolve problem of session_start on Linux
mac_gyver replied to Vidyadhar's topic in PHP Coding Help
on your windows development system, go into your php.ini and turn output_buffering OFF so that the code you develop will work without relying on one of php's non-portable short-cuts.