-
Posts
5,449 -
Joined
-
Days Won
174
Everything posted by mac_gyver
-
you need to tell us what you found when you were troubleshooting the problem. in what file and at what line/statement did you find that the code was not doing what you expected and what exact symptom are you getting and at what point during the process that leads you to believe the process isn't doing what you expect?
-
there two things i can offer - 1) your selected values need to have the same structure to use a UNION (the column heading from the first select is what is used for all the data.) if these tables are dissimilar in structure, it would be best to just query them individually. 2) the placeholder in the query does not use single-quotes around it and any wild-card characters in it must be in the actual value being bound. behind the scenes, when the bound value is put into the query statement at runtime, because it is a string, single-quotes will be added to it. so, your existing usage would result in - AGAINST(''some_string_here'*' ...). removing the single-quotes from inside the query and adding the wild-card to the actual data will result in - AGAINST('some_string_here*' ...) beyond these, was the result from your query what you expected when you tried it?
-
programming requires more than following along with some code in a tutorial you have found. you must actually understand what the code means and how it contributes to the goal you are trying to achieve. in your latest problem, you probably found you had an incorrect column name in the query. it's your responsibility to keep track what's going on in your code/variables/queries. the code that Ch0cu3r has given you, twice in this thread, is called error checking logic. you need to ALWAYS test if a step that can fail due to an error has worked or not before trying to use the result from that step. if you ALWAYS use error checking logic in your code, your code will help you troubleshoot, because your code will tell you if and why it failed.
-
My dropdown date of birth does not insert to db
mac_gyver replied to brincobb's topic in Application Design
nothing you have posted in this thread shows the code where the problem might be. the first post was for your dropdown. the second post shows some very old code for the start of a class. just exactly what sort of help were you expecting to get? -
nothing that was stated in this thread is an advanced programming subject. programming help is not about posting code that you can copy/paste to do what you want. if you don't know enough to even attempt the things that were stated, go take a programming class or just hire someone to do this for you.
-
$database is an instance of your database class. $database is not an instance of the mysqli database class. the instance of your database class only holds an instance of the mysqli database class in the _connection private property. for the affected_rows() method, it must have the actual database connection as part of it. the only place your actual mysqli database instance/connection is at is in the _connection private property in the instance or your database class. the code that runs must eventually result in $this->_connection->affected_rows. to do that, you must provide a method in your database class. your current code of return $result->affected_rows == 1 ? true : false; won't work correctly. $result is either a true or a false for an UPDATE query and that code should be producing a Notice: message about trying to get a property of a non-object. you need to stop using the global keyword to being the instance of your database class it into your other classes. didn't you fix this by brining it into the classes as a call time parameter when you created the instance of your classes?
-
just because you have code elsewhere that is successfully using the value in a variable, doesn't mean that variable contains the expected value on the offending page. you could be overwriting the variable before you get to that page; the session_start() might be failing on that page because of some output that is being sent to the browser; you could be changing the host-name/sub-domain in your url's and the session id cookie no longer matches the variation of your url where it was first created. you need to actually debug what your data is doing. use var_dump($_SESSION['user_level']); right before your conditional logic. the value isn't one that you expect (your code would be doing what you expect if it was) or your value of 1 isn't the one you picked for an admin. also, you need to use ONE header file that contains conditional logic in it to build the desired output. by making two files, you have now doubled the amount of work for yourself when you need to maintain or change your site. do you really want to go through multiple files if you change links or change the layout on your site? a straightforward way of using ONE file is to make a function that returns the user_level when called. next, you need to make defined constants for each level (this will make your code clearer when writing or reading it.) // in a common included file put the following function user_level(){ return isset($_SESSION['user_level']) ? (int)$_SESSION['user_level'] : 0; // default to a zero } define('ADMIN',1); // define a constant to represent the ADMIN user_level // at the point of wanting to produce some admin specific content, use the following - if(user_level() == ADMIN){ // admin specific content goes here.. }
-
what debugging have you done? did you check if the preg_match() statement is returning the expected value? do you have php's error_reporting set to E_ALL and display_errors to ON so that you would know if there are any header() redirect errors? and, you need an exit; statement after your header() redirect to prevent the remainder of your code on the page from running.
-
Slower downloads through Apache than with PHP readfile
mac_gyver replied to pvp's topic in Apache HTTP Server
php's output buffering and/or its use of gzip compression for the output it sends, may be the cause of the symptom.- 5 replies
-
- php
- performance
-
(and 3 more)
Tagged with:
-
PHP Coding help -getting variable name from variable
mac_gyver replied to Ramamoorthy's topic in PHP Coding Help
i've just reviewed your threads and you are making life hard for yourself (i'm pretty sure that programming is not intended to be a painful masochist activity.) you are making a wall of hundreds and perhaps thousands of variables that take a huge amount of time to create in the first place, to change, or to add anything to. this can all be replaced with a few lines of php code, if that code is using a database. in a fraction of the time you have spent trying to get just a small part of your your current scheme to work, you could have learned enough to fully use a database to do this. perhaps an example. your 1234 value is a key/index to your data. // make a database connection/select the database here (using the mysqli database extension) $mysqli = new mysqli(.... connection details here....); $key_value = 1234; // from wherever your input value is coming from now $query = "SELECT * FROM your_table WHERE id = $key_value"; // form the query statement $result = $mysqli->query($query); // run the query // use the query result object in $result any way you want ... // assuming you expect one matching row from the query (no loop needed) - $row = $result->fetch_assoc(); // $row is now an array holding the columns of data you stored in your_table for the key_value 1234. -
you need to set display_errors, in addition to the error_reporting - ini_set("display_errors", "1"); error_reporting(-1);
-
2 Types of Users problem (Problem: Dont have Limitation)
mac_gyver replied to Edmhar's topic in PHP Coding Help
every page must check if the user that is accessing it has the appropriate permission to do so. since you have a type value in your database table, you would test if the type of the current user is an admin or an employee. -
PHP ( 2 types of users - log in problem & Access Forbidden )
mac_gyver replied to Edmhar's topic in PHP Coding Help
you didn't actually state what exact problem you are having with the code. however, DRY (Don't Repeat Yourself). you are repeating the login form and form processing code. that isn't accomplishing anything, except to make more work for you. the purpose of logging in is to authenticate who the visitor is. your database table contains a type column that tells your code what the visitor may access. you would simply retrieve that type value and use it in the comparisons that determine what the visitor may see or do on any page. -
lol, well each of the OP's hacked up the code differently, so technically not the same code though it's the same root problem - copy/pasting code, rather than actually learning and writing the code you want because you know what it does and it does what you want.
-
your query is failing due to a sql syntax error. the fields listed in the SELECT list should not be enclosed in single-quotes. also, your $userid value is an integer, it shouldn't be enclosed by single-quotes in the query. so, two things - 1) you need set php's error_reporting to E_ALL and display_errors to ON in your php.ini (the best place) or in your script, to get php to help you by reporting and displaying all the errors it detects. 2) you need to ALWAYS have error checking logic in your code to test if a step worked or not before trying to use the result you expect from that step, i.e. don't nest functions like mysql_fetch_assoc(mysql_query(" ...")), where the inner function can fail due to an error. putting error checking logic in your code makes your code self troubleshooting, your code will tell you when and why it is failing, no guessing is needed.
-
and since this has nothing to do with PHP Regex, moving to the correct forum section....
-
Port 4430 : failed to open stream: Connection refused
mac_gyver replied to rahulpragma's topic in PHP Coding Help
the only thing that comes to mind is, in order for your web server to make a https request to another web server, php and your web server must both have the openssl extension/module installed/enabled and both must be using the same version of openssl. -
My dropdown date of birth does not insert to db
mac_gyver replied to brincobb's topic in Application Design
ummm. what INSERT statement? what db are you using? what have you done to pin down where your code and data are doing what you expect and where they are not? -
the "inspect element" in the browser is showing the DOM of the page that the browser produced. since the output isn't a complete web page, the browser used a default. that output isn't actually being sent from the server. your file is most likely saved as a utf-8 encoded file with the byte order mark characters (BOM). you need to save your file without the BOM characters.
-
the only way you would be getting the phpinfo() output is if you have a phpinfo() statement in the code on your editTable.php page. if the problem is you don't want the phpinfo() output, remove the phpinfo() statement from your code. you must be aware of what your code in your files contains and what it does. did you bother to scroll down to the end of the output and see the mysql_error information that is being displayed there? you have a query that either has a syntax error in it or contains an empty numerical value. if the extent of your attempt is to run your code, see some output on a page that isn't the result you want, post a link to a page in a help forum, without providing any information, posting a bunch of code that isn't even the code for the page where the problem is at, just what help were you expecting a help forum to be able to give you?
-
all text content (anything that isn't html/javascript/css) should be passed through htmlentities() before being output on a web page, so that any html entities in it are converted to their character equivalents. when these are submitted, they will be converted back to the actual html entities.
-
if just one of your queries is not working, it's because you are using two different table names. one is Student_Name, the other is Student_Names. you need to ALWAYS test if a query worked or failed before you try to use the data that query was expected to return. if your code had some error checking logic in it, you would have already known that the table name in one of the queries is (probably) not correct. your code is all over the place with things that, in the context of the posted code, don't work or are not needed. you have variables defined, but not used; variables used but not defined; global statements that don't do anything unless inside of a function and even there they should not be used; your table name, which ever one is correct, should hold student name information. why do you have date and hour fields in that table?
-
What's the Best Way to Deal with MySQL Errors?
mac_gyver replied to Fluoresce's topic in PHP Coding Help
for those of you posting about using the die(); statement, did you look at the code to see how it is being used? it's after a header() redirect, where you do need to use a die/exit statement because you don't want the remainder of the logic on the page to run. -
you need to check if the row in the database contains exactly the username and the complete matching hash value that you get when you echo the query in $qry. a common problem is your password field in the database table isn't long enough to hold the complete hash value. another possibility is when you initially inserted the row, you ended up with some white-space before/after the value(s).
-
what php version? because microtime(true) only produces values that can be directly subtracted in php5.0 or above.