PDA

View Full Version : Duplicate entry '' for key 'PRIMARY'



envisageiam
04-23-2010, 11:50 AM
Can someone please help me with this or point me to a thread with a similar issue:

Im trying to do a simple submit form from a flash file. When I put my php file on to the server and test the file out from my computer locally everything works fine and post to the data base as it should. But when I post my flash site to the server along with the submit php file nothing post.





//PHP:

<?


$host = 'localhost';
$user = '***';
$pass = '***';
$database = '***';

$table = 'loxlicense';

$assigned_number = $_POST['assigned_number'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$salon_name = $_POST['salon_name'];
$cosmetology_license = $_POST['cosmetology_license'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = $_POST['password'];



mysql_connect($host,$user,$pass) or die(mysql_error());
mysql_select_db($database) or die(mysql_error());
$add_all = "INSERT INTO $table values('$assigned_number','$first_name','$last_nam e','$salon_name','$cosmetology_license','$phone',' $email','$username','$password','')";
mysql_query($add_all) or die(mysql_error());



?>








//ActionScript 2 (in flash file, on my submit button:)

on (release){

if (box1.text != "" and box2.text != "" and box3.text != ""and box4.text != ""and box5.text != ""and box6.text != ""and box7.text != ""and box8.text != ""and box9.text != "") {


assigned_number = box1.text;
first_name = box2.text;
last_name = box3.text;
salon_name = box4.text;
cosmetology_license = box5.text;
phone = box6.text;
email = box7.text;
username = box8.text;
password = box9.text;


loadVariablesNum("http://www.loxextensions.com/submit_to_Database.php", 0, "POST");

gotoAndPlay(10);
}


}

shadmego
04-23-2010, 04:30 PM
What I would do is alter the php file to echo every variable set by the submitted form. This will help track down where the issue is. Something like below should do it:



// First check if the $_POST variable has been set and if it is not empty. If variable is emtpy, set to "Nothing Set"
$assigned_number = (isset($_POST['assigned_number']) && !empty($_POST['assigned_number']) ? $_POST['assigned_number'] : "Nothing Set");
$first_name = (isset($_POST['first_name']) && !empty($_POST['first_name']) ? $_POST['first_name'] : "Nothing Set");
$last_name = (isset($_POST['last_name']) && !empty($_POST['last_name']) ? $_POST['last_name'] : "Nothing Set");
// ... etc

// Now echo back all the variable:
echo "<p>Assigned Number: ".$assigned_number."</p>\n";
echo "<p>First Name: ".$first_name."</p>\n";
echo "<p>Last Name: ".$last_name."</p>\n";
// ... etc




Depending on the output of the php file, you will either learn the issue is in the php file or the ActionScript. One thing to look at the the names of the fields in your Flash file. Beyond that, I'm not even a noob with ActionScript, so you will have to find someone else to check that code for accuracy.

Also, try not to post login details for your database next time. Scrub this kind of information from your scripts in the future. Your login details have been "in the wild" now for about 5 hours. There is no telling how many nefarious types have it.

Recommendation: Change your password and username for the database.