Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. Not sure what you are asking but the stackoverflow post you linked to in your post goes through exactly what you need to and provides code which parses urls within text into HTML links (see the first post by Austin Burk).
  2. What you have posted makes no sense at all to me. If you are going to post code then wrap in tag or click the <> button in the editor. If you are new to PHP then I would suggest you look the PHP documentation first. Start with the Language Reference chapter first, this will explain the PHP syntax.
  3. Ch0cu3r

    echo

    mysqli_real_escape_string takes two arguments, the mysqli link resource ($con) as the first argument, and for the second argument being the value to be escaped ($premio). Your call to mysqli_real_escape_string should be mysqli_real_escape_string($con, $premio) Also if you are not going to be inserting a value into idPremio field then you do not need to include that field in your query it can written as just $query1 = mysqli_query($con, "INSERT INTO premio (premio, idArtesao) VALUES ('".mysqli_real_escape_string($con, $premio)."', '$id')");
  4. Ch0cu3r

    echo

    You have given the text fields the same name. When you do this only the last fields value will be submitted. In order for all the values for the fields that have the same name you need to add square brackets to the end of the name, eg name="premio[]" what will happen now is the values will be submitted as an array meaning $_POST['premio'] will contain a multi-dimension array of values. So $_POST['premio'][0] will contain the value for the first field, $_POST['premio'][1] will contain the value for the second field etc. To output all values you can use a simple foreach loop echo "All premico values: <br />"; foreach( $_POST['premio'] as $fieldValue) { echo $fieldValue . '<br />'; }
  5. Where is that PHP code placed? If its in an external javascript file then that PHP code will never be parsed. Typically the server is only configured to parse files with .php file extension as PHP . PHP is a server-side language, meaning it is ran when a file has been requested from the server. What the browser see is only the output from your PHP code. Web browsers will not know what PHP code is and so your browser is trying to run the PHP code as javascript code. This is why you are getting the syntax error. There is also no point in checking your javascript code that has PHP code in it with a linter, they are only expecting javascript code. They will not know how to handle PHP code.
  6. No, dont use md5 either that is just as bad as using SHA1 It is recommended to use a what scootstah suggested earlier, in reply #2 Also when using sessions, do not use the session_register functions, they are deprecated. When adding values to the session just define a new $_SESSION variable (making sure you have called session_start before hand).
  7. Are you saying files with file extensions in capital letters are being classes as invalid files? Have you tried applying strtolower to the file extension?
  8. What do mean by loss of data and dolphin? Copying regular folders/files to an external harddrive should not result in loss of data, unless the external hard drive is full/not enough capacity etc.
  9. Variables are case sensitive, so $_post is not the same as $_POST
  10. ugh! What why have you got foreach loops, within foreach loops etc ? You should only need one foreach loop to loop through the uploaded files! Looping over the uploaded files within a foreach loop that is also looping through the uploaded files is going to cause duplicate files being uploaded/entered into your tables.
  11. Then you need to put the move_uploaded_file inside a if statement, Use getimagesize as the condition for the if $destination = 'image/'; foreach($_FILES['myfile']['name'] as $fileIndex => $fileName) { // get info for each file $type = $_FILES['myfile']['type'][$fileIndex]; $size = $_FILES['myfile']['size'][$fileIndex]; $error = $_FILES['myfile']['error'][$fileIndex]; $tmp_name = $_FILES['myfile']['tmp_name'][$fileIndex]; // check image is a valid image if($imageInfo = getimagesize($tmp_name)) { // move the the upload file to destination move_upload_file($tmp_name, $destination . $fileName); // show info returned my getimagesize, if its a valid image print_r($imageInfo); // insert file info into mysql here } }
  12. Your are using a variable called $tmp_name when calling move_uploaded_file(). You are getting an error because this variable is not defined. Maybe Look back at my code example (in post #4) for how I reference the tmp_name for each uploaded file
  13. If you want a background process being ran constantly, then you are better of setting up a cron job rather than have it being ran from the browser. No, it has nothing to do with the browser. That function intended use is to allow the script to finish processing when a user aborts the script from the command line. PHP cannot detect when the browser (window/tab) has been closed.
  14. Why does the second script need to keep updating the hrs_to_go column? What is the purpose of this? shell_exec does not redirect the browser, it will wait until the script timer_script.php has finished executing/returned a result. This is why the browser is continually loading. I feel continually updating the hrs_to_go column is unnecessary. You are better of storing the interval as a future date/time, eg you add a row the time is 2015-07-06 10am, adn the interval is 36 hours form now, then you stored a second timestamp as 2015-07-08 22:00:00 as the interval date To calculate the hours to go you can use TIMESTAMPDIFF to subtract todays date with the date interval stored in your table. Example query SELECT time, TIMESTAMPDIFF(HOUR, NOW(), interval_date) as hrs_to_go #substracts todays date, with the date stored in interval and returns the difference in hours FROM theme WHERE interval < NOW() You should not need to continually update your theme table when calculating differences between dates/times
  15. The code provided by Barand should be fine. Im guessing you are running a version of PHP which is older than PHP5.3 (this was released over 6 years ago!). You should consider updating PHP to a much newer version (ideally 5.4.x minimum or preferably php5.6.x) Anyway the alternative to Barands code would be not to use anonymous functions function sortValues($a, $b) { return strnatcmp($a['text'], $b['text']); } usort($data, 'sortValues');
  16. Try using $data->data->hierarchy->Data->Total $data->data->hierarchy->Data->CrewId etc
  17. You will need to reformat the date before inserting it in your query, example $date = new DateTime('2015-07-05T09:50:38.0870000Z'); $dateFormatted = $date->format('Y-m-d h:i:s'); // reformat to YYYY-MM-DD HH:MM:SS (mysql datetime) format echo $dateFormatted;
  18. What do you mean "didn't work" could you explain what you are expecting that code to do?
  19. See documentation on cal_days_in_month Alternatively pass a timestamp to date and use t as the format
  20. As your title says use isset if (!isset($_POST['office'])) { $fielderror .= 'Please fill in the "Office" field'; $doNotSubmit = true; } else if(isset($_POST['office']) && strlen($_POST['office']) < 3) { $fielderror .= '"Office" field cannot contain less than three characters<br>'; $doNotSubmit = true; }
  21. Why not just make the replacement of the smiley codes be case-insensitve? function imageTag($value) { return '<img src="' . $value . '" />'; } $message = str_ireplace( array_keys($people) , array_map('imageTag', array_values($people)) , $message); Now you dont need to define : d or : D as smiley.gif Alternatively use array_unique when displaying your simileys EDIT: Damn stupid form keeps rendering the simely codes, even when wrapped in in nobbc tag
  22. Sorry, still not clear as to why you reading the text into an array. Could explain it again please?
  23. Is ths related to yesterdays post with the regex I gave? The regex I gave ignores all whitespace characters, this is how it able to return all the words, numbers and symbols from the text and puts them into an array. Can I ask why does your text need to be read into an array?
  24. You should not need to insert the image ids into the case table Instead, first insert your data into the casa table with the image id. When you have inserted the new row, use mysqli_insert_id to get the id of the row that was just inserted into the casa table. When you go to insert the image info into the imagem table you insert the case id too (you will need to add new column in your imagem table, you can call this cid or casa_id). When you go to retrieve the images that belong to the casa id you use a JOIN query. Example SELECT c.preco, c.descriaco, i.caminho FROM casa c LEFT JOIN imagem ON c.id = i.cid This query will return the images that relate the id field in the casa table. This is the correct way for storing your data. It is called data normalization.
  25. That page explains what happens when you upload multiple files, $_FILES super global will contain a multidimensional array of the files uploaded. To process each file you simply loop over the items in the $_FILES['myfile'] array. Example code $destination = 'image/'; foreach($_FILES['myfile']['name'] as $fileIndex => $fileName) { // get info for each file $type = $_FILES['myfile']['type'][$fileIndex]; $size = $_FILES['myfile']['size'][$fileIndex]; $error = $_FILES['myfile']['error'][$fileIndex]; // move the the upload file to destination move_upload_file($_FILES['myfile']['tmp_name'][$fileIndex], $destination . $fileName); // insert file info into mysql here }
×
×
  • 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.