Psycho
Moderators-
Posts
12,157 -
Joined
-
Last visited
-
Days Won
129
Everything posted by Psycho
-
I wouldn't hard code things such as conditions for checking a counter. Much better to make the code flexible enough so you can change the maximum columns by changing one parameter. This is also a perfect situation to use the modulus operator. <?php $max_columns = 3; $result = mysql_query($sql); $column=0; while($row = mysql_fetch_assoc($result)) { $column++; //First record in a row if($column%$max_columns==1) { echo "<tr>\n"; } echo "<td><center><img src=\"{$row['thumbpath']}\" height=\"100\" width=\"125\" hspace=\"10\" style=\"border: 1px solid #fff;\"></center></td>\n"; echo "<td>{$row['name']}<br>{$row['username']}</td>\n"; //Last record in a row if($column%$max_columns==0) { echo "</tr>\n"; } } //Close the last row if needed if($column%$max_columns!=0) { while($column%$max_columns!=0) { echo "<td></td>\n"; $column++; } echo "</tr>\n"; } ?>
-
OK, I see the problem. You have two WHERE clauses in your query, but only one of those search values is being set. $apprID = mysql_real_escape_string($_GET['id']); $query = "SELECT Appr_Value.ApprID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' AND Appr_Value.ApprID = '{$apprID}' ORDER BY Appr_Value.Account ASC"; WHERE is $seach being defined? Also, I mode one error in logic in the above code. Change this if (!$result) { $error = "<span style=\"color:#ff0000;\">No results found</span>"; } To this: if (mysql_num_rows($result)==0) { $error = "<span style=\"color:#ff0000;\">No results found</span>"; } That would have at least ensured you would have gotten the correct error message.
-
OK, I was trying to write anything specific for the code you had because, quite honestly, I knew I would have to rewrite the whole thing just to understand what went where. But, if it helps you, then it's worth it. I only see a few values being selected in your query. I suspect you need to get more results. Anyway, I left it up to you to define all the values to populate the page. I also rewrote the entire layout of the page using CSS which greatly cleaned it up. Although I would probably have gone further in removing all the redundant DIV's <?php $dbHost = '***'; $dbUser = '***'; $dbPass = '***'; $dbDatabase = '***'; $con = mysql_connect($dbHost, $dbUser, $dbPass) or die("Failed to connect to MySQL Server. Error: " . mysql_error()); mysql_select_db($dbDatabase) or die("Failed to connect to database {$dbDatabase}. Error: " . mysql_error()); $apprID = mysql_real_escape_string($_GET['id']); $query = "SELECT Appr_Value.ApprID as id, Appr_Value.Account, Asmnt_Parcel.OwnersName, Asmnt_Situs.Situs FROM Appr_Value INNER JOIN Asmnt_Parcel ON Appr_Value.Account=Asmnt_Parcel.Account INNER JOIN Asmnt_Situs ON Appr_Value.Account=Asmnt_Situs.Account WHERE Appr_Value.Account LIKE '{$search}' AND Appr_Value.ApprID = '{$apprID}' ORDER BY Appr_Value.Account ASC"; $result = mysql_query($query, $con) or die(mysql_error().": $query"); $error = ''; if (!$result) { $error = "<span style=\"color:#ff0000;\">No results found</span>"; } else { $r = mysql_fetch_assoc($result); $account = htmlentities($r['Account']); $nameID = htmlentities($r['OwnersName']); $address = htmlentities($r['']); $situs = htmlentities($r['']); $instrNo = htmlentities($r['']); $grantor = htmlentities($r['']); $saleDate = htmlentities($r['']); $salePrice = htmlentities($r['']); $description = htmlentities($r['']); $exempType = htmlentities($r['']); $exemption = htmlentities($r['']); $code = htmlentities($r['']); $landValue = htmlentities($r['']); $improvements = htmlentities($r['']); $mobileHome = htmlentities($r['']); $totalValue = htmlentities($r['']); $assessedValue = htmlentities($r['']); $taxableValue = htmlentities($r['']); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <meta name="generator" content="Adobe GoLive" /> <title>Search Results</title> <style> body { background-color: #bba86d; } .title { font-family: Georgia, Times New Roman, Times, serif; font-size: 16pt; font-weight: bold; color: #003300; text-align: center; } .tableBlock { border: 2px solid #cecece; } .tableBlock td { /* put styles that apply to both labels and values here */ font-family: Georgia, Times New Roman, Times, serif; font-size: 10pt; color: #352200; text-align: left; } .label { /* put styles specific classes here */ font-weight: bold; white-space: nowrap; padding: 8px 5px 8px 5px; } .value { /* put styles specific classes here */ padding: 8px 5px 8px 5px; color: red; width: 100%; } </style> </head> <body> <div align="center"> <div style="position:relative;width:871px;height:912px;-adbe-g:p;"> <div style="position:absolute;top:0px;left:111px;width:648px;height:350px;"> <img src="toplogo3.jpg" alt="" height="350" width="648" border="0" /> </div> <div style="position:absolute;top:350px;left:34px;width:800px;height:33px;"> <table width="800" border="1" cellspacing="2" cellpadding="0"> <tr><td class="title">Wagoner County Public Records Search Results:</td></tr> </table> </div> <?php echo $error; ?> <div style="position:absolute;top:384px;left:2px;width:434px;height:138px;"> <table class="tableBlock" width="430"> <tr><td class="label">Account:</td><td class="value"><?php echo $account; ?></td></tr> <tr><td class="label">Name ID:</td><td class="value"><?php echo $nameID; ?></td></tr> <tr><td class="label">Address:</td><td class="value"><?php echo $address; ?></td></tr> <tr><td class="label">Situs:</td><td class="value"><?php echo $situs; ?></td></tr> </table> </div> <div style="position:absolute;top:384px;left:436px;width:434px;height:122px;"> <table class="tableBlock" width="430"> <tr><td class="label">Instrument Number:</td><td class="value"><?php echo $instrNo; ?></td></tr> <tr><td class="label">Grantor:</td><td class="value"><?php echo $grantor; ?></td></tr> <tr><td class="label">Sale Date:</td><td class="value"><?php echo $saleDate; ?></td></tr> <tr><td class="label">Sale Price:</td><td class="value"><?php echo $salePrice; ?></td></tr> </table> </div> <div style="position:absolute;top:544px;left:2px;width:434px;height:69px;"> <table class="tableBlock" width="430"> <tr><td class="label">Legal Description:</td><td class="value"><?php echo $description; ?></td></tr> </table> </div> <div style="position:absolute;top:544px;left:436px;width:434px;height:94px;"> <table class="tableBlock" width="430"> <tr><td class="label">Exemption Type:</td><td class="value"><?php echo $exempType; ?></td></tr> <tr><td class="label">Exemption:</td><td class="value"><?php echo $exemption; ?></td></tr> <tr><td class="label">Code:</td><td class="value"><?php echo $code; ?></td></tr> </table> </div> <div style="position:absolute;top:656px;left:1px;width:209px;height:77px;"> <table class="tableBlock" width="207"> <tr><td class="label">Land Value:</td><td class="value"><?php echo $landValue; ?></td></tr> </table> </div> <div style="position:absolute;top:656px;left:227px;width:209px;height:77px;"> <table class="tableBlock" width="207"> <tr><td class="label">Improvements:</td><td class="value"><?php echo $improvements; ?></td></tr> </table> </div> <div style="position:absolute;top:656px;left:437px;width:209px;height:77px;"> <table class="tableBlock" width="207"> <tr><td class="label">Mobile Home:</td><td class="value"><?php echo $mobileHome; ?></td></tr> </table> </div> <div style="position:absolute;top:656px;left:659px;width:209px;height:69px;"> <table class="tableBlock" width="207"> <tr><td class="label">Total Value:</td><td class="value"><?php echo $totalValue; ?></td></tr> </table> </div> <div style="position:absolute;top:752px;left:128px;width:306px;height:69px;"> <table class="tableBlock" width="306"> <tr><td class="label">Assessed Value:</td><td class="value"><?php echo $assessedValue; ?></td></tr> </table> </div> <div style="position:absolute;top:752px;left:436px;width:306px;height:69px;"> <table class="tableBlock" width="306"> <tr><td class="label">Total Taxable:</td><td class="value"><?php echo $taxableValue; ?></td></tr> </table> </div> </div> </div> </body> </html>
-
Here's a related tip. Do the easy validations first. For example, in this case, check if the new password and confirm password match. If not, then there is no need to do a database query to retrieve the current password for comparison. A database query will be much more taxing on the servers than a simple string comparison.
-
How to add a style onto this array without having to repeat
Psycho replied to TeddyKiller's topic in PHP Coding Help
Just modify your function to accept a style parameter and apply that parameter to the output. function profile_details($id, $profile, $style) { $user = user_get_details($id); $detail = array("Username", "Date of Birth", "Age", "Full Name", "Marital Status", "Interested In", "Looking for", "Orientation", "School", "College", "University"); $fields = array(); $fields[] = "<tr><td style=\"{$style}\">{$detail[0]}</td><td>" . ucwords($user["username"]) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[1]}</td><td>{$user["dob"]}</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[2]}</td><td>" . getAge($user["dob"]) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[3]}</td><td>" . ucwords($user["name"]) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[4]}</td><td>" . ucwords($profile->rel_status) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[5]}</td><td>" . ucwords($profile->interested_in) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[6]}</td><td>" . ucwords($profile->looking_for) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[7]}</td><td>" . ucwords($profile->orien_status) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[8]}</td><td>" . ucwords($profile->school) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[9]}</td><td>" . ucwords($profile->college) . "</td></tr>"; $fields[] = "<tr><td style=\"{$style}\">{$detail[10]}</td><td>" . ucwords($profile->university) . "</td></tr>"; $fieldList = implode("\n", $fields); $output = "<fieldset><legend style=\"font-weight:bold;\">Basic Information</legend>\n"; $output = "<table id=\"details\" width="60%">{$fieldList}</table>\n"; $output = "</fieldset>\n"; return $output; } -
How to add a style onto this array without having to repeat
Psycho replied to TeddyKiller's topic in PHP Coding Help
Are the spans stlye properties always going to be the same? If so, then the spans should be in the HTML templates (i.e. Option #2). However, if they will be different for different records, then simply create a function to format the arrays: function addSpans($array, $style) { foreach($array as $key => $value) { $array[$key] = "<span style=\"{$style}\">{$value}</span>"; } return $array; } $formattedArray = addSpans($originalArray, $style); -
I suspect you will need to take a two phased approach. imagestring() simply writes text to an image, so it will always write it at the correct orientation. Here is what I would do. 1. Create the master image. Let's say you want the captcha letters to be 20 x 20 pixels. Then this image would be 120 wide and 20 high. 2. Create a single image for each letter that is 20 x 20. Then randomly rotate the image. They should maintain their 20x20 dimensions. 3. Place each image for each letter into the master image.
-
http://www.phpfreaks.com/forums/index.php/topic,293768.0.html
-
That ^^ code (EDIT: newbtophp''s code)would add a comma to the very beginning if the first checkbox is not checked. A better approach is to use an array with implode. However, the "quick" fix and the "right" fix are two different things. The right fix would be to change the names of the checkboxes to "salespersons[]" instead of naming them "salesperson1", "salesperson2", etc. By giving them the same name, they will be treated as an array and you could do this: if (isset($_POST['salesperson1'])) { $EmailTo = implode(',', $_POST['salespersons']); } With your current code you could do this: $emails = array(); if(isset($_POST['salesperson1'])) { $emails[] = $_POST['salesperson1']; } if(isset($_POST['salesperson2'])) { $emails[] = $_POST['salesperson2']; } if(isset($_POST['salesperson3'])) { $emails[] = $_POST['salesperson3']; } $emailTo = implode(',', $emails);
-
My point was that by using mysql_real_escape_string() and then using md5() on a value was creating tainted data, i.e. the value being stored was not the hashed value of what the user entered. And I agree that there is a lot the OP would need to change to , in fact, get to a data independant solution, but this one problem was at least a good example of something not to do.
-
All valid points only in the context of the application he currently has, which cannot support thse things. The fact remains that by using mysql_real_escape_string() and THEN using MD5(), the hashed value in the database is NOT the hashed value of what the user entered. I was only providing some useful info for future use. As for your other critiques... One thing I always try to profess is that you should always separate your logic from the presentation. By doing that, it is a simple matter to create a web application that is database independant. There are plenty of database classes that allow you to run the same PHP application off of any number of databases. As for creating a separate app to use the same data, yes, that app would needd a simialr function to guard against SQL injection and many languages already have that functionality, so I'm not sure what your point is. If anything it only supports my point. mysql_real_escape_string() ensures that the data saved in the database is exactly the data entered. The escaping of certain characters will ensure that the original character is what is saved. It just so happens that the function provides dual duty in also protecting against SQL injection. It may be that another application needs to escape characters differently but will end with the same result in the database. That is why there is no needor even a reason to, escape text that will be hashed. The MD5() algorithm is application independant. If you don't believe me, just do a google seach for data independence" or "database independence" and you will find numerous resources on the subject.
-
FYI: No need to use mysql_real_escape_string() on values that you will use MD5() on. In fact it is probably a bad idea. If the user enters characters that mysql_real_escape_string() modifies then the MD5 value will be of that modifed string, not the user's password. Probably doesn't make a big difference in most situations. But, by doing that your data is now dependant on php & mysql. Data should be language and environment independant. If you ever wanted to change to a different database application or if you wanted to create an application in a different language that uses the same data, you would have to create a function that mimics mysql_real_escape_string().
-
Wouldn't you have to loop through the results to put them into an array?
-
I copied your form above and put it into a test page and the post values were submitted correctly. The problem must be elsewhere. [Edit, just read your last post] Perhaps there is some modification of the POST data or the assigned variables on the processing page. Can you post that code? Although I do notice that in your first post you are stating you are getting the POSY value for 'machineid', whereas your form is using the names 'atmid[]'.
-
Oh, sorry, I didn't see you had mysql_query() inside the mysql_num_rows() function. It's better to split up the steps to make debugging easier. I'll add an "or die()" so you can see the error, but it's best to not leave that in when you go to production. //Create the query $query = "SELECT * FROM members_videos WHERE Email = '$email' "; $result = mysql_query($query) or die ("Query:<br>$query<br>Error:<br>".mysql_error()); $results = mysql_num_rows($result);
-
Try "running" the query!
-
Yes, but in this case it is inefficient $colors = array('red', 'blue', 'yellow'); if (in_array(strtolower($wpic), $colors)) { $require_file = strtolower($wpic) . '.php'; } else { $require_file = $colors[array_rand($colors)] . '.php'; } require_once($require_file);
-
I took what Ken2k7 posted and fixed it. This is tested: function validTime($time) { return preg_match("/^((0?[0-9])|(1[0-9])|(2[0-3]))(:[0-5][0-9]){2}$/", $time); } To be valid the time must follow the following parameters: The beginning must be one of the following (0-9) (any single digit number) 0(0-9) (0 followed by any single digit number) 1(0-9) (1 followed by any single digit number) 2(0-3) (2 followed by 0, 1, 2 or 3) There must then be a colon followed by (0-5)(0-9) (first digit a 0, 1, 2, 3, 4, or 5, second digit any number) Then another colon followed by (0-5)(0-9) (first digit a 0, 1, 2, 3, 4, or 5, second digit any number) One problem with the above is that it accepts 00:00:00 but not 24:00:00. Some people prefer one over the other. If you need to support 24:00:00, then change the regex to this: /^(((0?[0-9])|(1[0-9])|(2[0-3]))(:[0-5][0-9]){2})|(24:00:00)$/
-
0 = Off, 1 = On A byte is mayde up of 8 bits. Something like 00110101. So, what is that? Each place has a value the same as a base 10 number. Ex. The number 125. The 5 is in the ones place, the 2 is in the 10's place and the 1 is in the hundredths place. Each "place" can have a value of 0 to 9. In binary each place can have a value of 0 or 1. The amount of each place (i.e. column) is different than base 10. In binary it works like this: 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 So, the binary number 00110110 has the bits "turned on" for 32, 16, 4, & 2. So, the equivalent base 10 number is 54. 00111000 would be 32 + 16 + 8 = 56.
-
Again, using ocals and words with respect to bitwise operators will be confusing if it is not in the context of a real-world example. Stick with binary and base 10 numbers and it will be easier to understand. If you have a need to work with text and/or octals with respect to bitwise operators you will have the understanding to apply them. Ok, here is an example to explain a possible use for the ampersand '&' operator. This operator will return the bits that are set in both values. So, expanding upon the previous example, let's say in addition to the user's group permissions for general activity there could also exist permissions to specific records. So, in addition to having the general permission to delete staff, those staff can be put into security groups so only certain users can delete them. In that case you could use the & operator against the user's general permission and against the staff record specific permissions to ensure that the user has permissions to delete staf AND that the user has permissions to delete the specific staff. 0101 & 0110 = 0100 The carat '^' returns the bits where a bit is turned on in one value but not the other. I can't think of an example right now. But, basically it would be like this: 0110 ^ 0101 = 0011 Here is a tutorial that looks pretty good: http://www.litfuel.net/tutorials/bitwise.htm
-
Not sure what you are expecting in a forum post. Not really the appropriate medium for an exposition on bitwise operators. However, I think the use of 'text' in the examples is confusing. I can't think of any useful implementation of bitwise operators with text. Most of the uses I have seen with bitwise operators are for storing/mainpulating multiple boolean values. That's not to say there aren't other valid uses, but sticking with numbers will make more sense I think. Here is one example: Let's say you have an application where users' permissions are set according to the group(s) they are assigned to. The permissions could be stored in a bitwise operator where each bit is a true/false for a specific permission. Permissions: CreateUser | DeleteUser | CreateProduct | DeleteProduce So a user with the value 1010 (or 10 in binary) would have permissions to Create Users and Create Products, but would not be able to delete either. But, let's say users can be in multiple groups. How do you determine their permissions across all groups? Eaasy, just use the "|" (pipe). As you state above So, if you use that operator on two values, you will get the combined permissions. So, if a user is in two groups with the permission values of 1010 and 1100, their combined permission value (using |) will be 1110
-
I took your code and only used the form. I also removed the "readonly" attribute for the fields. The script worked fine. I entered data into all the fields and validation passed. I then selectively removed values from individual fields and found that validation failed no matter what field was empty regardless of round or bracket.
-
The problem is in the field names as I expected. After reviewing the table in some of the code above you have fields 1_1, 1_2, 1_3, 1_4 then it jumps to 1_17, 1_18, 1_19 & 1_20. That is not the format you stated previously. Where are fields 1_5 to 1_16?
-
No, that would not be the problem. Neither of the solutions provided above check the fields in the physical order displayed. Just "attach" the file. Click the "Preview" button below to get the expanded form to post a message and you will have the option to attach a file.
-
Did you look at the last code I posted? Do the field names match the format and sequence of field names that you are using? That code works. Like I said, if you have an error in one of your field names the script would exit prematurely. I think you need to attach your complete page.