Jump to content

Ch0cu3r

Staff Alumni
  • Posts

    3,404
  • Joined

  • Last visited

  • Days Won

    55

Everything posted by Ch0cu3r

  1. What url are you using for the iframe? and the parent frame/window? As long as the url for the parent window is a http request to a server that is configured with PHP then it should work fine. Can you post your code also?
  2. Yes that should be fine. No you'll add a ? (placeholder) and pass the value in the bind_param() if ($insert_stmt = $mysqli->prepare("INSERT INTO members (username, email, password, salt, Thing) VALUES (?, ?, ?, ?, ?)")) { // define query $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt, $drop); // add the values to query
  3. I dont understand you still haven't done anything with the data. You have coverted the $_POST array to json, but nothing else. window.location.href will redirect the user, which will cause the data in the ajax request to be forgotten. The success: will be called when the ajax request is successful. the data variable will contain the information PHP has echo'd. In your case the json
  4. This is a special query called a prepared statement. Prepared statements handles the input values separately from the actual query. This is to help prevent a vulnerability called SQL Injection. The values are coming from the bind_param() in the order they are listed. $insert_stmt->bind_param('ssss', $username, $email, $password, $random_salt); -- You have named the option as my_dropdown so you'll get it from $_POST['my_dropdown']. if you want to use the filter_input function it'll be $my_dropdown = filter_input(INPUT_POST, 'my_dropdown', FILTER_SANITIZE_STRING); $my_dropdown will contain the selected value.
  5. It looks like your PHP code appears to rely on a setting called register_globals being on. Nowadays this setting is off by default (on 5.3+) and has been removed since PHP5.4+. I would look into doing a complete rewrite so your code is more upto date. Also using eval() is very dangerous too.
  6. The data is being transferred via POST. So use json_encode on $_POST superglobal array. echo json_encode($_POST);
  7. You are not accessing their api correctly. The url you are using is for setting up the api parameters. With these parameters you need to create a session with a POST request. To do this you'll need to use cURL. Their api will then the return a session, which you'll use to retrieve the data. // get the api parametures from setup url $apiParamsUrl = "http://www.skyscanneraffiliate.net/portal/en-GB/UK/LivePricing/TestHarness?apikey=cc379434454338361714672782744594&country=GB&currency=GBP&locale=en-GB&originplace=edi&destinationplace=lon&outbounddate=2014-01-31&inbounddate=2014-02-07&adults=1&children=0&infants=0&locationschema=iata&cabinclass=economy"; $apiParamsStr = parse_url($apiUrl, PHP_URL_QUERY); // get the query string parametures parse_str($apiParamsStr, $apiParamsArray); // parse into an array // the api url. First we need to request for a session $apiSessionUrl = 'http://partners.api.skyscanner.net/apiservices/pricing/v1.0'; //open connection $ch = curl_init(); //set the url, number of POST vars, POST data curl_setopt($ch,CURLOPT_URL, $apiSessionUrl); curl_setopt($ch,CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded', 'Accept: application/json')); // make api return json data curl_setopt($ch,CURLOPT_POST, count($apiParamsArray)); // set how many fiels curl_setopt($ch,CURLOPT_POSTFIELDS, $apiParamsStr); // set the fields // caputre the headers curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_VERBOSE, 1); curl_setopt($ch, CURLOPT_HEADER, 1); //execute post $response = curl_exec($ch); // get the headers $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $header = substr($response, 0, $header_size); $body = substr($response, $header_size); //close connection curl_close($ch); // get the api session url preg_match('~Location: ([^\s]+)~', $header, $matches); $apiSessionUrl = $matches[1]; // add on the api key for the session $apiSessionUrl .= '?apiKey=' . $apiParamsArray['apikey']; // get the json data $data = file_get_contents($apiSessionUrl); // decode the json $array = json_decode($data); // dump json array printf('<pre>Poll Data %s</pre>', print_r($array, true));
  8. From the PHP code you posted that is all it currently does It sets the status to "Fail" and the error message to "Failed to save data". What do you want the PHP script to do with the data it receives?
  9. When an error occurs mysqli_query will return false. You'd then use mysqli_error to get the error message from mysql. The specific error codes for an unknown table is 1146 and for columns it is 1054 List of MySQL error codes http://dev.mysql.com/doc/refman/5.5/en/error-messages-server.html
  10. I have tested the code and it appears to work fine. EDIT: Remove the # comments from the code before you try. My test code <?php if(isset($_POST['selname'])) { $response = array('0001', '1'); // add return data to an array echo json_encode($response); // json encode that array exit; } ?> <html> <head> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script type="text/javascript"> function getvalues() { var selname = $("input[name='names']:text").val(); $.ajax({ url: "", data: {"selname":selname}, type: 'post', dataType: "json", success: function(output) { console.log(output); $("#aic").val(output[0]); $("#batchcode").val(output[1]); } }); } </script> </script> </head> <body> <form method="post"> <input type="text" name="names" id="query" onblur="getvalues()"/> <input type="text" name="aic" id="aic"/> <input type="text" name="batchcode" id="batchcode" /> </form> </body> </html>
  11. Echo do not send separate responses. You are setting aic and batchcode to same value as the response (00011). What you should do is json_encode the response while($rows = mysql_fetch_array($result)){ $response = array($rows['aic'], $rows['batchcode']); // add return data to an array echo json_encode($response); // json encode that array } Now set each text field the corresponding value from json array dataType: "json", # the datatype to expect from the response success: function(data) { $("#aic").val(data[0]); # first item is aic value $("#batchcode").val(data[1); # second item is batchcode value }
  12. Call the toggle_all_day_event() on page load (<body onload="toggle_all_day_event()">). When the page loads this function will be called and the other options will be enabled. As soon as you click the check box they should disable.
  13. You'll want to use file() to read the lines into an array. You'd then loop over each line, exploding on the tab character ("\t") to get each column (call number, dateStart, dateEnd and duration). You'd want to create an array, using the call number as the key. You'd assign the call date(s) and duration together into an array. That way all information for that call number is grouped together. Example code $lines = file('05-2012.txt', FILE_IGNORE_NEW_LINES); $callDataArray = array(); foreach($lines as $line) { // get each column, exploding on the tab character list($callNumber, , $callStartDate, $callEndDate, , $callDuration) = explode("\t", $line); // create a new array for each call number if(!isset($callDataArray[ $callNumber ])) $callDataArray[ $callNumber ] = array(); // group call number data together $callDataArray[ $callNumber ][] = array($callStartDate, $callEndDate, $callDuration); } Will produce the following array Array ( [19738424064] => Array ( [0] => Array ( [0] => 2012-05-01 09:04:17 [1] => 2012-05-01 09:05:44 [2] => 0.008 ) [1] => Array ( [0] => 2012-05-01 12:01:52 [1] => 2012-05-01 12:19:17 [2] => 0.072 ) [2] => Array ( [0] => 2012-05-01 14:27:30 [1] => 2012-05-01 14:27:45 [2] => 0.004 ) [3] => Array ( [0] => 2012-05-01 14:28:02 [1] => 2012-05-01 14:28:12 [2] => 0.004 ) [4] => Array ( [0] => 2012-05-02 09:20:19 [1] => 2012-05-02 09:21:19 [2] => 0.004 ) [5] => Array ( [0] => 2012-05-02 09:08:04 [1] => 2012-05-02 09:19:46 [2] => 0.048 ) [6] => Array ( [0] => 2012-05-02 14:16:54 [1] => 2012-05-02 14:23:49 [2] => 0.028 ) ) [19738424065] => Array ( [0] => Array ( [0] => 2012-05-01 14:14:17 [1] => 2012-05-01 14:18:49 [2] => 0.02 ) [1] => Array ( [0] => 2012-05-01 14:28:24 [1] => 2012-05-01 14:29:58 [2] => 0.008 ) [2] => Array ( [0] => 2012-05-02 09:21:33 [1] => 2012-05-02 09:39:27 [2] => 0.072 ) ) ) Passing $callDataArray to json_encode will produce {"19738424064":[["2012-05-01 09:04:17","2012-05-01 09:05:44","0.008"],["2012-05-01 12:01:52","2012-05-01 12:19:17","0.072"],["2012-05-01 14:27:30","2012-05-01 14:27:45","0.004"],["2012-05-01 14:28:02","2012-05-01 14:28:12","0.004"],["2012-05-02 09:20:19","2012-05-02 09:21:19","0.004"],["2012-05-02 09:08:04","2012-05-02 09:19:46","0.048"],["2012-05-02 14:16:54","2012-05-02 14:23:49","0.028"]],"19738424065":[["2012-05-01 14:14:17","2012-05-01 14:18:49","0.02"],["2012-05-01 14:28:24","2012-05-01 14:29:58","0.008"],["2012-05-02 09:21:33","2012-05-02 09:39:27","0.072"]]}
  14. Use strpos to find the position of a character
  15. I found the problem. On line 91 you left off the underscore in $day_count while ( $day_count>1 AND $daycount<=7) { // ^ no underscore
  16. Tested your code and one of your while loops is causing an infinity loop and so no output is ever sent. Have a look at Barands code here for producing a calendar in PHP. http://forums.phpfreaks.com/topic/285347-custom-php-calendar-integer-to-month-string/?do=findComment&comment=1465171
  17. Your code should already do this. That is what nl2br does It wont, however insert line breaks where continuous text hits the boundaries of a textarea. For example your series of v's will appear as the following in the textarea vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv vvvvvvvvvv There is no line break being inserted for the second line, it is the browser forcing the text to next line. The text will be submitted as one long line (exactly as it was typed). A line break will only be submitted when the user presses the enter key. If you want limit text to exactly 70 chars per line, then use wordwrap before nl2br
  18. This is not a regex question, but. You have only posted 147 lines of code. The errors are caused on lines 153 and line 154. These are lines you should be posting (plus about 10 or so lines beforehand)
  19. You should of logged into phpMyAdmin on your old wamp setup and exported all databases. Then on your new wamp setup you'd log into phpmyadmin and import the databases. Simply copying over the database files will not work.
  20. Is that right you close the div tag as soon as you open it? The closing div needs to go after the anchor tags <!-- start of categories list --> <div class="categories en"> <!-- open div --> <a href="../agriculture.html" target="_blank">agriculture</a><br /> <a href="../avantgarde.html" target="_blank">avantgarde</a><br /> <a href="../azyx.html" target="_blank">azyx</a><br /> </div> <!-- close div -->
  21. Output is anything (whitespace, text etc) that is outside of the <?php ?> tags, and what you echo out. You should process any input before you start to output anything, So move your PHP code before your html.
  22. You only want to run the login code when a POST request has been made, example <?php if(isset($_POST['submit')) { // perform login } ?> // display login for <form action="" method="post"> ... <input type="submit" name="submit" value="Login" /> </form> Make sure you do not have any output before you use header().
  23. Have the form submit to itself and then only redirect (using header) when you have confirmed the username/password matches.
  24. If you have numbers assigned to what images to display you can still do away with the ifelse/if. You could set up an array of images assigned to numbers, eg $rating_images = array( 0 => 'nostar.jpg', ... 5 => 'random_image.jpg', ... 20 => 'abottleofwhisky.gif', ... ); Then to output the image you'd do echo "... <img src='../ratings/{$rating_images[ $band['rating'] ]}'/> ..."; Here $band['rating'] is being used as the array key for images. The matching key will then return the image.
  25. Building on gristoi code. Try http://jsfiddle.net/PY5j2/1/
×
×
  • 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.