Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Community Answers

  1. Ch0cu3r's post in php fwite add blank spaces from each loop was marked as the answer   
    Maybe the tab/spaces is coming from  $item->station_id  . Try applying trim to that variable.
     
    fclose needs to be moved outside of the loop.
  2. Ch0cu3r's post in Table To update from database was marked as the answer   
    Doesn't have to be. 
     
    If the the form is submitting to itself then in the forms action add a hash, eg
    <form action="#invoice" method="post"> ... form ields ... </form> When the page loads, in javascript use  window.location.hash  to get the hash value, it it is equal to #invoice then have the invoice tab be the active tab rather than the customer tab. Judging by your screenshot you are possibly using Bootstrap tabs component? Looking at the documentation you should be able to call the .show() method on your invoice tab to set as active, eg
    if(window.location.hash == '#ivoice') { $('#invoiceTabIdHere').tab('show'); // should make the invoice tab active } 
  3. Ch0cu3r's post in handling html form fields with preg_match was marked as the answer   
    First you need to use the following xpath query.
    $rows = $xpath->query('//table[@id="r"]/tbody[@class="table-text"]/tr'); As your HTML table is not syntax formatted then the following lines will no longer work.
    // explode on each newline character in nodeValue (note the HTML tags are stripped out, leaving just the text inside the td tags) // and merge with the $defaults array $values = array_replace($defaults, explode("\n", trim($row->nodeValue))); // remove any whitespace before or after each value $values = array_map('trim', $values);  Instead replace them with the following
    // get the values for the child "td" tags in the row $values = getChildNodeValues($row->childNodes, 'td'); And add the following function before the foreach loop
    function getChildNodeValues(&$nodeList, $nodeName) { $values = array(); foreach($nodeList as $node) { if($node->nodeName == $nodeName) $values[] = trim($node->nodeValue); } return $values; }
  4. Ch0cu3r's post in Quick help regarding showing typed text from one input to another. Check out this code. was marked as the answer   
    So you only want plain text to be inserted into seo_page_description textarea, stripping out all html tags returned by CKEditor? In that case use JQuery.text method
    $('#seo_page_description').val($(evt.editor.getData()).text());
  5. Ch0cu3r's post in Form Data not passing into Array was marked as the answer   
    Your form for registering the user has a submit button named register
    <input type="submit" value="Register" name="register"/> But your code for registering the user will only run if POST value named submit exists
    if(isset($_POST['submit'])){ You want to be checking if $_POST['register'] exists 
     
    Why are you using filepaths in header redirects?
    header('Location: C:/xampp/htdocs/home.php'); header('Location: .C:/xampp/htdocs/index.php?action=joined'); You should be using urls
    header('Location: /home.php'); header('Location: /index.php?action=joined'); Also I wouldn't recommend hard coding absolute file paths. Instead either define a constant containing an absolute file path the root of your application (C:/xampp/htdocs) and prepend your file paths with that constant or use $_SERVER['DOCUMENT_ROOT'] instead
    define('ROOT', 'C:/xampp/htdocs/'); require_once(ROOT . 'includes/dbconfig.php'); // OR use require_once($_SERVER['DOCUMENT_ROOT'] . 'includes/dbconfig.php'); That way you only need to edit the file path in one place rather than having to hunt throughout your code to modify filepaths
  6. Ch0cu3r's post in Signature code problem! was marked as the answer   
    You dont need PHP for this. Use HTML/Javascript/CSS.
     
    Live Example
     
    Set this variable to the url to your signature image
    imageUrl = 'http://yoursite.com/signauture.php',
  7. Ch0cu3r's post in Apostrophes using a textarea [PHP 5] was marked as the answer   
    No, nl2br has nothing to do with sanitizing. I just telling you not to manually convert the newlines to HTML line break tags.
     
    Sanitizing is where you are escaping user input to make it safe to use within SQL queries. Typically this is done either by using mysqli_real_escape_string or using prepared statements. Are you not doing neither of those? If not then that is most likely the issue. Failure to do so will make your code prone to SQL Injection attacks
     
    I suspect the reason your code works on godaddy is because they have a setting enabled called magic quotes, which automatically escapes any quotes in user input being submitted. This was removed as of 5.4 and so your quotes are not being escaped on 1&1 which is leading to syntax error in your SQL query.
     
    If you sanitize your user input properly then quotes within user input should not have any affect on your queries.
  8. Ch0cu3r's post in Text editor save to file was marked as the answer   
    1) You have not assigned this
    $_POST['update']; to a variable. I presume that line is meant to read as
    $update = $_POST['update']; 2) Open the file use append mode
    $file = fopen($file1, "a"); Then there is no need for this
    $contents = file_get_contents($file1); file_put_contents($file1, $contents); 3) fwrite takes the file handler as the first argument and the value to be written as the second argument (needs to be $update not $file1)
    fwrite($file, $update); The alternative is not use fopen/fwrite/fclose  but to use only file_put_content using the FILE_APPEND flag
    if(isset($_POST['update'])) { $file = "file.txt"; $update = $_POST['update']; file_put_contents($file, $update, FILE_APPEND); // append $update the file.txt }
  9. Ch0cu3r's post in Check login username and password was marked as the answer   
    session_register() function is deprecated and removed as of PHP5.4. You should not be using this function for registering session variables at all. Instead you should be assigning the value to the $_SESSION superglobal variable
    $_SESSION['user'] = $username; // add the username to the session variable, named user Make sure you are calling session_start() at the top of all your pages which uses $_SESSION variables, in order for session values to persist between pages.
  10. Ch0cu3r's post in Ajax call php class function? was marked as the answer   
    No, that is not what hansford meant
     
    You still need to to have the code you used in post #7 for handing the ajax request, except rather than doing this
    $id_itens = filter_input(INPUT_POST, 'item'); $delItem = filter_input(INPUT_POST, 'delItem'); if ($delItem != null) { $ret = $user->delItem($id_itens); echo json_encode($ret); } it'll now be
    $id_itens = filter_input(INPUT_POST, 'item'); // get the action passed for ajax request $action = filter_input(INPUT_POST, 'action'); // do this if action is set to delItem if ($action == 'delItem') { $ret = $user->delItem($id_itens); echo json_encode($ret); }
  11. Ch0cu3r's post in Was PHPFreaks hacked? was marked as the answer   
    Sadly, yes.
     
    See topic in the Announcements Forum
  12. Ch0cu3r's post in I'm testing basic login system was marked as the answer   
    If you are getting the COuld not work message then that means your query is failing, use mysqli_error to find out why your query failing
    $result = mysqli_query($Garydb, $log) or die("could not work. MySQL Error: " . mysqli_error($Garydb));
  13. Ch0cu3r's post in Query about how to hide errors if was marked as the answer   
    Before using $_GET['id'] you need to check it exists. One way is to use the ternary operator
    $id = isset($_GET['id']) ? $_GET['id']: '' /* <-- set this to the default value */;
  14. Ch0cu3r's post in Simple Get function not working from URL was marked as the answer   
    No, You misunderstood Psycho and mac_gyver replies please read them again.
     
    Yes you are connected to the DB using mysqli (mysql improved). But you are using mysql_real_escape_string function which is not compatible with MySQLi Improved.  The mysql_ functions and mysqli_ functions (note the i after mysql) are not compatible with each other.
     
    The mysql improved equivalent is mysqli_real_escape_string (has an i after mysql).
     
    However reading your post score should only contain a number, then you should not be using mysqli_real_escape_string. This function is should only be used for escaping string values, such as a persons name, contents of a blog post etc. Not for numbers. What you should do is only insert the new score value if $_GET['score'] is in fact a number.
    // validate $_GET['score'] exists and consist of digits if(isset($_GET['score']) && ctype_digit($_GET['score'])) { // assign $_GET['score'] to $score and convert to an integer (whole number) $score = intval($_GET['score']); $sql = "UPDATE users SET score_03='$score' WHERE id=2"; if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $conn->error; } } else { echo "Submitted score is invalid"; }
  15. Ch0cu3r's post in display specific number of characters was marked as the answer   
    Use substr
     
    Example
     
    echo "<td>" . substr($row->comments, 0, 100) . "</td>"; Will only show the first 100 characters from the string stored in $row->comments
  16. Ch0cu3r's post in reCaptcha integration problems was marked as the answer   
    As explained in googles recaptcha documentation for verifying the recaptcha response you need to send a POST request to https://www.google.com/recaptcha/api/siteverify containing both your google recaptcha's secret key and the g-recaptcha-response value in order for google to verify the users recpatcha value is valid when your form has been submitted.
     
    To do this you would use curl, take a look at the post by printf's here for the code to do this. Note you will need to set the value of $key here
    $key = 'my key';  to your google recaptcha secrete key. And also replace
    echo 'Recaptha Result: '; var_dump ( $result['success'] ); With
    if($result['success']) { // YOUR CODE FOR SENDING THE EMAIL GOES HERE }
  17. Ch0cu3r's post in Timeout on Jquery Remove Class Does Not Work was marked as the answer   
    Use Jquery's delay method rather than setTimeout to remove the fade class
  18. Ch0cu3r's post in Need help with a Javascript function was marked as the answer   
    Yes you can echo the value of $fileId for passing its as an argument to the javascript function. Your javascript function definition then becomes
    function removeReceipt(fileId) { $.ajax({ url: '<?php echo Thisurl();?>', data:{ReceiptId: fileId }, type: 'post', success:function() { window.location.reload(true); } }); }
  19. Ch0cu3r's post in Alert buttons ID shows 'undefined' was marked as the answer   
    Probably because $(this) is only defined by jquery if it is handling the click event. Jquery only handles events you instruct it to do.
     
    Either have Jquery handle the onclick event (using its event handler) or pass  this  as the argument to the function being called in the onclick attribute  onclick="DeleteItemByID(this)". Setting  this  as the argument passes the event instance of the element that was clicked to the function.
     
    Now in your function will be
    function DeleteItemByID(elm) { var deleteid = elm.id; // get the id attribute from the element instance from where this function was called from alert(deleteid); }
  20. Ch0cu3r's post in Why manual array works with extract but auto download does not? was marked as the answer   
    @tommytx the reason extract is not working is because by default $wpdb->get_results() returns the query results as an object. extract requires an (associative) array.  You need to set the second argument (called output type) for $wpdb->get_results() to ARRAY_A.  See documentation on various output types here: https://codex.wordpress.org/Class_Reference/wpdb#SELECT_Generic_Results
     
    I do agree with benanamen comment though.
  21. Ch0cu3r's post in loop php multidimensional array was marked as the answer   
    Use a foreach loop to iterative over the names array, using the array key to get the corresponding value in the prices array
    // loop over the names array foreach($array['names'] as $key => $name) { // use the array key to reference the corresponding value in the prices array $price = $array['prices'][$key]; // do insert query } Change $array to be your variable that contain the names and prices array
  22. Ch0cu3r's post in Need Help in Hiding Response code fro SMS gateway API was marked as the answer   
    Set the CURLOPT_RETURNTRANSFER option to true

    $ch = curl_init(); // set URL and other appropriate options curl_setopt($ch, CURLOPT_URL,$url); curl_setopt($ch, CURLOPT_HEADER,FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // set to true to have curl return the response, rather than output it directly // $response will now contain the sms confirmation code $response = curl_exec($ch); // close cURL resource, and free up system resources curl_close($ch);
  23. Ch0cu3r's post in substr () Question was marked as the answer   
    Yes with the highlighted corrections in red
    That'll be pretty much the same code I posted earlier and what Psycho had also posted
  24. Ch0cu3r's post in Mysql SELECT and UPDATE in same command was marked as the answer   
    What are you trying to do? Increment pad_count by a certain amount? There is no need for the select query to get the current pad_count. You can reference the pad_count column in your update query and do simple arithmetic
    $pad_id = 1; $add_pad_count = 2; // add 2 to the current pad_count column $sql = "UPDATE user SET pad_count = (pad_count + $add_pad_count) WHERE pad_id = $pad_id";
  25. Ch0cu3r's post in Do/While Loop was marked as the answer   
    Where did you add that line? It must be within the do {} statement not after the while condition.
    $red = "exciting"; do { echo "<p>It's $red to be red.</p>"; $red = false; // set $red to false to stop the loop } while ($red == "exciting");
×
×
  • 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.