Hello,
I am new to PHP, I only started to read books and watch video online.
I do apologies if my code is incorrect and added in a stupid way but I did my maximum with whatever I have learned till now.
I am having a real problem, I have created 2 forms, the first form takes the data of the users and then pass them to the next form using sessions. Now on the second form, I need to take the final data, send it to mysql and return an error if the phone number is not unique(if the user has already registered).
Any idea how to do this please?
The code works well apart form this.
Also, at the end of the execution, I need the page to be redirected to the first page, which is why I use an header redirect.
Please help keep looking online for a solution but get completely mixed up.
On this form I only have:
<?php session_start();// store session data//echo $_COOKIE['PHPSESSID'];$code = trim($_POST['code']);require_once("header.php");//if ($code != $_SESSION['random'])//{//Echo '<br><br>You should have now receive a Code via sms</br>';// Echo 'Please enter Your Mobile Code in the Box!</br>';// Echo 'If no Mobile Code have been received, contact email.....</br>';//}else{//echo ' There was an error, please go back and try again';//}?><!DOCTYPE HTML><head><link type="text/css" rel="stylesheet" href="jotform.css" /></head><body><div align="center"><form action="" method="post" enctype="application/x-www-form-urlencoded"><div class="form-all"><ul class="form-section"><div class="form-line" id="id_1"><input type="text" name="email" value="<?php echo $_SESSION["email"];?>" type="text" /><input type="text" name="phone" value="<?php echo $_SESSION['prefix'];?><?php echo $_SESSION['phone'];?>" type="text" /><div class="form-label-top">Type in Your Mobile Code<br />Awaiting for Validation</div><div id="cid_1" class="form-input-wide"><input class=" form-textbox" name="code" value="" type="text" maxlength="6" /><br /><img src="awaiting-loading.gif" width="105" height="16" /></div><br /><div><textarea class="textarea" id="textarea" readonly="readonly" rows="7" cols="68">Terms and Conditions ForMemberskhkhjkjhkjhkhkjhkjhkjh</textarea></div></br><input class=" form-textbox" type="checkbox" name="terms" /><span id="form-tickbox-text">I have read and agree to the Terms and Conditions</span></br><input class=" form-textbox" type="checkbox" name="agree" /><span id="form-tickbox-text">Yes I agree to receive VIP notifications</span></br><input type="hidden" name="submitted" value="1"/><input name="submit" type="submit" value="Register Now!" class="form-submit-button form-submit-button-flat_round_teal"/><br /><br /></div></form><?php echo $_SESSION['random']; ?></div></body></html>
Here it is:
On my second form page, I have "require_once("header.php");" at the top. The below code is for the header.php page
<php>
<?php$host="localhost"; // Host name$username="---------------"; // Mysql username$password="----------------"; // Mysql password$db_name="----------------"; // Database name$tbl_name="-----------------"; // Table name$random = trim($_POST['code']);$phone = trim($_POST['phone']);$email = trim($_POST['email']);//$session_random = trim($_SESSION['random']);//If hidden field is submittedif ( isset($_POST['submitted']) && $_POST['submitted']==1){$email_sanitize= $email ;if(filter_var($email_sanitize, FILTER_VALIDATE_EMAIL) == FALSE) {echo '<div align="center" class="text-not-correct">Error:xx001 There is an error with the form please try again</div></br>';}else{if(strlen($phone) !== 11){echo '<div align="center" class="text-not-correct">Error: xx002 There is an error with the form please try again</div></br>';}else{if(empty($email_sanitize)){$errorMessage .= '<div align="center" class="text-not-correct">Error: xx003 There is an error with the form please try again</div></br>';}else{if ($random != $_SESSION['random']){echo '<div align="center" class="text-not-correct">Your Mobile code is incorrect - Please try again</div></br>';}else{echo '';if(!isset($_POST['terms'])){echo '<div align="center" class="text-not-correct">Please tick and accept the Terms and Condition Box!</div></br>';}else{if(!isset($_POST['agree'])){echo '<div align="center" class="text-not-correct">Please tick and accept the VIP notifications!</div></br>';}else{<!-------------------------------HERE IS WHERE i STRUGGLE-------------------------------->$con=mysqli_connect($host,$username,$password,$db_name);// Check connectionif (mysqli_connect_errno($con)){echo '<div align="center" class="text-not-correct">Error: xx003 Failed to connect to Database: </div></br>';}mysqli_query($con,"CREATE TABLE $tbl_name");$email=$_POST['email'];$phone=$_POST['phone'];$code=$_POST['code'];$date = date('Y-m-d H:i:s');$email=mysqli_real_escape_string($con,$email);$phone=mysqli_real_escape_string($con,$phone);$code=mysqli_real_escape_string($con,$code);// This query will fail, cause we did not escape $newpersmysqli_query($con,"INSERT into $tbl_name (date, phone_number, email, code) VALUES ('$date', '$phone', '$email', '$code')");// This query will work, cause we escaped $newpersif(mysqli_num_rows($con) > 0) {echo "Phone already exist!";}else{mysqli_close($con);if (mysqli_query) header("Refresh: 5;url=http://website.com/page1.php");echo '<div align="center" class="text-correct">Congratulation you are now registered!</div></br>';echo '<div align="center"><img src="loading.gif" width="100" height="100" /></div>';}}}}}}}}?></php>
Thank you so much in advance for your help, a friend of mine told me this forum was top of the top to get problems sorted in PHP.
Ben