Jump to content

btherl

Staff Alumni
  • Posts

    3,893
  • Joined

  • Last visited

Everything posted by btherl

  1. Check the line number of your error.. it's actually because you used ' in the second line instead of " for the img src attribute.
  2. Could you explain more clearly what isn't working?
  3. You would be better off asking on a .net forum rather than a php forum
  4. Oops.. it looks like php can't handle those types of entites. And I was using the wrong function too.. Anyway, back to the problem I found this function on the php website function utf8_replaceEntity($result){ $value = (int)$result[1]; $string = ''; $len = round(pow($value,1/8)); for($i=$len;$i>0;$i--){ $part = ($value & (255>>2)) | pow(2,7); if ( $i == 1 ) $part |= 255<<(8-$len); $string = chr($part) . $string; $value >>= 6; } return $string; } function utf8_html_entity_decode($string){ return preg_replace_callback( '/&#([0-9]+);/u', 'utf8_replaceEntity', $string ); } If you feed your string into that, it will convert the data from html entities into utf8. I tested it here, and with the sample string you gave it produces greek characters. If you have any trouble with it let me know. You should call utf8_html_entity_decode($str) to do the decoding.
  5. I found a guide here: http://cheminfo.informatics.indiana.edu/~rguha/misc/apachessl.html Assuming you're using apache..
  6. There's a little switcheroo in there.. email and ip <?php $query = "INSERT INTO user (username, password, email, ip) VALUES ('".$username."', '".$password."', '".$email."', '".$ip."')"; ?>
  7. Assuming you are using mysql, you can use http://sg.php.net/manual/en/function.mysql-list-fields.php But note the comment recommending you use the SQL command SHOW COLUMNS FROM table instead.
  8. $str = 'phpfreaks.com'; if (strpos($str, 'www') !== 0) { # !== 0 fails only if 'www' is found at the start of $str $str = "www.$str"; } I deliberately searched for 'www' instead of 'www.', to allow for cases like www1, www2. I often use a regex like this instead if (!preg_match('|www[0-9]*\.|', $str)) That one matches www. www1. www50. And all other numbers following www
  9. You might want to use parse_url(). It's much less effort. http://sg.php.net/manual/en/function.parse-url.php
  10. Do other scripts work, or is it just this one that gives the error?
  11. Replace $data = addslashes(fread(fopen($form_data, "r"), filesize($form_data))); with $filehandle = fopen($form_data, "r"); if ($filehandle === false) die("Couldn't open $form_data"); $filesize = filesize($form_data); if ($filesize === false) die("Couldn't get filesize for $form_data"); $data = fread($filehandle, $filesize); if ($data === false) die("Couldn't read from filehandle"); $data = addslashes($data); Edit: Actually, you could just use file_get_contents(). Again, check for errors! You might want to check if $form_data is empty first, using if (empty($form_data)) { ... }
  12. No there's not.. you might want to redesign your database if this is a recurring problem. Otherwise, just write a function to set all the fields to 0 and you're finished. It only has to be written once.
  13. It's likely you are storing them that way. Try the following (for a post variable named "var"): $var_decoded = urldecode($_POST['var']); $var_escaped = mysql_real_escape_string($var_decoded); Then put $var_escaped in the database. Do you know what encoding your data is in? UTF8?
  14. What exactly do you see for a flash? And why do you only see it for a flash? Is this via web server or command line? Second question: If you run $command manually (exactly as it is displayed by the script when echoed), does it work?
  15. Change your mysql section to this: con = mysql_connect("localhost","warp_gm","Forest77"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("warp_gm", $con) or die('Could not select db'); mysql_query("INSERT INTO pending_uploads (uploadname, uploaddescription, uploadicon, uploadlink, uploadtype, uploadgenre, uploadstyle) VALUES ('$creationname', '$creationdescription', '$iconlink', '$uploadlink$uploadrand', '$uploadtype', '$uploadgenre', '$uploadstyle')") or die ("Insert failed: " . mysql_error()); And make sure you change that password before going live
  16. Is that your full code? It doesn't appear to be valid php syntax. The code looks like it should be inside a class definition, but the class definition is missing.
  17. The first thing to look at is how to distinguish all your inputs. After that you can look at how to insert it into the database. Have you decided how to distinguish the inputs yet? PHP will create arrays for you if you give variables names like "var[]" in the html. Two alternatives are to parse the form input yourself, or to give each variable from each question a distinct variable name (including the question number).
  18. Oh.. is the problem that there is no comma after create_date=CURDATE() ? If so, mysql_error() should have given you additional information about the error.
  19. In what way did it not work? Did it give an error message, or did it not act like you expected? Details please
  20. Can you post the code you tried? If you need to convince yourself that it works, try the sample code I posted.
  21. preg patterns need a starting and ending delimiter. Look at the following example from the manual: $string = 'The quick brown fox jumped over the lazy dog.'; $patterns[0] = '/quick/'; $patterns[1] = '/brown/'; $patterns[2] = '/fox/'; $replacements[2] = 'bear'; $replacements[1] = 'black'; $replacements[0] = 'slow'; echo preg_replace($patterns, $replacements, $string); In this case, the delimiter is "/", and appears at the start and end of every search pattern.
  22. I doubt you will see any slowdown unless you have hundreds or thousands of users creating content simultaneously. I imagine any one user could not produce more than 1 piece of content every minute, and even that's being optimistic. The structure I am suggesting is not the same as yours. I am suggesting both a categories table AND a content table, but no others. Instead of content1, content2 and content3 tables, I am suggesting a categories table containing the identifiers 1, 2 and 3, and a single content table containing all content. My suggestion is more flexible, but yours may well be faster. Seperating tables often gives speed benefits, at the cost of flexibility. Can I clarify that your content1, content2 and content3 tables store different kinds of content? Or are they a kind of load balancing system to store the same kind of content in seperate tables?
  23. I would start with a structure like this: Table users user_id - integer, automatically incrementing user_name - varchar email - varchar etc etc .. with all other information you want to keep for the user Table categories category_id - integer, automatically incrementing category_name - varchar and other information for each category Table content content_id - integer, automatically incrementing user_id - owner of content category_id - category of content content - varchar and other information regarding a piece of content That structure makes it easy to add categories and users without creating new tables.
  24. A blank screen is often due to a syntax error. Have you set display_errors to 1? display_errors and other error reporting related directives are listed here: http://sg2.php.net/manual/en/ref.errorfunc.php You can set it in php.ini, or you can try ini_set('display_errors', 1);. ini_set() will only work for errors that occur after the script starts executing (ie, not syntax errors). Remember to switch it off once the site is working properly, otherwise it may reveal details about your script to others.
  25. How about this: $command = trim(urldecode($_POST['command'])); if (strpos($command, '/hexcode') === 0) { # We found /hexcode at offset 0 $colour = preg_replace('|/hexcode *|', '', $command); # Then update the db with $colour } There's many other ways to do it.. if you have many commands to detect, you may want to start by checking if '/' is at the start, and only then parsing the command.
×
×
  • 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.