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");
Related
Maybe i am wrong but i can not find anyone who wants to display a json message just in json format from url on the page except for me.
I have a webshop in html, javascript and css. I am looking for some code example to display the json message just on the page. I don't want to parse the json into html or what else. I just want to display the json message as it is like this format: {"success":0,"message":"User not known"}.
This message above is the url response from my php database in xampp.
Below is my code and it works good, the problem is that this code is static. I am looking for some dynamic solution where you enter the url and it responds with json message. Any help is appriciated.
this is my login.html
if(form.id.value == "" || form.pass.value == "") {
alert("Empty details!");
}else if (form.id.value=="johan" && form.pass.value=="123") {
location="Page2.html"
} else { alert("Wrong username or password!")
}
}
and this is the json read:
// 1 - read josn:
var my_json_output = {"success":1,"message":"Vol","Username":"jan","UserSurname":"janman"}',
json_yes.succes json_yes = JSON.parse(my_json_output);
var my_json_output = '{"success":0,"message":"User_Unknown"}',
json_no = JSON.parse(my_json_output);
if(json_no.success == 1) { alert("Welcome, " + s + json_yes.Username);
}else if(json_no.success == 0) { alert("Try again");
}
Now i could find the answer and will share with others: just make a variable from XMLHttpRequest(); and use that variable for the message:
myconnect = new XMLHttpRequest();
I've been stuck with this problem for a day now. I think I'm overlooking something simple but I can't see it.
I am developing a web application where the user fills up forms and the forms get saved in the database. However, I'm having a problem inserting values to a form. The database does not update and I get a 500 Internal Server Error at the console.
Here is the controller that I call when the user saves the form that was filled up
var personStore = Ext.getStore('personBaseDetails');
var caStore = Ext.getStore('creditApplication');
var form = button.up('form').getForm();
var id = personStore.first().get('ID');
//use this to update
if(caStore.count() < 1){
var creditApplication = Ext.ModelManager.create({
}, 'app.model.creditApplicationModel');
caStore.add(creditApplication);
}
var record = caStore.first();
form.updateRecord(record);
caStore.getProxy().extraParams = {
selectedUserID: id
};
caStore.sync({
success: function(batch) {
console.log(batch.operations[0].request.scope.reader.jsonData['message']);
},
failure: function(batch) {
console.log("Failed syncing ca");
}
});
I have checked with various console.log statements that all of the variables here have the proper values.
Here is the php file that gives the 500 Internal Server Error problem:
<?php
require_once('../../db_connection.php');
require_once '../../lib/response.php';
require_once '../../lib/request.php';
class creditApplication{
var $ID_PERSON;
var $APPLICATION_TYPE;
var $APPLICATION_SUB_TYPE;
var $APPLICATION_NUMBER;
var $CUSTOMER_NUMBER;
var $DATE;
var $STATUS;
var $ID_UNIT;
}
$request = new Request(array());
if(isset($request->params)){
var $selectedCustomer = '';
if(isset($_GET['selectedUserID'])){
$selectedCustomer = $_GET['selectedUserID'];
$array_r=$request->params;
$inputData = new creditApplication();
$inputData->ID_PERSON=$selectedCustomer;
$inputData->APPLICATION_TYPE=($array_r->APPLICATION_TYPE);
$inputData->APPLICATION_SUB_TYPE=($array_r->APPLICATION_SUB_TYPE);
$inputData->APPLICATION_NUMBER='sample application number';
$inputData->CUSTOMER_NUMBER='sample customer number';
$inputData->DATE='2014-4-4';
$inputData->STATUS=42;
$inputData->ID_UNIT='sampleUnit';
$query="INSERT INTO CREDIT_APPLICATION (ID_PERSON, APPLICATION_TYPE, APPLICATION_SUB_TYPE, APPLICATION_NUMBER,
CUSTOMER_NUMBER, DATE, STATUS, ID_UNIT)
VALUES ($inputData->ID_PERSON,
'$inputData->APPLICATION_TYPE',
'$inputData->APPLICATION_SUB_TYPE',
'$inputData->APPLICATION_NUMBER',
'$inputData->CUSTOMER_NUMBER',
'$inputData->DATE',
$inputData->STATUS,
'$inputData->ID_UNIT')";
$result = mysql_query($query);
//object response
$res = new Response();
$res->success = true;
$res->message = "Created user";
print_r($res->to_json());
}
else{
$res = new Response();
$res->success = false;
$res->message = "Error - no userID";
$res->data = array();
print_r($res->to_json());
}
}
else{
$res = new Response();
$res->success = false;
$res->message = "Error - no request";
$res->data = array();
print_r($res->to_json());
}
?>
All the database rows are varchars except for ID_PERSON and STATUS which are ints (hence the single quotes in the insert) and the DATE which is of date format.
Now, I've tried hard coding the values, commenting out the if else conditions, and calling the php file through localhost:8888/..../createCreditApplication.php and it actually works. The problem happens when I bring back the if-else blocks and get the values passed to the php file.
I appreciate any help.
Currently blank rows are being entered into my mySQL database. Undefined index is what I'm getting for Name and Address in the PHP. I'm using the javaScript code as part of a function. The user will activate this function and this adding to the database will happen seemless behind the scenes.
How can I get the values to enter the mySQL.
PHP Code,
<?php
$connection = mysqli_connect("localhost", "user", "pass", "db");
$name = $_POST['Name'];
$address = $_POST['Address'];
mysqli_query($connection,"INSERT INTO offerSelected (Id, Url) VALUES ('".$name."','".$address."')");
?>
JavaScript
var name = "John";
var address = "UK";
var sendInfo = {
Name: name,
Address: address
};
var params = JSON.stringify(sendInfo);
alert(params);
var httpSend = new XMLHttpRequest();
var php = "http://server/~name/folder/insertOffer.php";
httpSend.open("POST", php, true);
httpSend.onreadystatechange = function()
{
if(httpSend.readyState == 4 && httpSend.status == 200) {
alert("sent");
}
}
httpSend.send(params);
UPDATED
var params = 'Name=' + name + '&Address=' + address;
alert(params);
var httpSend = new XMLHttpRequest();
var php = "http://server/~name/folder/insertOffer.php";
httpSend.open("POST", php, true);
httpSend.onreadystatechange = function()
{
if(httpSend.readyState == 4 && httpSend.status == 200) {
alert("h");
}
}
httpSend.send(params);
Apart from the SQL injection problems people mentioned in the comments, the problem with your code is JSON.stringify. The POST parameters use a key-value format just like GET requests, which means your params should look like this:
Name=name&Address=address
And not a JSON object. You also have to add this line of code after httpSend.open to tell the server that you are sending key/values:
httpSend.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
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");
i am having strange issue with Flash and PHP. actually i have one Forgot password form in flash in which user enters his email id and when presses submit button flash passes data to PHP and retrieves(here i am stuck) data from PHP.
The issue is Flash getting UNDEFINED from PHP.
my flash code.
var email_id:RegExp = /(\w|[_.\-])+#((\w|-)+\.)+\w{2,4}+/;
var urlRequest:URLRequest = new URLRequest("forgot_password.php");
var urlVariable:URLVariables = new URLVariables();
var urlLoader:URLLoader = new URLLoader();
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
urlLoader.addEventListener(Event.COMPLETE, urlLoader_complete);
btn_submit.addEventListener(MouseEvent.CLICK, btn_submit_click);
function btn_submit_click(e:Event)
{
if(txt_email.text == "")
{
txt_error.text = "Email can not be blank.";
}
else if(!email_id.test(txt_email.text))
{
txt_error.text = "Enter proper email address.";
}
else
{
urlVariable.mailId = txt_email.text;
urlRequest.data = urlVariable;
urlLoader.load(urlRequest);
}
}
function urlLoader_complete(e:Event)
{
trace(e.target.data.return_var); // **it receive Undefined** i am checking in flashlog.txt :(
//txt_error.text = e.target.data.return_var;
}
my PHP code
<?php
require_once('connection.php');
$query = "select * from user_account where email='".$_REQUEST['mailId']."'";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0)
{
echo "return_var=success";
}
else
{
echo "return_var=failed";
}
?>
there is a space before return_var but i don't know why.. i have checked my PHP file 100 times it is perfect than what is the issue??????????????????????????????????????????
EDIT:
If i am tracing
trace(e.target.data);
it traces
%20return%5Fvar=success
Note %20 before return%5var // what is that?????????????
Obviously problem isn't in PHP, anyway you should write it something like this to prevent SQL injection...
<?php
require_once 'connection.php';
$email = $_GET['mailId'];
$email = mysql_real_escape_string($email);
$query = "SELECT email FROM user_account WHERE email = '$email' LIMIT 1";
$result = mysql_query($query);
echo (mysql_num_rows($result) > 0)? 'return_var=success': 'return_var=failed';
?>
Remove this line:
urlLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
and change your urlLoader_complete() function to:
function urlLoader_complete(e:Event)
{
var loader:URLLoader = URLLoader(e.target);
var vars:URLVariables = new URLVariables(loader.data);
trace(vars.return_var);
}
does that help?
First of all thank you all for your contributions.
Now the issue was not related with Flash or PHP but it was related with our server. if i am creating PHP file and directly saving on our server than that PHP file gives response with adding one space before variable name. and if i am creating PHP file and saving it in my local drive and than pasting it on my server it works perfectly!!!!!!!!!!!!!!!!!
see the response difference between two files..............
return_var=success
return_var=success // adding space before response.
may be its issue related with memory but now its working fine so cheers!!!!!!!!!
Again many Thanx.