Jump to content

bambinou1980

Members
  • Posts

    130
  • Joined

  • Last visited

Everything posted by bambinou1980

  1. Hello, I have 3 buttons on my website, I also have 3 divs with content in it(a lot of pictures in each). So imagine that when someone clicks on the button A, DIV A shows up but DIV B & C hide. What I am not too happy about is that I have noticed that even if the DIV are hidden, the whole graphics are loaded. Is there a way to put the content into other files and only load the files when the user request it please so I can then load the page empty(onload only). Thank you, Ben
  2. Hi Thank you so much for the reply. So lets say that instead of setNumber3 and 4 i want to reuse setNumber1 and 2 from the Calculator Class? I am just trying to understand the "extends" concept as i cannot find a good example. Would it be possible to demo the "extends" on my current code please? I am trying to learn the Yii framework and knows that extends means that the function of a class extends to another one but cannot work out how to reuse them in that other class:-)) At the same time why would someone extends functions from a base class rather than pulling that base class functiond directly on the file? Thanks Ben
  3. Hi Freak Dr and the Web mason Thank you so much for your help. I have added Dr Freak code after the insert and it gives me 2 strange errors: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, object given in /home... Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home.... Any idea what this translate to please? <?php$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); $result=mysqli_query($con,"SELECT * FROM $tblname WHERE phone=$phone");$row_cnt = mysqli_num_rows($result);if ($row_cnt>0){echo '<div align="center" class="text-correct">This phone number has already been registered!</div>';}else{ // 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 $newpers if(mysqli_num_rows($con) > 0) { echo "Phone already exist!"; }else{ mysqli_close($con); if (mysqli_query) header("Refresh: 5;url=http://site.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>'; }}}}}}}}}?> Thank you! Ben
  4. 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 submitted if ( 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 $newpers if(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
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.