Jump to content

Psycho

Moderators
  • Posts

    12,157
  • Joined

  • Last visited

  • Days Won

    129

Everything posted by Psycho

  1. My first question would be "What do you consider a valid vs. invalid address"? That is a very significant question. Are you only wanting to verify the FORMAT of the address is valid or are you wanting to know if the address is an ACTUAL physical address? The former requires you to create logic to test for specific patterns and values. The problem here is that it will never be 100% perfect. In fact, with the sheer variability of possible values it will be hard to get anything relatively accurate. That means you will either have to build the logic to be overly strict and have false negatives (incorrectly find valid addresses to be invalid) or build the logic to be too loose and have false positives (find invalid addresses to be valid). But, you will probably fall somewhere in the middle and have both false positives and false negatives. Now, if you mean to do the latter - verify the address is an actual address. Then, you will need to purchase/link to a database of all known valid addresses. You typically have to pay for such things - if they are any good. But, the problem with that is that addresses are always changing. So, the database will never be 100% accurate either.
  2. As I stated previously, you don't provide enough code to see where that problem may be.
  3. You don't show the full query that you are running. Also, is that the ONLY query you are running in this process? Also, this line: $products_name = rtrim(ucwords(strtolower($data_row[8]))) . ' ' . rtrim(ucwords(strtolower($data_row[2]))) . ' ' . $data_row[1]; Can be simplified to $products_name = ucwords(strtolower( rtrim($data_row[8]).' '.rtrim($data_row[2]) )) . $data_row[1]; It could probably be simplified even more, but without seeing the possible input data I can't be sure
  4. Are you using session_start() on both pages? EDIT: You don't show enough code to see that problem. All you have is this elseif($user_answer != $real_answer) { echo "Can't send because the question is wrong."; If you close out that execution block and have code later on in the page to send the email, then that error handling would do nothing to prevent that. You need to ensure the email logic is only run if there are no errors.
  5. If you can load the user's account information, you can just as easily send it via POST or GET. You don't have to make a form for the support rep to enter the credentials into. Whether or not sending the data via POST vs GET and actually working will be completely dependent upon how the authentication page was built. If it looks for both POST and GET variables it would work. If not, it wont. It's that simple.Would take all of 30 seconds to test. But, as I said, it would be just as easy to build a solution that sends the data via POST. I'm not sure how you were planning to "present" the feature to the service rep to utilize. but, if you were going to show links on the page, you could just as easily create multiple forms with hidden fields for the authentication data with only a visible submit button for each client for the support rep to click.
  6. Well, it could be a number of things. Have you checked the HTML source code to see if there is actually any value following: sendcmd.php?cmd= If no, then the variables $prefix and $row[code] are likely not set. Or, are you trying to use those to reference a variable variable? If yes, then the script sendcmd.php is likely not referencing that value correctly. Based upon your description, I think the problem is the former - the variables are not set when the page is created. Where are $prefix and $row[code] defined?
  7. Looking through that code there are a ton of problems. Most/all of them are from not paying attention to what you are doing. For example, look at your query: $sql = "INSERT INTO users(username, password, email ,user_date, user_level, university) VALUES('" . mysql_real_escape_string($_POST['username']) . "', '" . sha1($_POST['password']) . "', '" . mysql_real_escape_string($_POST['email']) . "', '" .($_POST['university']) . "', NOW(), 0)"; Look at the order of the fields that you list, then look at the order of the values. They do not match up. But, I doubt you are even getting that far because of issues in the validation logic. Here is a complete rewrite of your page. I don't guarantee it will work as I did not test it, but it will get you going in the right direction <?php include 'mysql.php'; //Preprocess input data (if posted) also used for form repopulation $username = isset($_POST['username']) ? trim($_POST['username']) : ''; $email = isset($_POST['email']) ? trim($_POST['email']) : ''; $university = isset($_POST['university']) ? trim($_POST['university']) : ''; $password = isset($_POST['password']) ? $_POST['password'] : ''; $pass_check = isset($_POST['pass_check']) ? $_POST['pass_check'] : ''; //Create variable to hold error message $errorMsg = ''; //Check if form was posted if($_SERVER['REQUEST_METHOD'] == 'POST') { //Create array to hold errors $errors = array(); //Username validation if(empty($username)) { $errors[] = 'The username field must not be empty.'; } if(!ctype_alnum($username)) { $errors[] = 'The username can only contain letters and digits.'; } if(strlen($_POST['username']) > 30) { $errors[] = 'The username cannot be longer than 30 characters.'; } //University validation if(!ctype_alpha($university)) { $errors[] = 'The university name can only contain letters and digits.'; } if(strlen($university) > 30) { $errors[] = 'The university name cannot be longer than 30 characters.'; } //Password validation if(empty($password)) { $errors[] = 'The password field cannot be empty.'; } elseif($password != $pass_check) { $errors[] = 'The two passwords did not match.'; } //Check if there were errors if(!empty($errors)) { $errorMsg .= "Uh-oh.. a couple of fields are not filled in correctly...<br>\n"; $errorMsg .= "<ul>\n"; foreach($errors as $err) { $errorMsg .= "<li>{$err}</li>\n"; } $errorMsg .= "</ul>\n"; } else { //No errors attempt to create record //sha1 alone is NOT a good method of securing the password $sql = sprintf("INSERT INTO users (username, password, email ,user_date, user_level, university) VALUES('%s', '%s', '%s', '%s', NOW(), 0)", mysql_real_escape_string($username), sha1($password), mysql_real_escape_string($email) mysql_real_escape_string($university); $result = mysql_query($sql); //Check result of query if(!$result) { //Error running query to insert record echo 'Error creating record. Please try again later.'; //Uncomment the following line for debuggin purposes //echo 'Query: $sql <br> Error: ' . mysql_error(); exit(); } else { //Record created successfully echo 'Successfully registered. You can now <a href="signin.php">sign in</a>'; exit(); } } } ?> <?php include 'header.php'; ?> <?php echo $errorMsg; ?> <h3>Sign Up</h3> <form method="post" action=""> Username: <input type="text" name="username" value="<?php echo $username; ?>" /></p> Password: <input type="password" name="password" /></p> Password again: <input type="password" name="pass_check" /></p> Univeristy E-mail: <input type="email" name="email" value="<?php echo $email; ?>" ></p> University: <input type="text" name="university" value="<?php echo $university; ?>" ></p> <input type="submit" value="Add category" /></p> </form> <?php include 'footer.php'; ?>
  8. <?php $offset = isset($_GET['offset']) ? intval($_GET['offset']) : 0; $currMonth = date('n'); $list = array(); $list[] = mktime(0, 0, 0, $currMonth+$offset-1, 1); $list[] = mktime(0, 0, 0, $currMonth+$offset, 1); $list[] = mktime(0, 0, 0, $currMonth+$offset+1, 1); foreach ($list as $dateTS) { echo date('M Y', $dateTS) . ' '; } $prev = $offset-3; $next = $offset+3; echo "<br><a href='?offset={$prev}'>Prev</a> <a href='?offset={$next}'>Next</a>" ?>
  9. Then you should post the solution here in case someone else stumbles upon this post with the same problem.
  10. You should pick a font that will be available on your server, such as Arial. If you are developing on a Windows machine and your app is running on a Linux box you will be limited on the fonts available.
  11. How often do you plan to update the data from the csv file? Unless those updates are going to be frequent and will negatively affect users I don't see a reason to have two databases.
  12. OK, I'm having no luck either. Even after finding multiple posts elsewhere on the subject. Anyway, here is the code written in a more logical format that may assist as you proceed. <?php //Define variables as set by user $bannerWidth = 336; $bannerHeight = 280; $bannerColorR = 0x59; $bannerColorG = 0x08; $bannerColorB = 0x08; $overlayImageSrc = 'downloads/eco_car.png'; // Create background image of selected size $bannerImg = imagecreatetruecolor($bannerWidth, $bannerHeight); // Set background color of banner $backgroundColor = imagecolorallocate($bannerImg, $bannerColorR, $bannerColorG, $bannerColorB); //Fill banner image with background color imagefill($bannerImg, 0, 0, $backgroundColor); //Create source image to add $overlayImg = imagecreatefrompng($overlayImageSrc); //Get size of image to add list($width, $height) = getimagesize($overlayImageSrc); //Set alpha blending imagealphablending($bannerImg, false); imagesavealpha($bannerImg, true); //Merge banner and overlay images imagecopy($bannerImg, $overlayImg, 0, 10, 0, 0, $width, $height); //Display in browser header('Content-Type: image/png'); imagepng($bannerImg); //Destroy imagedestroy($bannerImg); imagedestroy($foregroundImg); exit(); ?>
  13. Is this close to what you are trying to achieve? <?php //Set source image name $sourceImage = "downloads/eco_car.png"; //Get size of source image list($width, $height) = getimagesize ($sourceImage); // Create background image same size as source $backgroundImg = imagecreate($width, $height); // add background #590808 $transparentColor = imagecolorallocate($backgroundImg, 0x59, 0x08, 0x08); // makebackground #590808 transparent imagecolortransparent($backgroundImg, $transparentColor); // add transparent //Create source image object $foregroundImg = imagecreatefrompng('downloads/eco_car.png'); // merge 2 image imagecopy($backgroundImg, $foregroundImg, 0, 0, 0, 0, $width, $height); // display on browser header('Content-Type: image/png'); imagepng($backgroundImg); // destroy imagedestroy($backgroundImg); imagedestroy($foregroundImg); ?>
  14. Your explanations in this post are not providing me with an understanding of what you are trying to achieve. I tried with using the photoshop image, using the php image and with using the dynamically created image in the code. I see no difference in the output created. So, I'm at a loss as to what you are trying to achieve. The best I can tell from your description is that you want to put the car image onto the larger background image and make the background part transparent. This would result in an image of the car with an extended border that is transparent. And, that makes no sense since you could achieve the same effect much simpler by applying some styles to the image. You also didn't answer this question: Why are you dynamically creating the background image on each load of the page. You can either use a static file or you can create the image only in memory instead of saving it.
  15. So, why are you trying to apply a transparency to the background image and not to the overlapping image? Could you please provide an example of what you want the resulting image to look like?
  16. OK, so please explain what - exactly - you are trying to achieve. Because some of your code isn't making sense, so I don't know what you are trying to achieve. For example: // create image $image = imagecreate(336, 280); // add background #590808 $backgroundImage = imagecolorallocate($image, 0x59, 0x08, 0x08); imagecolortransparent($image); // add transparent You create the image, then you defined a color, then you call imagecolortransparent, but don't pass the color to make transparent. So, it doesn't do anything. When you leave the second parameter empty, then that function only returns the current transparent color. Since you aren't saving the return from that function you must be wanting to set the transparent color (which isn't happening). EDIT: Also, why are you always creating a new background image on the filesystem? Why not just create the image object and use that instead of saving a file and then reading that file back into memory?
  17. I'm not following. Perhaps you need to provide copies of two sample images and update your code to include more comments as to what you expect to happen at each step.
  18. I would suggest reading these forums and trying to solve some of the problems posted. I can't tell you how many times someone posted an interesting problem that I decided I wanted to solve. In some cases I have to go out to the PHP manual to see if there are any functions I'm not familiar with that will help me - which increases my knowledge of the language. Then I'll think through the problem in my head (and sometimes on paper) to determine the logical steps to achieve the end result. Then, I'll actually build it. Sometimes, by the time I come back to the post to add my solution I find that someone already posted a solution. But, then I review their solution to see what they did differently. Sometimes they did some things that were better than me and in others I did something better than them. But, by comparing what someone else did to get the same result as myself I learn a lot.
  19. //Import uploaded file to Database $handle = fopen($_FILES['filename']['tmp_name'], "r"); $values = array(); while (($data = fgetcsv($handle, 1000000, ";")) !== FALSE) { //Create record inserts as array elements $values[] = spintf("('%s','%s','%s','%s','%s','%s','%s')", mysql_real_escape_string($napravio), mysql_real_escape_string($vrijeme), mysql_real_escape_string($data[0]), mysql_real_escape_string($data[1]), mysql_real_escape_string($data[2]), mysql_real_escape_string($data[3]), mysql_real_escape_string($data[4]) ); } $query="INSERT DELAYED INTO kalkulacija_import_kategorija (uvezao, vrijeme,kat_br,naziv_artikla,kategorija_artikla,grupa_proizvoda,podgrupa_proizvoda) VALUES " . implode(",\n", $values); echo "<pre>{$query}</pre><br>"; mysql_query($query) or die(mysql_error());
  20. If you have multiple records to insert you should create ONE query with all the values to insert. INSERT INTO table (field1, field2, field3) VALUES (value1a, value2a, value3a), (value1b, value2b, value3b), (value1c, value2c, value3c), (value1d, value2d, value3d) So, using your above logic you would create the "values" list in the loop, then run one query after the loop with all those values.
  21. $output = ''; if(!isset($_POST['choices'])) { //User did not answer the questions, show form $output .= "<form method='post' action=''>\n"; $qNo = 0; foreach($quiz_questions as $qid => $question) { //output the question text $qNo++; $output .= "<p>{$qNo}. {$question['question']}<p>\n"; foreach($question['choices'] as $choiceValue => $choiceText) { $output .= "<input type='radio' name='choices[{$qid}]' value='{$choiceValue}'> {$choiceText}<br>\n"; } } $output .= "<br><br>\n"; $output .= "<button type='submit'>Submit</button>\n"; $output .= "</form>\n";; }
  22. Right, but your requirement to only pick a random value based upon a specific condition completely negates the method he was suggesting. But, yes, even if the intent was to get any random record, just using the max ID (or count of records) and selecting a random value out of that as an ID is not useful since IDs can be skipped - either intentionally when created or by records being deleted. But, that's not to say that approach is completely without merit. You could, for example, get the highest ID value and get a random value between 0 and 1 less than that highest ID value.and do a query similar to what we did above SELECT * FROM table WHERE id > $randID LIMIT 1
  23. Not sure exactly what you mean. The query is not selecting by ID. It is selecting a record randomly using LIMIT (i.e. the position in the result set). So deleting records does not mess up the logic for selecting a random record. As long as there are ANY records that match the set banner_size you will get a result. If there are no records matching the banner_size then you will get an empty result set. The only real problem I see is a race condition issue. If a banner was deleted between the first query and the second query AND the random position selected was for the last record, then the second query would be trying to get a record in a position that is 1 higher than the ones that exist (resulting in an empty result set). But, unless the site is going to have a very high concurrent usage and records will be deleted regularly I think this is a very, very low probability of happening. Plus, the more records that exist the lower probability it would ever occur.
  24. I don't think you understand. The OP wants a random record from the list of records "WHERE banner_size = 7". So, let's say you have these records in your DB id | name | banner_size 1 A 6 2 B 7 3 C 6 4 D 7 5 E 6 6 F 7 7 G 6 The result should be a random record from item B, D, or F. Using the logic of "SELECT WHERE ID == RANDOM NUMBER" would grab ANY record from the table and not just one where banner_size = 7.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.