Page 1 of 1

Mysql insert only sometimes

Posted: Mon Jun 29, 2009 12:20 pm
by edwlarkey
I have this form that calls this php script (below) and it only works sometimes. If I try to send the form again it works and if I try again it fails and again it fails. It is very hit or miss. Could someone please tell me why it does this. Thanks

Code: Select all

<?php
$name = "name";
$invoice = "invoice";
$type = "type";
$source = "ccnum";
$fp = fopen("******************","r");
$pub_key = fread($fp,8192);
fclose($fp);
openssl_get_publickey($pub_key);
 
openssl_public_encrypt($source,$crypttext,$pub_key);
 
mysql_connect ("***********", "***************", "***************") or die ('Error: ' . mysql_error());
mysql_select_db ("test_cards");
 
$query="INSERT INTO cardinfo (name, type, ccnum, invoice)VALUES ('$_POST[name]','$_POST[type]','".$crypttext."','$_POST[invoice]')" or die(mysql_error());
                    
mysql_query($query) or die('Unable to insert credit card data');
 
?>

Re: Mysql insert only sometimes

Posted: Mon Jun 29, 2009 1:18 pm
by requinix
What does "fail" mean? You get an error message from PHP? From your code? Nothing but the INSERT doesn't work?
Have you tried printing the query to see what it is, if it's valid?
Have you done any debugging at all?

Re: Mysql insert only sometimes

Posted: Mon Jun 29, 2009 1:36 pm
by edwlarkey
McInfo wrote:Your encrypted text might occasionally contain characters that need to be escaped (like quotes). Use mysql_real_escape_string().

Thank you so much! Works every time!