Jump to content

Psycho

Moderators
  • Posts

    12,160
  • Joined

  • Last visited

  • Days Won

    130

Everything posted by Psycho

  1. What you are stating makes no sense. You can't have the AJAX call a method. An AJAX call has to be to a PHP page that will be processed just as if the user typed the URL into their browser. The AJAX call doesn't automatically initiate/run a method on the page called. So, either you are doing something completely wrong or you are using the wrong terminology which is making it difficult to help you. You stated previously that the functionality worked when you let the form post normally (w/o the AJAX). If your form action is pointing to the file where the Users class is defined, then I call BS. Just loading that script would do nothing. All it does is define the class - it never calls the class to actually do anything.
  2. You stated that the page works when you do not implement the AJAX call and just let the form post to the PHP page identified in the action parameter, correct? That doesn't make sense since it would just load the page with the class definition, but not actually use the class. If you are not getting a response from the AJAX call, the first order of business is to verify that it is even calling the page correctly. You are setting the URL for the AJAX call using this url: from.attr('action'), You should validate that it is the value you think it is. Try adding a line right after you define from var from = $(this); alert(from.attr('action')); If that isn't alerting the value you expect then that's the source of your problem. If it is the value you expect, then go to the next logical step in the process and verify the data.
  3. OK, good. That's the type of information that would be helpful to know up front. Well, I don't see how that class gets called from the AJAX request. It may not be getting used at all for all I know. You could do a couple of quick tests to see what is happening. Change the success condition in the AJAX call to alert() the returned value. Then you can verify what, if anything, is being returned. If you do get a 0 response then change the PHP method to return the $_POST['to_email'] value (with the alert still in place) so you can verify the AJAX is passing the value correctly. If you aren't getting anything inthe alert() then that method is not getting called. What I meant was why do you have a loop at all? IF there will only be one record just reference that record directly if(!empty($email_addr)) { $this->load->library('email'); $this->email->from('[email protected]', 'Your Name'); $this->email->to($email); $this->email->subject('Password'); $this->email->message($email_addr[0]['password']); // <<==
  4. If you know that then why are you not implementing a password reset process instead of going to the trouble of retrieving their current password to send to them? If you truly intend to do it correctly, then why are you wasting time writing code to do something the wrong way? It would make more sense if you were just building this to send a mock email with the intent of updating it to send a new temp password rather than writing code to retrieve the password. As to your problem, what debugging have you done so far and what did you find? We can't solve your problem since we don't know what the results are. So, pick one place of possible failure and verify what is or is not happening. Here is the break-down as I see it should go: 1. The JavaScript makes a call to a PHP page passing the email value 2. The PHP page takes the email value, performs operations and returns a 1 or 0 3. The JavaScript page takes the return value to determine what to show/hide All you know is that in step 3 you are always getting the error condition, I would start by testing the PHP page by directly submitting the form instead of calling it via AJAX. If that works then adding some debugging to the PHP page to verify the data it is receiving from the AJAX call the ultimate output. However, since this is being called via AJAX you need a way to output that info. You could either have the page write debugging info to a flat file that you inspect or you could output the debugging info back to the AJAX return function and output it to the page. Edit: After reading the PHP file, all it contains is a class. Is that the file that is called from the AJAX request? If so, the class is never instantiated or called. So, that page would simply return nothing. Also, that function has almost zero error handling. Plus, the logic in it isn't making sense to me. For example, why is there a foreach() loop on something that should only include a single record? Anyway, you just need to follow some simple debugging processes. Take one point in the process and add some debugging code to verify the data coming in and the data going out. - If the data coming in is not right, then you know that the problem exists somewhere earlier in the process - If the data coming in is correct, but incorrect going out - then you've found at least one problem and can address it - If the data coming in and going out is correct, then you know the problem exists somewhere later in the process.
  5. Or more simply use mysql_result(). I've renamed the variables to more commonly used for the intended purpose. There's no need to give all the query strings or the results unique names: $photo = mysql_real_escape_string(trim($_GET['image'])); $query = "SELECT title FROM photo_from_user WHERE picture = '$photo' limit 1"; $result = mysql_query($query); if(!$result) { echo "Error running title query - message is " . mysql_error(); exit(); } $title = mysql_result($result, 0);
  6. Forget your AJAX problem. You first need to resolve the issue that you are apparently storing an unhashed value for the user's password. No one, not even you, should have access to the user's password. You should store a hash of the user's password which is a sort of one-way encryption. If done correctly, it would be impossible to ever revert the hashed value back to the original value provided by the user. And, you're sending this through email no less!
  7. Sure thing. Post back if you run into any problems/questions after reviewing a tutorial or two. EDIT:When I clicked the Tutorials tab on this site, it is empty of content. But, when I just did a Google search, the PHP Freaks tutorial was the second result and can be accessed here: http://www.phpfreaks.com/tutorial/basic-pagination
  8. What you are referring to is called pagination. How you achieve this requires more than just a query (you need two queries plus PHP code to manage it). There are tons of tutorials on how to accomplish this. There used to be one on this site, but it looks like they've removed them all. Just Google "PHP pagination tutorial"
  9. You didn't state whether all clients have at least one object and, if they don't, whether you want clients without any objects to be displayed. If all clients have objects OR if you don't want to show ones that don't ahve any objects, remove the "LEFT" part of the JOIN. This is just an example since I don't know your table structure. It will get one object for each client based on the object with the lowest ID. This would select only the first object SELECT * FROM clients LEFT JOIN objects ON clients.client_id = objects.client_id AND objects.object_id IN ( SELECT MIN(object_id) FROM objects GROUP BY client_id )
  10. Well, that code works for me. I don't work with images much. I just took the example code from the manual and then made one change after another to meet the intent of your original code. That's what I was expecting you would do. If you are getting a broken image, then an error is occurring, but because the header is forcing the output to be an image you see a broken image. Comment out the following line to see the errors header('Content-Type: image/jpg'); Are you sure the two directories where you are trying to save the photos exist where you think they do? Also, your comments above still don't explain why you need to save two instances of the photo. makes no sense. Just create one file.
  11. Do "what" exactly with JQuery? You could superimpose text on top of an image using CSS (no JavaScript involved). Or, if you are talking about using JQuery to perform AJAX calls to PHP, yes. But, not knowing how you want to use it, I can't give you any input. I will say this, however: I don't see why you are creating the image, writing it to two different places and then also outputting it directly to the browser. It would make more sense to me to write the image ONCE to the file system and then have a normal IMG tag for displaying it. <?php if (isset($_GET['image'])) { ## Hard coded values $images_folder = ''; $font_path = '../fonts/Timeless-Bold.ttf'; $font_size = 10; $top_margin = 50; $bottom_margin = 50; $photo_directory = '../photos/'; $upload_directory = '../useruploadedphotos/'; #Variable values $image_name = $_GET['image']; $topcaption = $_GET['topcaption']; $bottomcaption = $_GET['bottomcaption']; $image_path = "{$images_folder}{$image_name}"; //Create image resource from source image $imageRes = imagecreatefromjpeg($image_path); //Determine the image hieght & width $image_x = imagesx($imageRes); $image_y = imagesy($imageRes); //Create color identifier for the text $black = imagecolorallocate($imageRes, 0, 0, 0); //Create bounding box for the top caption $bbox = imagettfbbox($font_size, 0, $font_path, $topcaption); //Calculate cordinates for X and Y of top caption $x = $bbox[0] + (($image_x-$bbox[4]) / 2); $y = $top_margin - $bbox[5]; //Write top caption to image imagettftext($imageRes, $font_size, 0, $x, $y, $black, $font_path, $topcaption); //Create bounding box for the bottom caption $bbox = imagettfbbox($font_size, 0, $font_path, $bottomcaption); //print_r($bbox); //Calculate cordinates for X and Y of bottom caption $x = $bbox[0] + (($image_x-$bbox[4]) / 2); $y = $image_y - $bottom_margin; //Write bottom caption to image imagettftext($imageRes, $font_size, 0, $x, $y, $black, $font_path, $bottomcaption); //Write image to file system imagejpeg($jpg_image, "{$photo_directory}{$image_name}"); imagejpeg($jpg_image, "{$upload_directory}{$image_name}"); //Output to browser header('Content-Type: image/jpg'); imagejpeg($imageRes); imagedestroy($imageRes); // header("location: success.php"); } ?>
  12. So, where is the modified code you've made and where is the problem you are now facing?
  13. Did you look at the code in the manual?
  14. You'll also need to use imagettfbbox() first. That function will give you the bounding box size. From that you can calculate where to put the text so it will be centered. Look at the example code for that function.
  15. What do you mean they are "linked from another table". Are you saying the image you provided is the result of a query with a JOIN? You'll need to provide the data from the relevant tables and the query you are using if we are to understand the details.
  16. Perhaps all of the values have a line break at the beginning?
  17. I stand corrected. I could have sworn it did not do that.
  18. EDIT: NEVER put user entered data into a query (unless you are using prepared statements). In this case you can use intval() on the value $id = intval($_GET['data']); $statement = "SELECT * FROM table1 WHERE id={$id}"; As to your issue, MySQL does not return NULL for a NULL field. Just check if the value is not empty. Plus, there are no quotes around the value if (!empty($row['img'])) { echo "<img src=\"{$row['img']}\">"; }
  19. Works for me on my FTP server. Are you getting any output for the var_dump()? You should get a Boolean false if the function is failing.
  20. Did you turn on error reporting? If not, turn it on. If so, what errors are you receiving? Heck, you may be using the commands wrong for all we know, but since you failed to provide a single line of code we would only be guessing.
  21. $value = (isset($_POST['hidden'])); $querys = "SELECT * FROM kommentarer where img_id = $value"; $value is being set to a Boolean (i.e. True/False) not to the value passed in the hidden field. That is probably the source of your problem. Try $value = isset($_POST['hidden']) ? intval($_POST['hidden']) : 0;
  22. Did you consider asking the author of that API?
  23. That is so the "label" of the options will be "Jan", "Feb", "Mar", etc. but the values for the options will still be 1, 2, 3, . . . Because the function to create options uses the INDEX of the array as the value and the VALUE of the array as the label. The function can be used to create options for any select list. Say you have a list of users in your database, you would use the UserID as the value and the User's name as the text/label. Seriously? I don't think you looked at the sample code very well. Those two functions will call the createOptions() function as I showed. I also showed how you would actually implement the functions in the HTML code.
  24. You are looking at it completely wrong. A database is not meant ot be viewed directly. Anything you use to "look" at the database is simply doing a query and outputting the data in some format. You know, you can store whole images in your database, but you aren't going to "see" an image if you were to inspect the contents. You would just see a string of random characters. It is when you retrieve the content and format it back as an image that it would be viewable as an image. Stop thinking of the database as an Excel document. As for storing data you simply choose the appropriate field type. For something that can be a very long article you would use the BLOB or TEXT types. http://dev.mysql.com/doc/refman/5.0/en/blob.html
  25. So the PHP code just spontaneously generates data? Let's start again. I *think* you are having the data submitted via a form by the user. OK, instead of taking that data, creating HTML and writing to a file you should instead save it to a database. It can be a little intimidating to get started but, honestly, once you start using a database that is when things get fun (at least I think so). You just have individual records, so you would only need one table. I can't really go over everything that you need to do to get started in a forum post, so go find a tutorial. But, I'll provide some basics for you based upon what I see above. First, you will create a table with the following fields: id: This will be an INT type field set to be auto-incremented. You will not need to set it as it will be set automatically. You will use this field to reference the records. date: this should be a timestamp field with a default value of NOW(). This way you never have to actually set it - it will be done automatically when you create the record referrer: This will be a varchar with a length big enough to hold whatever the longest value may be ip: This will be a varchar with a length of 15 characters account: This will be a varchar with a length big enough to hold whatever the longest value may be password: This will be a varchar with a length big enough to hold whatever the longest value may be Once the DB is set up you can then process a form post to insert the record into the database as follows. Note: the mysql_ functions have been deprecated, but I know them without having to check syntax. You'll want to use the mysqli_ functions instead. Just check the manual to check the differences mysql_connect('DB_URL', 'DB_UserName', 'DB_PassWord'); mysql_select_db('name_of_database'); $referrer = $_SERVER['HTTP_REFERER']; $ip = $_SERVER['REMOTE_ADDR']; $account= mysql_real_escape_string($_POST['name']); $password= mysql_real_escape_string($_POST['pass']); $query = "INSERT INTO table_name (referrer, ip, account, password) VALUES ('$referrer', '$ip', '$account', '$password')"; $result = mysql_query($query); That's just very, very basic code, but should get you started.
×
×
  • 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.