Jump to content

PHP MySQL db issues


g0mab2

Recommended Posts

Hello,

I have been trying to get my php file to save data to mysql db, but it hasn't worked yet.  Can anyone please tell me what I am doing wrong, I am trying this for the first time and I am relatively new to php and mysql.

Thank you all in advance.

 

actionscript

import fl.controls.RadioButton
import fl.controls.RadioButtonGroup;
     //hide processing MC
processing_mc.visible=false;
     //custom function to populate the combobox lists
function addCountriesToList():void{
countryList.addItem({label: "United States"});
countryList.addItem({label: "Mexico"});
countryList.addItem({label: "Canada"});
countryList.addItem({label: "United Kingdom"});
     //run function above now
}
addCountriesToList();
     //custom function to populate the combobox lists
function addViewableByToList():void{
viewableList.addItem({label: "Everyone"});
viewableList.addItem({label: "Friends Only"});
viewableList.addItem({label: "Only Me"});
}
     //run function above now
addViewableByToList();
     // make radio button group distiction
var radioGroup1:RadioButtonGroup = new RadioButtonGroup("radioGroupGender");
radioMale.group = radioGroup1;
radioFemale.group = radioGroup1;
     // build variable name for the URL Variables loader
var variables:URLVariables = new URLVariables;
     // Build the varSend variable
var varSend:URLRequest = new URLRequest("face.php");
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
     // Build the varLoader variable
var varLoader:URLLoader = new URLLoader;
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
varLoader.addEventListener(Event.COMPLETE, completeHandler);
     //handler for the PHP script completion and return of status
function completeHandler(event:Event):void {
// remove processing clip
processing_mc.visible = false;
fname_txt.text = "";
lname_txt.text = "";
email_txt.text = "";
month_txt.value = 1;
day_txt.value = 1;
year_txt.value = 1965;
uname_txt.text = "";
passwd_txt.text = "";
repasswd_txt.text = "";
favactor_txt.text = "";
favmovie_txt.text = "";
favtv_txt.text = "";
favmusic_txt.text = "";
favartist_txt.text = "";
favsport_txt.text="";
favteam_txt.text = "";
favathlete_txt.text = "";
checkbox.selected = false;
     // Load the response from php here
status_txt.text = event.target.data.return_msg;
}
     // Add event listener for submit button click
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
     // function ValidateAndSend
function ValidateAndSend (event:MouseEvent):void {
//validate fields
if(!fname_txt.length){
	status_txt.text = "Please Enter Your First Name";
} else if(!lname_txt.length){
	status_txt.text = "Please Enter Your Last Name";
	} else if(!email_txt.length){
	status_txt.text = "Please Enter a Valid Email Address";
	} else if(!uname_txt.length){
	status_txt.text = "Please Create a Username";
	} else if(!passwd_txt.length){
	status_txt.text = "Please Create a Password";
	} else if(!repasswd_txt.length){
	status_txt.text = "Please Create a Password";
	} else {
// All is good, send the data now to PHP
	processing_mc.visible = true;
		variables.fname_txt = fname_txt.text;
		variables.lname_txt = lname_txt.text;
		variables.countryList = countryList.value;
		variables.email_txt = email_txt.text;
		variables.month_txt = month_txt.value;
		variables.day_txt = day_txt.value;
		variables.year_txt = year_txt.value;
		variables.uname_txt = uname_txt.text;
		variables.passwd_txt = passwd_txt.text;
		variables.repasswd_txt = repasswd_txt.text;
		variables.radioGroup1 = radioGroup1.selection.value;
		variables.viewableList = viewableList.value;
		variables.favactor_txt = favactor_txt.text;
		variables.favmovie_txt = favmovie_txt.text;
		variables.favtv_txt = favtv_txt.text;
		variables.favmusic_txt = favmusic_txt.text;
		variables.favartist_txt = favartist_txt.text;
		variables.favsport_txt = favsport_txt.text;
		variables.favteam_txt = favteam_txt.text;
		variables.favathlete_txt = favathlete_txt.text;
		variables.checkbox = checkbox.selected;
	// Send the data to PHP now
	varLoader.load(varSend);
} // close else condition for error handling
} // close validate and send function

<?php

   //Connection to database
$username="apples";
$password="apples";
$database="apples";
   //Capture data from $_POST array
   $fname_txt = $_POST['fname_txt'];
   $lname_txt = $_POST['lname_txt'];
   $countryList = $_POST['countryList'];
   $email_txt = $_POST['email_txt'];
   $month_txt = $_POST['month_txt'];
   $day_txt = $_POST['day_txt'];
   $year_txt = $_POST['year_txt'];
   $uname_txt = $_POST['uname_txt'];
   $passwd_txt = $_POST['passwd_txt'];
   $repasswd_txt = $_POST['repasswd_txt'];
   $radioGroup1 = $_POST['radioGroup1'];
   $viewableList = $_POST['viewableList'];
   $favactor_txt = $_POST['favactor_txt'];
   $favmovie_txt = $_POST['favmovie_txt'];
   $favtv_txt = $_POST['favtv_txt'];
   $favmusic_txt = $_POST['favmusic_txt'];
   $favartist_txt = $_POST['favartist_txt'];
   $favsport_txt = $_POST['favsport_txt'];
   $favteam_txt = $_POST['favteam_txt'];
   $favathlete_txt = $_POST['favathlete_txt'];
   $checkbox = $_POST['checkbox'];
mysql_connect("localhost",$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
   //Perform the query
   $query = "INSERT INTO infodb VALUES(",'$fname_txt','$lname_txt','$countryList','$email_txt','$month_txt','$day_txt','$year_txt','$uname_txt','$passwd_txt','$repasswd_txt','$radioGroup1','$viewableList','$favactor_txt','$favmovie_txt','$favtv_txt','$favmusic_txt','$favartist_txt','$favsport_txt','$favteam_txt','$favathlete_txt','$checkbox')";
mysql_query($query);
  mysql_close();
?>

Link to comment
Share on other sites

You need to debug your query.

 

if (!mysql_query($query)) {
  trigger_error(mysql_error() . " " $query);
}

 

ps: I reformatted your code so it was at a readable size and posted within


tags. I'm not sure why you would make it so small that it couldn't be read.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.