-
Posts
16,734 -
Joined
-
Last visited
-
Days Won
9
Everything posted by PFMaBiSmAd
-
Did you stop and start your web server to get any changes made to the master php.ini to take effect? Did you use a phpinfo statement in a .php script to confirm that the mysql extension got loaded? Are you sure that is the php.ini that php is using?
-
A) There's a section in the php.net manual about magic quotes. B) If you happen to be on a server where you don't have the ability to disable magic_quotes_gpc (you should be able to do this in a local php.ini when php is running as a cgi application or a htaccess file when php is running as an apache module), you would need to add logic to your script to test if magic_quotes_gpc is on and use stripslashes on the incoming data before you use mysql_real_escape_string on the data. C) You didn't actually state if the \ characters are stored in your database table (they should not be.) If they are not stored in the table, but you get them when you retrieve the data, that means that magic_quotes_runtime is ON, which you can and should turn off in your script. D) The problem of the content not displaying after the ' when you output it in a form field is most likely because you don't have any quotes in your HTML markup surrounding the value= '...' attribute.
-
You need to enable php's mysql extension in your php configuration (php.ini) How you do this depends on how you obtained and installed php. ?
-
Here's a post about this very subject - pagination, building content in variables, and outputting the content in a html document at the end of the code, after all the 'business' logic - http://forums.phpfreaks.com/topic/270523-can-you-echo-a-var-that-is-defined-later-on-in-the-script/#entry1391569
-
Your code is missing a closing ?> tag on the line right before the line with the error on it, making the inline-html inside of some php code and throwing a php syntax error. That style of coding, in addition to being hard to read, makes it difficult to troubleshoot simple errors, doesn't it?
-
What have you tried? One of the important points about programming is you can try something and immediately observe the result right in front of you, to confirm or disprove that your idea on how to do something was correct or not. If you haven't actually made an attempt, so that you are posting a question about a symptom or error you got (and the code/query that produced that symptom/error), you should probably be posting in the freelancing forum section.
-
When you try to copy/paste together a html document using php include statements, that's the kind of problems you run into.
-
Yes, pagination normally just retrieves the rows you are interested in by using a LIMIT x,y clause in the query. edit: what you are currently doing, I jokingly refer to as rowination. Also, for your existing code, mysql_result is the slowest way of accessing data because each time you call it, it performs a data seek. Your existing code would be better off by performing an explicit data seek to the 1st row you are interested in before the start of your loop, then use a normal mysql_fetch_xxxxxx statement in the loop to fetch an entire row at a time and advance to the next row in the result set.
-
Any bets that you are trying to check if it is empty, but are actually assigning an empty string to it?
-
lol, drop this idea, very punny.
-
^^^ Especially since your user level check code lets the rest of the code on your page run and anyone could drop the table.
-
You likely have more items in your list() statement than what there are columns in your query. Posting the actual error message(s) would help pin down what is occurring.
-
multisort example - <?php // assuming that $data is the name of your array - foreach ($data as $key => $row) { $sort1[$key] = $row['stamp']; } array_multisort($sort1, SORT_DESC, $data);
-
Your first step would be to form the existing query string in a php variable (this is required for the pagination logic to produce the actual query that gets the rows for the requested logical page.) Once you have the query in a php variable, it would be possible for you to then copy this logic to form the query that gets a count of all the matching rows (used to calculate and limit the highest logical page.) Also, you should eliminate the duplication in your existing code (Don't Repeat Yourself - DRY) so that you don't have a wall of code. Here's your code reworked to serve as a starting place (untested) - <?php $user = $login->username; if($user =='admin'){ $where_clause = ''; } else { //not the admin $where_clause = "WHERE aname='$user'"; } $query = "SELECT id, aname, cname, hnumber, address, lamount, status, time FROM db_table $where_clause ORDER BY id DESC"; $result = mysql_query($query); $rowNo = 1; //Increment Row Number while($res = mysql_fetch_array($result)){ $id = $res['id']; $date = $res['time']; $newdate = date("D, j M, Y", $date); if($res['status'] == "Approved"){ echo "<tr align='center' bgcolor='#CDE861'>"; }else{ echo "<tr align='center' bgcolor='#EDA553'>"; } echo"<td><font color='black'>" .$rowNo++."</font></td>"; echo"<td><font color='black'>" .$res['aname']."</font></td>"; echo"<td><font color='black'>" .strtoupper($res['cname'])."</font></td>"; echo"<td><font color='black'>" .$res['hnumber']."</font></td>"; echo"<td><font color='black'>". $res['address']. "</font></td>"; echo"<td><font color='black'>". $res['lamount']. "</font></td>"; echo"<td><font color='black'>". $newdate. "</font></td>"; if($res['status'] == "Approved"){ echo"<td>Approved</td>"; }else{ echo"<td>Pending</td>"; } echo"<td><a href ='view.php?id=$id'><center>Click to View </center></a></td>"; if($user =='admin'){ if($res['status'] !== "Approved"){ echo"<td><a href ='accepted.php?id=$id'>Approve</a>"; }else{ echo"<td><a href ='cancel.php?id=$id'>Cancel</a>"; } echo"<td> <a href ='del.php?id=$id'><center>Delete</center></a>"; } echo "</tr>"; } echo '</tbody> </table>'; ?>
-
There's no easy way to do this in a query because your table design is laid out like a spread-sheet, not as a database table. You should have ONE ROW per data item. Then the problem is simple, just insert a new row if the existing data is not already in the table.
-
You would either use array_multisort (there's an example at that link showing how to extract the values to sort by) or you would use usort and write a custom function that compares that field in the data.
-
I'm going to guess your web host has imposed a maximum post size limit on the sever that is independent of php's settings. Have you checked the web host's FAQ section or asked the web host?
-
Any clue about what? Your first post in the is thread doesn't contain actual code. The last code you posted is incomplete because it doesn't show the code from the point where you are forming the query statement through to where the problem is occurring at. Sorry for posting the Programming Riot Act, but programming is an exact science. Computers only do exactly what their code and data tells them to do. We only see the information you supply in your post. While it might be possible your symptom is due to a bug in php (~.2%), it's more likely (~99.8%) that it is due to something you are doing in your code. The only why anyone here can help determine if it is something in your code is if you post ALL the relevant code the reproduces the problem (so that they can reproduce the problem if need be.) All the relevant code in this case is the query statement through to the end of any loop that is accessing the data from that query statement. Also, for the specific code you post, indicate what symptom or incorrect result you are getting and what the expected result should be.
-
The only attempt you make is to post your assignment on a programming help forum, with a title demanding to be given something, without even asking a question in the post.
-
An empty $_FILES array is generally a symptom of exceeding the max_post_size setting. What does echoing $_SERVER['CONTENT_LENGTH'], on the line right before your if( $_FILES['upload']['error'] > 0 ) statement, show?
-
No, you need to troubleshoot why your code is not working and FIX it. I can tell from the symptom that your login script is not applying any hash method to the entered password to match the hash method it applied in the registration script. And, what code have you tried to get the username to display on a page?
-
Best guess about what the OP wants is to be able to query different tables and display the arbitrary columns from that table by retrieving the actual column names that the query returned, for something like a general purpose sortable data-grid or general purpose crud application. If so, the answer is simple, just use ONE query to get the rows you are interested in, then fetch the field names from that result set, followed by fetching the data in the rows.
-
Escaping the table name being dynamically put into the query doesn't protect against sql injection in it because the table name isn't string data, which is the only thing that mysql_real_escape_string is for, it's an identifier and its not in a place in the query (between single-quotes) where there's anything that it needs to be prevented from escaping from.
-
^^^ That's not how you retrieve data from a prepared query. It would take seeing your actual code that doesn't work to be able to help with what it is doing. I suspect your // some code or // do stuff is overwriting a variable.
-
What method did you originally use to install php? An all in one apache/mysql/php (xAMP) package or the php .msi installer? For an all in one package, you generally must use the control panel for that package to install php extensions. For the php .msi installer, you must use the Windows add/remove control panel to install php extensions.