JOIN PAGE

"; echo 'TEST ' . $views . ' hits'; $views=$views+1; $new_views="UPDATE guestbook2 SET gbViews = $views WHERE user_id =7"; echo "
"; echo 'the Homepage has been viewed ' .$row['gbViews'] .' times' ; if ($connection->query($new_views) === TRUE) { echo "Record updated successfully"; } else { echo "Error updating record: " . $connection->error; } //$views=$row['views'];//views has index 2 //$new_views = "UPDATE counterTestTable SET views = '$views'+1 WHERE id=1"; //$final=mysqli_query($connection, $new_views); //echo "the new no of views is:". $new_views; } //end COUNTER //Go over again later - the purpose of this php code is so that the form will print out on screen with existing entries even if there are errors. function input_select($element_name, $selected, $options, $multiple=false)//('subject',$defaults,$subject_options) { /* $subject_options = array(//was actually defined at bottom.May not need here. 'rant'=>'rant', 'praise'=>'praise', 'question'=>'question'); */ // print out the '; // set up the list of things to be selected $selected_options = array(); if ($multiple) { foreach ($selected[$element_name] as $val) { $selected_options[$val] = true; } } else { $selected_options[ $selected[$element_name] ] = true; } // print out the '; } print ''; } //Create form function display_form($defaults) { ?>

Your user name
Your email
Your password
U need 2 ntr your name

"; $errors[]= "The name field cannot be empty"; } elseif (strlen($name)>32){ $errors[] = "The name field cannot exceed 32 characters. Please re-enter your name."; } else{ $name=htmlspecialchars($name); echo "

Thanks for entering your name: $name

"; //$errors = NULL; } /* if(empty($_POST['f_username'])){ $errors[]= "The username field cannot be empty"; }else{ $username = test_input($_POST["f_username"]); if (strlen($username)>32){ $errors[] = "The username field cannot exceed 32 characters. Please re-enter your username."; }else{ echo "

Thanks for entering your username: $username

"; } } */ //see if email field is empty. If not then check format. if(empty($_REQUEST['email'])){ //$email = NULL; //echo "

U need 2 ntr ur mail address

"; $errors[]= "You cannot leave the email field empty"; } elseif(!preg_match("/^[^@\s]+@([-a-z0-9]+\.)+[a-z]{2,}$/i",$email)) //(!preg_match("/^[A_Z0-9._%+-]+@[A_Z0-9.-]+\.[A_Z]{2,}$/i",$email)) { $errors[] = "The entry isn't valid. You must type in an email adddress w/ correct format"; } else{ $email=$_REQUEST['email']; echo "

Thanks for entering your email adress $email

"; //$errors = NULL; } //See if password has been entered if(empty($_REQUEST['password'])){ //echo "

U need 2 ntr your name

"; $errors[]= "The password field cannot be empty"; } elseif (strlen($password)>64){ $errors[] = "The password field cannot exceed 64 characters. Please re-enter your name."; } else{ $password=htmlspecialchars($password); echo "

Thanks for entering your password.

"; //$errors = NULL; } return $errors; } //------------------ function Errors($errors){ if ($errors) {//After validation fx is run, then come back here. If errors then results are in these messages: echo "

Sorry, we are unable to process your submission because:

", "

Please correct your form and re-submit it.

"; display_form($_POST);//call display form. It's displayed again with values already submitted. } } //------------------ //clean up function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } //--------------------- function process($data) {//here you'd add logic to send to a database or to an email...Here just print to screen. display_form($_POST);//call display form. It's displayed again with values already submitted. } // end function definitions /////////////////////////// //---------------------------------------------- // begin form-handling logic /////////////////////////// // If submit was clicked then method="post" and PHP_SELF => this function will run: if(isset($_POST['SubmitWasClicked'])){ $errors = validate($_POST);// If submitted (the post exists), then validate. Errors($errors); if (!$errors){//if no errors then run this fx: // If form is submitted, then insert into DB //projecting from sql injection (grab from form) $name = $_POST["name"]; $email = $_POST["email"]; $password = $_POST["password"]; //$date = Date("Y-m-d h:i:s"); //Query values from table if un matches with form entry $sql = "SELECT user_id, user_pass, user_name FROM guestbook2 WHERE user_name = '$name' "; //table = form $resultArray=mysqli_query($connection, $sql);//Pass in the connection string and sql query to a temp var? or array? $get_row = mysqli_fetch_assoc($resultArray); if($get_row > 0 ){ $db_name = $get_row["user_name"]; $db_password = $get_row["user_pass"]; $db_ID = $get_row["user_id"]; //validate the un is correct if ($name == $db_name){ echo "

You are registered. UN exists in db. Go to login screen.

"; } }//end if statement else{ echo "

You were not registered yet. You have successfully registered. Please go to Login page to login.

"; //return 1; //Indicates username match failure //Insert new un and pw into data base //query (access) table and insert the form's values in sequence that's same as columns. $query = "INSERT INTO guestbook2 VALUES(0, '$name', '$password','$email', '$date','')";//Temp var.created. Values inserted into table. $date goes under gbDateAdded. $result = mysqli_query($connection, $query);//put info into array var. /* //this results in a bug where entry occurs twice so leave out. //pass in the connection string and sql query //and print out how many rows entered successfully if (mysqli_query($connection, $query)) { $returnedRows = mysqli_affected_rows($connection); echo $returnedRows . " record(s) created successfully"; } else { echo "Error: " . $query . "
" . mysqli_error($connection);//will print out "Error" + "insert into guestbook values" + the values that I tried to enter+date+ an error message. } */ }//end of else process($_POST); }//end of !errors }//end submit was clicked //START else {//if submit was NOT clicked and so post doesn't exist: Then set the defaults array and display the form. //definition of $default is all fields have null values echo "

Please fill in the fields and click on the Submit button

"; $defaults = array('name'=>'','email'=>'','password'=>'',); display_form($defaults); } //Turn off output buffering ob_flush(); ?>