Click here to Skip to main content
15,868,016 members
Home / Discussions / Database
   

Database

 
AnswerRe: trying to follow this tutorial but video not set at 100% Pin
CHill607-Jun-18 2:10
mveCHill607-Jun-18 2:10 
Questionhow to use implode and explode Pin
piano00112-Jun-18 16:55
piano00112-Jun-18 16:55 
AnswerRe: how to use implode and explode Pin
Eddy Vluggen4-Jun-18 0:37
professionalEddy Vluggen4-Jun-18 0:37 
AnswerRe: how to use implode and explode Pin
phan anh huan13-Jun-18 5:43
phan anh huan13-Jun-18 5:43 
QuestionCan't get my 2nd table working Pin
piano00112-Jun-18 2:06
piano00112-Jun-18 2:06 
QuestionRe: Can't get my 2nd table working Pin
Richard MacCutchan2-Jun-18 2:46
mveRichard MacCutchan2-Jun-18 2:46 
AnswerRe: Can't get my 2nd table working Pin
piano00112-Jun-18 4:33
piano00112-Jun-18 4:33 
AnswerRe: Can't get my 2nd table working Pin
piano00112-Jun-18 18:39
piano00112-Jun-18 18:39 
I have been trying to do a multiple select option in my html form, so I will include that file here as well.... Someone else also replied to my question, do I need to post it back to him or her? I think i will post it just in case but here are my html and php code... From my experience, when this type of problem happened, it is usually the problem of my sql variables. Also, I am trying to use implode and did something like $subscriptionplan = implode(',', $subscriptionplan); in order to insert the following into a single column: Level 1, Level 2, Level 3...

Can you also check my signup2.php page and let me know if I did do the if statements correctly as I have been following mmtuts on youtube but shouldn't it be elseif()?

// Code for html

<?php




if(isset($_SESSION['u_uid'])) {
   header("Location: index.php?signup=mustsignupfirst");
   exit();

} else {
   include_once 'index.php';
   include_once 'includes/dbh.php';
}


?>


<section class="main-container">
   <div class="main-wrapper">
      <h2>Signup</h2>
      <form class="signup-form" action="includes/signup2.php" method="POST">
         <label>Firstname</label>
         <br></br>
         <input type="text" name="first" placeholder="Firstname">
         <label>Lastname</label>
         <br></br>
         <input type="text" name="last" placeholder="Lastname">
         <label>E-Mail</label>
         <br></br>
         <input type="text" name="email" placeholder="E-mail">
         <label>Username</label>
         <br></br>
         <input type="text" name="uid" placeholder="Username">
         <label>Password</label>
         <br></br>
         <input type="password" name="pwd" placeholder="Password">
         <label>Basic Subscription Plan</label>
         <br></br>
         <select name="freelesson">
            <option value="Primer Level">Primer Level: Free</option>
         </select>
         <br></br>
          <label>Premium Subscription Plan 1</label>
          <br></br>
         <select name="subscriptionplan[]" multiple="multiple">
            <option value="">Choose Subscription Plan 1</option>
            <option value="None">None</option>
            <option value="Level 1">Level 1</option>
            <option value="Level 2">Level 2</option>
            <option value="Level 3">Level 3</option>
         </select>
         <br></br>
         
         <button type="submit" name="submit">Sign up</button>
      </form>
      <?php
         $fullUrl = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

         if (strpos($fullUrl, "signup=empty") == true) {
               echo "<br>";
               echo "<p class='error'>You did not fill in all fields!</p>";
         }
         elseif (strpos($fullUrl, "signup=invalid") == true) {
               echo "<br>";
               echo "<p class='error'>Your first name and last name have invalid characters!</p>";
         }
         elseif (strpos($fullUrl, "signup=email") == true) {
               echo "<br>";
               echo "<p class='error'>You have an invalid email address!</p>";
         }
         elseif (strpos($fullUrl, "signup=notalphanumeric") == true) {
               echo "<br>";
               echo "<p class='error'>Password has to contain both letters and numbers!</p>";
         }
         elseif (strpos($fullUrl, "signup=usertaken") == true) {
               echo "<br>";
               echo "<p class='error'>Username already taken!</p>";
         }
         
         elseif (strpos($fullUrl, "signup=success") == true) {
               echo "<br>";
               echo "<p class='success'>You have been signed up!</p>";
         }

         elseif (strpos($fullUrl, "signup=chooseoneplanonly") == true) {
               echo "<br>";
               echo "<p class='error'>You can't choose more than one of the same plan!</p>";
         }

         elseif (strpos($fullUrl, "signup.php?signup=cannotchoosealllevel1") == true) {
               echo "<br>";
               echo "<p class='error'>Cannot choose the same level plan!</p>";
         }

         elseif (strpos($fullUrl, "signup.php?signup=cannotchoosealllevel2") == true) {
               echo "<br>";
               echo "<p class='error'>Cannot choose the same level plan!</p>";
         }

         elseif (strpos($fullUrl, "signup.php?signup=cannotchoosealllevel3") == true) {
               echo "<br>";
               echo "<p class='error'>Cannot choose the same level plan!</p>";
         }







      ?>
   </div>
