Mysql insert only sometimes

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
edwlarkey
Forum Newbie
Posts: 2
Joined: Mon Jun 29, 2009 12:16 pm

Mysql insert only sometimes

Post 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');
 
?>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Mysql insert only sometimes

Post 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?
edwlarkey
Forum Newbie
Posts: 2
Joined: Mon Jun 29, 2009 12:16 pm

Re: Mysql insert only sometimes

Post 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!
Post Reply