Help with extracting data from table!

Hello!

Terribly sorry for the likely simplicity of my query, I’m just starting to get my feet wet with MySQL.

Basically, the situation is this: I’m setting up a page for a friend. The overall programming of the page is to monitor and distribute PINs after a purchase is made. I have that bit done fine, the problem is that using the same receipt code, they could receive multiple PINs. I solved this problem by having the web page’s PHP coding pull the PIN out of the first table, delete that entry from the first table, then insert it into a second table, along with the Receipt Number that authenticated the purchase. Then, the plan for the web page was to have it First check the second table to see if such a Reciept Code (as passed to the page) had been used before. If it had, it is to return the previously issued PIN, thank the user, and end. If not, it is to authenticate the Reciept Code, issue a new PIN, and do the rest of the rigamaroll (that already does work, I’ve tested it repeatedly.)

So, to keep you from trudging through the code that does work, here’s the bit that I’m having a problem with.

[code]<?php
$host=“MyIP”;
$usrnm=“username”;
$passwrd=“password”;
$database=“database”;
$con=mysql_connect($host,$usrnm,$passwrd) or die("Connection failed!!!
");
$varselect=mysql_select_db($database) or die(“Database selection failed!!!”);

/* Check if Reciept Code Seen Before */
$tablename="cbDistributedPINs";
$query="SELECT * FROM " . $tablename . " WHERE `rcptnum` = '" . $cbreciept . " LIMIT 1'";
$result=mysql_query($query);
if (!$result) { die("Query problem checking for existing record."); }
$row=mysql_fetch_assoc($result);

/* Reciept Code Seen Before */
if ($row['numrecords'] >= 1){
    echo 'Your Reciept Code was seen before.  Your PIN Number is ' . /*INSERT PIN NUMBER FROM ROW HERE*/ . '.<br />';
}
/* END Reciept Code Seen Before */

/* Reciept Code Not Seen Before */
else {

    /* Distribute New PIN Number & Email Notifications (code works fine) */

}/* (end the else) */
/* END Reciept Code Not Seen Before */

?>[/code]

I’m not precisely sure what needs changing, but I need to know how to extract that PIN number from the row selected by Reciept Number.

I think I’m being clear, but it’s very possible I’m being about as clear as a brick wall. Please ask me anything that may clarify the situation, and thank you in advance for any help that you’d be willing to offer!

I am not really sure what you are asking for.

Could you try the following after line 11:

echo $query;

and post the results? It looks like you’re messing up with single quotes in your query.

Sponsor our Newsletter | Privacy Policy | Terms of Service