Log in

View Full Version : Get Mysql data in to text field



PatrikIden
11-22-2011, 05:36 PM
Hi, i have in my DB a field that is named "Idkod".
And on my Website i have a Regisration form (Only a mail form, but when submitted this mailform creats a Idkod (10 digits).
And also on my Webpage i have a anwering mailform and in this mailform i whant a textfiled whare the reg,user have to enter the 10 didgit Idkod they recived on regisration, and i also whant when clicking submit the mailform to check the DB if that Idkod is in the DB, if so than redirect to thankyou page, if not then redirect to error page.

Thank you.

/Patrik.

fobos
12-20-2011, 03:50 PM
i would suggest using a rand() in your php code



<?php
if (isset($_POST['Submit'])) {
//$random = rand(100000,999999); <-- Generate random number for them. OR
//$raddom = $_POST['idkod']; <-- Use the input field to check against database
$result = mysql_query("SELECT idkod from table where idkod = $random");
$row = mysql_fetch_array($result)
if($row == $random) {
echo "That number already exist";
} else {
query statement for insert, send email, then redirect.
}
}
<input id="idkod" type="input">
<input type="button" value="submit">


Hope this helps. You can figure out the rest.