</section>

<?php
   include_once 'footer.php';

 ?>


// This is my php code for signup2.php:

<?php

   
   if (!isset($_POST['submit'])) {
      header("Location: ../signup.php");
      exit();
   } else {
   	    
   	   include_once 'dbh.php';

   	   // information from users table

   	   $first = $_POST['first'];
   	   $last = $_POST['last'];
   	   $email = $_POST['email'] ;
   	   $uid = $_POST['uid'];
   	   $password = $_POST['pwd'];
   	   $user_permission = 'Standard User';
   	   $freelesson = $_POST['freelesson'];
   	   $datejoined = date('Y-m-d H:i:s', strtotime('+1 day'));
   	   $user_activate = 0;
   	   $premium = 0;



      // information from memberships table

        
   	   $subscriptionplan = $_POST['subscriptionplan'];
   	   
   	  
   	   $subscriptionplandate = date('Y-m-d H:i:s', strtotime('+1 day'));
   	   $subscriptionplandate2 = date('Y-m-d H:i:s', strtotime('+1 day'));
   	   $subscriptionplandate3 = date('Y-m-d H:i:s', strtotime('+1 day'));
   	   $fees =  0;
       $fees2 = 0;
       $fees3 = 0;
       $totalfees = 0;
       $paid = 0;
       $paid2 = 0;
       $paid3 = 0;
       $expirydate = date('Y-m-d H:i:s', strtotime('+1 day'));
       $expirydate2 = date('Y-m-d H:i:s', strtotime('+1 day'));
       $expirydate3 = date('Y-m-d H:i:s', strtotime('+1 day'));
       $paidbydate = date('Y-m-d H:i:s', strtotime('+1 day'));
       $paidbydate2 = date('Y-m-d H:i:s', strtotime('+1 day'));
       $paidbydate3 =  date('Y-m-d H:i:s', strtotime('+1 day'));
       $overdue = 0;
       $overdue2 = 0;
       $overdue3 = 0;
   	   
   	  // $fees = mysqli_real_escape_string($conn, $_POST['fees']);
   	  // $totalfees = mysqli_real_escape_string($conn, $_POST['totalfees']);
   	   
      
       
       $activate =  0;
       
      
   	   //Error handlers...

   	   if (empty($first) || empty($last) || empty($email) || empty($uid)|| empty($password)) {
   	   	   header("Location: ../signup.php?signup=empty");
   	   	   exit();
   	   } else {
          //Check if input characters are valid
   	   	    if (!preg_match("/^[a-zA-Z]*$/", $first) || !preg_match("/^[a-zA-Z]*$/", $last)) {
                header("Location: ../signup.php?signup=invalid");
                exit();
   	   	    } else {
   	   	    	
   	   	    	//Checking for valid emails
                 if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
                     header("Location: ../signup.php?signup=email");
                     exit();
                 } else {
                   if (Strlen($password) < 5) {
                   header("Location: ../signup.php?signup=invalidlength");
                   exit();
                   } else {
                      if (!preg_match('/^(?=.*\d)(?=.*[A-Za-z])[0-9A-Za-z!@#$%]{8,20}$/', $password)) {
                       header ("Location: ../signup.php?signup=notalphanumeric");
                       exit();
                      } else {
                      	if($subscriptionplan == '') {
                      		header("Location: ../signup.php?signup=mustchooseplan");
                      		exti();
                      	}
                      		

                      		

                           
                      $sql = "SELECT * FROM users WHERE user_uid = ?;";
                      // Create a prepared statement
                      $stmt = mysqli_stmt_init($conn);
                      //Prepare the prepared stement

                      if (!mysqli_stmt_prepare($stmt, $sql)) {
                         echo "SQL statement failed";

                      } else {
                      	   //Bind parameters to the placeholder
                      	mysqli_stmt_bind_param($stmt, "s", $uid);
                      }

                      
                      if($resultCheck > 0) {
                         header("Location: ../signup.php?signup=usertaken");
                         exit();
                      } else {

                    
  								
                                           
  										
   							            
                            



           // Select subscription 

          


                                     
       

                         // Supply a random generated token for email activation
                        

                      	$token = 'qqewreqreqwsdfdfdafcbvcQERFGHFGHGFHRETERTDF!@#$%^^()';
                      	$token = str_shuffle($token);
                      	$token = substr($token, 0, 10);

                      	$token2 = 'qqewreqreqwsdfdfdafcbvcQERFGHFGHGFHRETERTDF!@#$%^^()';
                        $token2 = str_shuffle($token2);
                      	$token2 = substr($token2, 0, 10);
                        $paid = 0;
                      	
                      	$activate = 0;

                      	//Hashing the password
                      	$hashedPwd = password_hash($password, PASSWORD_DEFAULT);
                      	//Insert the user into the database
                      	$sql ="INSERT INTO users (user_first, user_last, user_email, user_uid, user_password, user_permission, freelesson, datejoined, user_token, user_activate, premium) VALUES (?,?,?,?,?,?,?,?,?,?,?);";

                      	$stmt = mysqli_stmt_init($conn);
                      	if(!mysqli_stmt_prepare($stmt, $sql)) {
                      		 echo "SQL error";
                      	} else {
                      		mysqli_stmt_bind_param($stmt, "sssssssssss", $first, $last, $email, $uid, $hashedPwd, $user_permission, $freelesson,$datejoined, $token, $user_activate, $premium);
                      	  mysqli_stmt_execute($stmt);
                      	}

                       // insert into user_lessonsubscription table

                       
                       
                         
                       

                          
                     

                   // $subscriptionplan  = implode(',',$subscriptionplan);

                        
                        
                       
                  

                      $sql ="INSERT INTO memberships (user_uid, subscriptionplan, subscriptionplandate, subscriptionplandate2, subscriptionplandate3, fees, fees2, fees3, totalfees, paid, paid2, paid3, expirydate, expirydate2, expirydate3, paidbydate, paidbydate2, paidbydate3, overdue, overdue2, overdue3, token, activate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";

                      $stmt = mysqli_stmt_init($conn);
                      	if(!mysqli_stmt_prepare($stmt, $sql)) {
                      		 echo "SQL error";
                      	} else {
                      		mysqli_stmt_bind_param($stmt, "sssssssssssssssssssssss", $uid, $subscriptionplan, $subscriptionplandate, $subscriptionplandate2, $subscriptionplandate3, $fees, $fees2, $fees3, $totalfees, $paid, $paid2, $paid3, $expirydate, $expirydate2, $expirydate3, $paidbydate, $paidbydate2, $paidbydate3, $overdue, $overdue2, $overdue3, $token2, $activate);
                      	  mysqli_stmt_execute($stmt);
                      	}

                      


                        // Send an email to the user:
                        $company = "pianocourse101@hotmail.com";
                        $subject = "Activate your email account";
                        $mailTo = "piano0011@hotmail.com";
                        $headers = "From: ".$company;
                       $txt = "Thank you for registering with pianocourse101! At pianocourse101, your child can now learn how to play the piano right from the comfort of your own home! \n\nOur lessons are based from the Bastien Piano Basics series because it is both fun and educational for your child. \n\nHowever, you must activate your FREE membership account by clicking on the link below: \n\n http://localhost/loginsystem/includes/activate.php?email=".$mailTo."&activatetoken=".$token."" ;

                        mail($mailTo, $subject, $txt, $headers);
                        





                      	header("Location: ../signup.php?signup=success");
                      	exit();
                        }
                 }
             }
         }
     
   	   }
   	  }
   	}

