Hi. The answer to this is probably so simple I'll end up cracking my head on the keyboard later.
Using a very simple example, I have a table with just 2 fields. A primary key consisting of a unique auto-number and a name field. A user would submit their name in a form and the ctahing page will say thanks and show them their unique number. Of course I can't find the unique number by querying against the name, as name's are hardly unique themselves.
Here is my example code. How do I get the $reference variable to be the relevent primary key?
----------------------------------------
Knowing is not enough, we must apply. Willing is not enough, we must do.
--So said the ever wise Bruce Lee
Memorize and live by it!
Using a very simple example, I have a table with just 2 fields. A primary key consisting of a unique auto-number and a name field. A user would submit their name in a form and the ctahing page will say thanks and show them their unique number. Of course I can't find the unique number by querying against the name, as name's are hardly unique themselves.
Here is my example code. How do I get the $reference variable to be the relevent primary key?
Code:
<?php
if (isset($_POST['submit'])) {
$query = 'INSERT INTO table VALUES(default,' .$_POST['name']. ')';
mysql_query($query);
$reference = 'XXXX'; //Where XXXX is the primary key of the record just submitted (i.e. 'id')
echo 'Thank you ' .$_POST['name']. '. Your reference is ' .$reference;
}else{
echo '<p>Submit your name </p>';
echo '
<form action="thispage.php" method="post">
Name: <input type="text" name="name" /><br />
<input type="submit" name="submit" value="Submit your name" />
</form>';
}
?>
----------------------------------------
Knowing is not enough, we must apply. Willing is not enough, we must do.
--So said the ever wise Bruce Lee
Memorize and live by it!