I've been to almost every forum possible with this question (including this one). I almost got the answer to my question. The problem is no one seems to figure out my problem because everything looks right, and everything looks right to me too. Can someone please help me? Here are my codes.
Flash Code:
var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();
register_button.onRelease = function(){
var valid:Boolean = validateForm();
if (valid) {
//gather information and put in loadvars object
lvSend.username = username1.text;
lvSend.password = password1.text;
lvSend.email = email1.text;
lvSend.sendAndLoad("register.php", lvReceive, "POST");
gotoAndStop(1);
}
};
lvReceive.onLoad = function(success:Boolean) {
if (success) {
username1.text = "";
password1.text = "";
email1.text = "";
}
}
function validateForm():Boolean {
if (username1.text == "" || password1.text == "" || email1.text == "") {
return false;
}
return true;
}
Php Code:
http://i.stack.imgur.com/RXPWb.png
(Sorry its in link form)
Please favorite this or something until I get an answer because I've been everywhere and no one could help me. :/ BTW I have been getting a few blank entries into my database but I don't know why. Also, the lvReceive function doesn't seem to work, but when I add the username1.text = ""; into the register_button function it seems to clear the text fields. Please help me. I left the database info on the php file cause I thought maybe the database I entered could be the problem, but I did use this php code with an html file and it worked fine. I will accept any answers. Thanks in advance! :D
lvSend.sendAndLoad("register.php", lvReceive, "POST");
You put the information in lvSend and not in lvReceive.
Perhaps you should put the information in lvReceive:
lvReceive.username = username1.text;
lvReceive.password = password1.text;
lvReceive.email = email1.text;
lvSend.sendAndLoad("register.php", lvReceive, "POST");
Related
I've an application in PHP 4.3.9 and I've a problem with SESSION.
When I put a variable SESSION in an other variable, like this :
$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] content is removed.
I don't understand why. Is a PHP4 particularity ?
EDIT
I tried many case to found where exactly I lose my content and this is in a foreach :
reset($tempInsInscription);
foreach($tempInsInscription as $key => $ins_inscription){
if(is_array($ins_inscription)){
reset($ins_inscription);
foreach($ins_inscription as $key_etape => $etape){
$_SESSION["dossier"][$key_etape]=$etape;
}
}else{
$_SESSION["dossier"][$key]=$ins_inscription;
}
}
SOLUTION
I found a solution to solve my problem. here my new code & it's works perfectly :
$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] = $tempInsInscription;
reset($tempInsInscription);
while(list($key, $ins_inscription) = each($tempInsInscription)) {
if(is_array($ins_inscription)){
reset($ins_inscription);
while(list($key_etape, $value_etape) = each($ins_inscription)) {
$dossier[$key_etape]=$value_etape;
}
}else{
$dossier[$key]=$ins_inscription;
}
}
SOLUTION
I found a solution to solve my problem. here my new code & it's works perfectly :
$tempInsInscription = $_SESSION['ins_inscription'];
$_SESSION['ins_inscription'] = $tempInsInscription;
reset($tempInsInscription);
while(list($key, $ins_inscription) = each($tempInsInscription)) {
if(is_array($ins_inscription)){
reset($ins_inscription);
while(list($key_etape, $value_etape) = each($ins_inscription)) {
$dossier[$key_etape]=$value_etape;
}
}else{
$dossier[$key]=$ins_inscription;
}
}
My script is working most of the times, but in every 8th try or so I get an error. I'll try and explain this. This is the error I get (or similar):
{"gameName":"F1 2011","gameTrailer":"http://cdn.akamai.steamstatic.com/steam/apps/81163/movie_max.webm?t=1447354814","gameId":"44360","finalPrice":1499,"genres":"Racing"}
{"gameName":"Starscape","gameTrailer":"http://cdn.akamai.steamstatic.com/steam/apps/900679/movie_max.webm?t=1447351523","gameId":"20700","finalPrice":999,"genres":"Action"}
Warning: file_get_contents(http://store.steampowered.com/api/appdetails?appids=400160): failed to open stream: HTTP request failed! in C:\xampp\htdocs\GoStrap\game.php on line 19
{"gameName":"DRAGON: A Game About a Dragon","gameTrailer":"http://cdn.akamai.steamstatic.com/steam/apps/2038811/movie_max.webm?t=1447373449","gameId":"351150","finalPrice":599,"genres":"Adventure"}
{"gameName":"Monster Mash","gameTrailer":"http://cdn.akamai.steamstatic.com/steam/apps/900919/movie_max.webm?t=1447352342","gameId":"36210","finalPrice":449,"genres":"Casual"}
I'm making an application that fetches information on a random Steam game from the Steam store. It's quite simple.
The script takes a (somewhat) random ID from a text file (working for sure)
The ID is added to the ending of an URL for the API, and uses file_get_contents to fetch the file. It then decodes json. (might be the problem somehow)
Search for my specified data. Final price & movie webm is not always there, hence the if(!isset())
Decide final price and ship back to ajax on index.php
The error code above suggests that I get the data I need in 4 cases, and an error once. I only wanna receive ONE json string and return it, and only in-case $game['gameTrailer'] and $game['final_price'] is set.
This is the php (it's not great, be kind):
<?php
//Run the script on ajax call
if(isset($_POST)) {
fetchGame();
}
function fetchGame() {
$gameFound = false;
while(!$gameFound) {
////////// ID-picker //////////
$f_contents = file("steam.txt");
$url = $f_contents[mt_rand(0, count($f_contents) - 1)];
$answer = explode('/',$url);
$gameID = $answer[4];
$trimmed = trim($gameID);
////////// Fetch game //////////
$json = file_get_contents('http://store.steampowered.com/api/appdetails?appids='.$trimmed);
$game_json = json_decode($json, true);
if(!isset($game_json[$trimmed]['data']['movies'][0]['webm']['max']) || !isset($game_json[$trimmed]['data']['price_overview']['final'])) {
continue;
}
$gameFound = true;
////////// Store variables //////////
$game['gameName'] = $game_json[$trimmed]['data']['name'];
$game['gameTrailer'] = $game_json[$trimmed]['data']['movies'][0]['webm']['max'];
$game['gameId'] = $trimmed;
$game['free'] = $game_json[$trimmed]['data']['is_free'];
$game['price'] = $game_json[$trimmed]['data']['price_overview']['final'];
$game['genres'] = $game_json[$trimmed]['data']['genres'][0]['description'];
if ($game['free'] == TRUE) {
$game['final_price'] = "Free";
} elseif($game['free'] == FALSE || $game['final_price'] != NULL) {
$game['final_price'] = $game['price'];
} else {
$game['final_price'] = "-";
}
}
////////// Return to AJAX (index.php) //////////
echo
json_encode(array(
'gameName' => $game['gameName'],
'gameTrailer' => $game['gameTrailer'],
'gameId' => $game['gameId'],
'finalPrice' => $game['final_price'],
'genres' => $game['genres'],
))
;
}
?>
Any help will be appreciated. Like, are there obvious reason as to why this is happening? Is there a significantly better way? Why is it re-iterating itself at least 4 times when it seems to have fetched that data I need? Sorry if this post is long, just trying to be detailed with a lacking php/json-vocabulary.
Kind regards, John
EDIT:
Sometimes it returns no error, just multiple objects:
{"gameName":"Prime World: Defenders","gameTrailer":"http://cdn.akamai.steamstatic.com/steam/apps/2028642/movie_max.webm?t=1447357836","gameId":"235360","finalPrice":899,"genres":"Casual"}
{"gameName":"Grand Ages: Rome","gameTrailer":"http://cdn.akamai.steamstatic.com/steam/apps/5190/movie_max.webm?t=1447351683","gameId":"23450","finalPrice":999,"genres":"Simulation"}
I have a strange problem with Google Captcha. I've tried all kinds of php codes from different tutorials, but the result is exactly the same every time...
The problem is this:
it shows up correctly
if you check the box, it works correctly
if you then send the form it works correctly
but... if you don't check the box, the form is still sent!
So, in other words, it's only on the form as a decorative piece. What could be the problem? It's probably something very simple, but I'm totally missing it.
Help or insights are very much appreciated! Thanks in advance!
Addendum
The following is the code that came with the template I used:
require_once('recaptcha-php-1.11/recaptchalib.php');
if ($use_captcha == 1) {
$resp = null;
$error = null;
$reCaptcha = new ReCaptcha($secret);
$secret = "MY SECRET KEY HERE";
$captcha_error_message = '<div class="pi-alert-danger fade in"><button type="button" class="pi-close" data-dismiss="alert"><i class="icon-cancel"></i></button><p>Bewijs dat je geen robot bent!</p></div>';
if (isset($_POST["captcha_response"]) && $_POST["captcha_response"] != '') {
$resp = $reCaptcha->verifyResponse(
$_SERVER["REMOTE_ADDR"],
$_POST["captcha_response"]
);
if ($resp && $resp->success != true) {
echo $captcha_error_message;
exit();
}
} else {
echo $captcha_error_message;
exit();
}
}
You have to check if the captcha was solved (at your PHP-Script which do anything with the Form-data)
Like this:
function checkCaptcha($recaptchaResponse) {
$recaptchaPrivateKey = 'Your Private Key';
if(! $recaptchaResponse)
return false;
$recaptchaObj = new ReCaptcha($recaptchaPrivateKey);
$response = $recaptchaObj->verifyResponse($_SERVER["REMOTE_ADDR"], $recaptchaResponse);
if($response != null && $response->success)
return true;
return false;
}
If you don't include a function like this to your form function, your server will say, the form is okay, because it don't know about the captcha.
Note, that you have to include the Google-captcha Libarys-File as well. You can find it here:
https://github.com/google/recaptcha/blob/1.0.0/php/recaptchalib.php (Worked for NoCaptcha as well)
I need help with my flash registration form. I made sure all my information is correct, but when I enter the information, it doesn't seem to enter it into the mysql database. Here is the flash code:
var lvSend:LoadVars = new LoadVars();
var lvReceive:LoadVars = new LoadVars();
register_btn.onRelease = function() {
var valid:Boolean = validateForm();
if(valid){
//gather information and put in loadvars object
lvSend.username = username.tInput.text;
lvSend.password = password.tInput.text;
lvSend.email = email.tInput.text;
//send information php script for insertion into database
lvSend.sendAndLoad("register.php", "POST");
}
};
function validateForm():Boolean{
if(username.tInput.text == "" || password.tInput.text == "" || email.tInput.text == ""){
return false;
}
return true;
}
function clearTextFields():Void{
username.tInput.text = "";
password.tInput.text = "";
email.tInput.text = "";
}
Here is the Php Code:
http://i.stack.imgur.com/cvvcO.png
Sorry that my code is in picture form. That was the best way I could make it readable by you guys.My problem is that all the information in both codes seem correct. All my text fields are called username, password, and email, same goes for the database columns. The database info isn't wrong because I used the php code with html, I just can't get it to work with flash. My php file is called register.php and my flash file is called play.swf. Thanks for your help!
try:
lvReceive.onLoad = function(success:Boolean) {
if (success) {
trace("ok");
}
else {
trace("error");
}
lvSend.sendAndLoad("register.php", lvReceive, "POST");
So I must be missing something. I can retrieve the zpid and the zestimate no problem doing the following:
$zdata->response->zpid; //zpid
$zdata->response->zestimate->amount; //zestimate
But then when I try what appears to be the obvious equivalent to retrieve a part of the address:
$zdata->response->address->street;
$zdata->response->address->city;
None of it works! Why?? Clearly I must be missing something here. Below is my entire code
<?php
$zillow_id = '1234';
$search = $_POST['address'];
$citystate = $_POST['csz'];
$address = urlencode($search);
$citystatezip = urlencode($citystate);
$url = "http://www.zillow.com/webservice/GetSearchResults.htm?zws-id=".$zillow_id."&address=".$address."&citystatezip=".$citystatezip;
$result = file_get_contents($url);
$data = simplexml_load_string($result);
$zpidNum = $data->response->results->result[0]->zpid;
$zurl = "http://www.zillow.com/webservice/GetZestimate.htm?zws-id=".$zillow_id."&zpid=".$zpidNum;
$zresult = file_get_contents($zurl);
$zdata = simplexml_load_string($zresult);
//echo $zdata->response->zestimate->amount;
//$zestimate=$zdata->response->zestimate->amount;
$zstreet=$zdata->response->address->street;
echo $street;
?>
Looking at the XML output as seen on Zillow's own documentation, I am following the same pattern to try to get the street as to get the zestimate. I am not very familiar with working with XML so it is very possible I am missing something.
So I am getting an error in my console that shows the following:
Uncaught SyntaxError: Unexpected token T
The 'T' seems to be the first letter of the street that is entered, as it changes accordingly. Perhaps this could shine some light on the issue?
I'll post my AJAX too but I don't know why there would be something wrong with it. As stated above, I am able to display the ZPID and Zestimate just fine, only the address isn't working.
AJAX/JS:
function validateAddress(){
var address = document.getElementById('address').value;
var csz = document.getElementById('city_state_zip').value;
if (address == null || address == "" || csz == null || csz == "") {
return false;
}
else{
getZestimate(address,csz);
}
}
function getZestimate(address,csz){
var xmlhttp = new XMLHttpRequest();
var userdata = "address="+address+"&csz="+csz;
xmlhttp.open("POST","../wp-content/themes/realhomes/submit_address.php",true);
xmlhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xmlhttp.onreadystatechange = function(){
if(xmlhttp.readyState == 4 && xmlhttp.status == 200){
//retrieve = JSON.parse(xmlhttp.responseText);
retrieve = xmlhttp.responseText;
document.getElementById("zestimateArea").innerHTML = '<div id="zillowWrap"><img src="http://www.zillow.com/widgets/GetVersionedResource.htm?path=/static/logos/Zillowlogo_150x40.gif" width="150" height="40" alt="Zillow Real Estate Search" id="ZillowLogo" /><span id="zestimateTag">Zestimate®</span></div><span id="zestimatePrice">'+retrieve+'</span><div id="zillowDisclaimer"><span>© Zillow, Inc., 2006-2014. Use is subject to Terms of Use</span><span>What’s a Zestimate?';
}
else{
document.getElementById("zestimateArea").innerHTML = "Error!"
}
}
xmlhttp.send(userdata);
document.getElementById("zestimateArea").innerHTML = "Generating...";
return false;
}
So when I went to post my AJAX as a last ditch effort for help I had seen I still had this line of code:
retrieve = JSON.parse(xmlhttp.responseText);
As Daedalus helpfully explained, this wasn't an issue when I was retrieving integers but posed a problem when I was retrieving text. I had originally put that line of code in when I was trying to retrieve both the Zestimate and the address together in an array encoded with JSON. When it was unsuccessful I took a step back to see if I could retrieve the address individually with no success. I never thought twice about that line of code since the AJAX still seemed to work fine.
Hence the perplexing outcome.
Changing that line back to:
retrieve = xmlhttp.responseText;
Allowed me to retrieve the address with success.
Don't you had simple mistakes that cause huge problems? Back to figuring out why the JSON encode and parsing wasn't working, but that's a question for a different post.