GeneralRe: Can't get my 2nd table working Pin
Richard MacCutchan2-Jun-18 21:08
mveRichard MacCutchan2-Jun-18 21:08 
GeneralRe: Can't get my 2nd table working Pin
piano00112-Jun-18 21:27
piano00112-Jun-18 21:27 
GeneralRe: Can't get my 2nd table working Pin
Richard MacCutchan2-Jun-18 21:35
mveRichard MacCutchan2-Jun-18 21:35 
GeneralRe: Can't get my 2nd table working Pin
piano00112-Jun-18 22:27
piano00112-Jun-18 22:27 
AnswerRe: Can't get my 2nd table working Pin
piano00112-Jun-18 15:43
piano00112-Jun-18 15:43 
GeneralRe: Can't get my 2nd table working Pin
OriginalGriff2-Jun-18 18:45
mveOriginalGriff2-Jun-18 18:45 
GeneralRe: Can't get my 2nd table working Pin
piano00112-Jun-18 18:50
piano00112-Jun-18 18:50 
GeneralRe: Can't get my 2nd table working Pin
OriginalGriff2-Jun-18 19:08
mveOriginalGriff2-Jun-18 19:08 
AnswerRe: Can't get my 2nd table working Pin
Eddy Vluggen2-Jun-18 4:27
professionalEddy Vluggen2-Jun-18 4:27 
GeneralRe: Can't get my 2nd table working Pin
piano00112-Jun-18 15:41
piano00112-Jun-18 15:41 
GeneralRe: Can't get my 2nd table working Pin
piano00112-Jun-18 15:42
piano00112-Jun-18 15:42 
QuestionError in Restoring SQL Server Backup of v 2012 to v 2008 Pin
indian1431-Jun-18 11:14
indian1431-Jun-18 11:14 
AnswerRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
Victor Nijegorodov1-Jun-18 20:46
Victor Nijegorodov1-Jun-18 20:46 
AnswerRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
Eddy Vluggen2-Jun-18 0:21
professionalEddy Vluggen2-Jun-18 0:21 
GeneralRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
indian1434-Jun-18 6:10
indian1434-Jun-18 6:10 
GeneralRe: Error in Restoring SQL Server Backup of v 2012 to v 2008 Pin
Eddy Vluggen4-Jun-18 7:08
professionalEddy Vluggen4-Jun-18 7:08 
QuestionA Control flow Task is appearing in the SSIS Packages xml even after disabling and the deleting it. Pin
indian14331-May-18 13:34
indian14331-May-18 13:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.