dolpaz Posted January 7, 2014 Share Posted January 7, 2014 (edited) Hello Guys/GurusPlease I have an issue, am some months into php and i need your help/assistance.This is the flow. a client register at another site, when we confirm the registration, we send them a code.The code is generated and saved in another table name called code.I develop a form (http://cash2money2020.com/form.html)So all i want is if someone inputs the generated code we sent to them, and filled it in the form, it makes a database checks to see if the code exists in the other table, if yes, submit form..if not, error message that the code is invalid and the form will not be submitted:This is the code i have so far which saves the data into the database:$why = $sql->real_escape_string($_POST['why']);$interesting = $sql->real_escape_string($_POST['interesting']);$impressive = $sql->real_escape_string($_POST['impressive']);$code = $sql->real_escape_string($_POST['code']);$query = " INSERT INTO registration (id, why, interesting, impressive, generated_code, submitted_date) VALUES ('', '$why', '$interesting', '$impressive', '$code', now()) ";$sql->query($query) or die($query.''.$sql->error);if($_SERVER['REQUEST_METHOD'] == 'POST')This is where am stucked and i dont know what to do next.Also, this is the code the generates and saves data into the database:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>Untitled Document</title></head><body><?php$sqli = @mysqli_connect ( 'localhost', 'root', 'wisdom', 'cash2money' ) OR die ( mysqli_connect_error() ) ;mysqli_set_charset( $sqli, 'utf8' ) ;//Checking if the user has already validated the form we show the stringif(isset($_POST["submit"])){$length = 10;$randomString = substr(str_shuffle("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), 0, $length);echo "$randomString";}else //If he hadn't show the form{?><form method="post" action=""><input type="submit" name="submit" value="Generate Code" /><input type="hidden" name="code" value="" /></form><?php}$code = $sqli->real_escape_string($_POST['submit']);$query = "INSERT INTO code (id, generated) VALUES ('','$randomString')";$sqli->query($query) or die($query.''.$sql->error);//From here, there is error... but the above code saves the generated code into the database.$result = mysqli_query("SELECT generated FROM code ", $sqli); //guess a COUNT statement should work$row = mysqli_fetch_array($result);$table1 = $result("generated_code `registration`", $sqli);$table2 = $result("generated `code`", $sqli );if( json_encode($table1) == json_encode($table2) ){echo "Code does not match";}else{echo "It matched";}?></body></html>Please who will help me out with the comparison of values between two tables Edited January 7, 2014 by dolpaz Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.