Messages - The Code Queryer [ switch to compact view ]

Pages: prev1 2 [3] 4 5 6 7next
11
Developer's Corner / Re: File Upload
« on: April 11, 2019, 06:47 AM »
Mmmm. Again, here too no one knows the answer ?  :'(

12
No one knows the answer ?  :-\

13
Php Folks,

The following code meets all my REQUIREMENTS mentioned on my original post with 2 exceptions:

* Search feature - EXACT MATCH & FUZZY SEARCH
* Web Responsive Design


This code of mine works fine. It PRACTICALLY displays all results (rows) from the mysql table.


<?php 
//https&#58;//www.w3schools.com/whatis/tryit.asp?filename=trywhatis_bootstrap_table&stacked=h
//Required PHP Files. 
include 'header_account.php'//Required on all webpages of the Account. 
?>


<?php 
if (!$conn

$error mysqli_connect_error(); 
$errno mysqli_connect_errno(); 
print "$errno&#58; $error\n"
exit(); 


// Get the total number of records from our table "students". 
$total_pages $conn->query('SELECT * FROM browsing_histories')->num_rows

// Check if the page number is specified and check if it's a number, if not return the default page number which is 1. 
$page_number = isset($_GET['page_number'&#93;) && is_numeric($_GET['page_number'&#93;) ? $_GET['page_number'&#93; &#58; 1; 
//Number of results to show on each page. 
$num_results_on_page 25

if (
$stmt_1 $conn->prepare('SELECT * FROM browsing_histories ORDER BY id LIMIT ?,?')) { 
// Calculate the page to get the results we need from our table. 
$calc_page = ($page_number 1) * $num_results_on_page
$stmt_1->bind_param('ii'$calc_page$num_results_on_page); 
$stmt_1->execute(); 
//Get the results...
$result $stmt_1->get_result();  //Do not make this into $result_1 as there is only 1 $result on this page. 

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_http $_SERVER['HTTP_REFERER'&#93;; //This fails to capture the Query String! 

if(!empty($_SERVER['QUERY_STRING'&#93;)) 

$query_string $_SERVER['QUERY_STRING'&#93;; 

//$referral_page = "$referral_page_http?$query_string"; //Added the Query String. 
$referral_page "$referral_page_http"//No Query String. 

$referral_page_original "$referral_page"//Query String included in Url. 
$referral_page_to_convert "$referral_page_original"//Query String included in Url. 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
$current_page "$current_page_http?$query_string"//Added the Query String. Added the query string to add the proxied url onto my proxy's url. So now, the url includes both proxy's url and the proxied url. Eg. http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 
//$current_page = "$current_page_http"; //No Query String. 

$current_page_original "$current_page"//Query String included in Url. Url includes proxy's url and proxied url. 
$current_page_non_proxied "$query_string"//Url only includes proxied url's actual url. Excludes the proxy's url. 
$current_page_to_convert "$current_page_non_proxied"//Convert only the proxied url's actual url. And not the proxy's url. 

else 

$referral_page "$referral_page_http"//Added NO Query String. 
$referral_page_original "$referral_page"//Query String NOT included in Url. 
$referral_page_to_convert "$referral_page_original"//Query String NOT included in Url. 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
$current_page "$current_page_http"//Url only includes my proxy's url. Eg. http&#58;//www.proxy.com/proxify_url? and not http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 

$current_page_original "$current_page"//Query String NOT included in Url. Url includes proxy's url and NOT the proxied url. 
$current_page_to_convert "$current_page"//Converting only the proxy's actual url. And not the proxied url as it NOT exists in the url. 


else 

if(!empty($_SERVER['QUERY_STRING'&#93;)) 

$query_string $_SERVER['QUERY_STRING'&#93;; 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
//$current_page = "$current_page_http?$query_string"; //Added the Query String. Added the query string to add the proxied url onto my proxy's url. So now, the url includes both proxy's url and the proxied url. Eg. http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 
$current_page "$current_page_http"//No Query String. 

$current_page_original "$current_page"//Query String included in Url. Url includes proxy's url and proxied url. 
$current_page_non_proxied "$query_string"//Url only includes proxied url's actual url. Excludes the proxy's url. 
$current_page_to_convert "$current_page_non_proxied"//Convert only the proxied url's actual url. And not the proxy's url. 

else 

$current_page_http $_SERVER["PHP_SELF"&#93;; //Fails to add query strings on dynamic pages' urls. Fails to go beyond the "?". Only displays my proxy's url. Not the proxied url. Eg. Only shows&#58; Eg. http&#58;//www.proxy.com/proxify_url? 
$current_page "$current_page_http"//Url only includes my proxy's url. Eg. http&#58;//www.proxy.com/proxify_url? and not http&#58;//www.proxy.com/proxify_url?http&#58;//www.example.com 

$current_page_original "$current_page"//Query String NOT included in Url. Url includes proxy's url and NOT the proxied url. 
$current_page_to_convert "$current_page"//Converting only the proxy's actual url. And not the proxied url as it NOT exists in the url. 



if(empty(
$visiting_pages_count)) 

$visiting_pages_count "1"

else 

$visiting_pages_count++; 


if(
$visiting_pages_count == "1"

$current_page_converted "$settings_user_first_quick_link"."$current_page_to_convert"
if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_first_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "2"

$current_page_converted "$settings_admin_second_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_second_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "3"

$current_page_converted "$settings_user_third_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_third_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "4"

$current_page_converted "$settings_admin_fourth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_fourth_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "5"

$current_page_converted "$settings_user_fifth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_fifth_quick_link"."$referral_page_to_convert"

}  
elseif(
$visiting_pages_count == "6"

$current_page_converted "$settings_admin_first_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_first_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "7"

$current_page_converted "$settings_user_second_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_second_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "8"

$current_page_converted "$settings_admin_third_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_third_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "9"

$current_page_converted "$settings_user_fourth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_fourth_quick_link"."$referral_page_to_convert"


elseif(
$visiting_pages_count == "10"

$current_page_converted "$settings_admin_fifth_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_admin_fifth_quick_link"."$referral_page_to_convert"

}  
elseif(
$visiting_pages_count "1")  

$current_page_converted "$settings_user_first_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_first_quick_link"."$referral_page_to_convert"


else 

$visiting_pages_count "1"
$current_page_converted "$settings_user_first_quick_link"."$current_page_to_convert"

if(!empty($_SERVER['HTTP_REFERER'&#93;)) 

$referral_page_converted "$settings_user_first_quick_link"."$referral_page_to_convert"



$followed_page_original "$current_page_original"
$followed_page_converted "$current_page_converted"

$follower_username $user
$follower_browser $_SERVER['HTTP_USER_AGENT'&#93;; 

//Insert the User's Click Logs into Mysql Database using Php's Sql Injection Prevention Method "Prepared Statements". 
//All entries related to the "Follower" apart from "followee_username" and "followee_browsed_page_converted". 
$stmt_2 mysqli_prepare($conn,"INSERT INTO trailing_histories(query_type,followed_word,query_string,followed_page_original,followed_page_non_proxied,followed_page_converted,referral_page_original,referral_page_non_proxied,referral_page_converted,followee_username,username,gender,age_range,date_of_birth,skin_complexion,height,weight,sexual_orientation,religion,education,profession,marital_status,working_status,country_of_birth,home_town,home_neighbourhood,home_borough,home_council,home_city,home_county,home_district,home_region,home_state,home_country) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"); 
mysqli_stmt_bind_param($stmt_2,'sssssssssssssiisssssssssssssssssss',$query_type,$followed_word,$query_string,$followed_page_original,$followed_page_non_proxied,$followed_page_converted,$referral_page_original,$referral_page_non_proxied,$referral_page_converted,$followee_username,$username,$gender,$age_range,$date_of_birth,$skin_complexion,$height,$weight,$sexual_orientation,$religion,$education,$profession,$marital_status,$working_status,$country_of_birth,$home_town,$home_neighbourhood,$home_borough,$home_council,$home_city,$home_county,$home_district,$home_region,$home_state,$home_country); 
mysqli_stmt_execute($stmt_2); 

//Check if User's Click Logs have been successfully submitted or not. 
if (!$stmt_2

die("<h3 style='text-align&#58;center'> 
ERROR 1&#58; Sorry! Our system is currently experiencing a problem logging your trailing!<br> 
SUGGESTION&#58; Try visiting this page another time.</h3>"
); 

else 

mysqli_stmt_close($stmt_2);

?>


<!DOCTYPE html>
<html>
<head>
<title><?php echo "Browsing History in $server_time Time.";?></title>
<meta content="text/html; charset=ISO-8859-1" http-equiv=" content-type">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
html {
font-family; Tahoma, Geneva, sans-serif;
padding: 20px;
background-color: #F8F9F9;
}
table {
border-collapse: collapse;
width: 500px;
}
td, th {
padding: 10px;
}
th {
background-color: #54585d;
color: #ffffff;
font-weight: bold;
font-size: 13px;
border: 1px solid #54585d;
}
td {
color: #636363;
border: 1px solid #dddfe1;
}
tr {
background-color: #f9fafb;
}
tr:nth-child(odd) {
background-color: #ffffff;
}
.pagination {
list-style-type: none;
padding: 10px 0;
display: inline-flex;
justify-content: space-between;
box-sizing: border-box;
}
.pagination li {
box-sizing: border-box;
padding-right: 10px;
}
.pagination li a {
box-sizing: border-box;
background-color: #e2e6e6;
padding: 8px;
text-decoration: none;
font-size: 12px;
font-weight: bold;
color: #616872;
border-radius: 4px;
}
.pagination li a:hover {
background-color: #d4dada;
}
.pagination .next a, .pagination .prev a {
text-transform: uppercase;
font-size: 12px;
}
.pagination .currentpage a {
background-color: #518acb;
color: #fff;
}
.pagination .currentpage a:hover {
background-color: #518acb;
}
</style>
</head>
<body>
<p align="center"><span style="font-weight:bold;"><?php echo "Search Result for&#58;<br> \"All Users\""?></span></p>
<br>
<br>
<table>
<tr>
<th>Submission Number</th>
<th>Date & Time</th>
<th>Query Type</th>
<th>Followed Word</th>
<th>Query String</th>
<th>Browsed Page Original</th>
<th>Browsed Page Non-Proxied</th>
<th>Browsed Page Converted</th>
<th>Referral Page Original</th>
<th>Referral Page Non-Proxied</th>
<th>Referral Page Converted</th>
<th>Username</th>
<th>Gender</th>
<th>Age Range</th>
<th>Date Of Birth</th>
<th>Skin Complexion</th>
<th>Height</th>
<th>Weight</th>
<th>Sexual Orientation</th>
<th>Religion</th>
<th>Education</th>
<th>Profession</th>
<th>Marital Status</th>
<th>Working Status</th>
<th>Country Of Birth</th>
<th>Home Town</th>
<th>Home Neighbourhood</th>
<th>Home Borough</th>
<th>Home Council</th>
<th>Home City</th>
<th>Home County</th>
<th>Home District</th>
<th>Home Region</th>
<th>Home State</th>
<th>Home Country</th>
</tr>
<?php while ($row $result->fetch_assoc())&#58; ?>
<tr>
<td><?php echo $row['id'&#93;; ?></td>
<td><?php echo $row['date_and_time'&#93;; ?></td>
<td><?php echo $row['query_type'&#93;; ?></td>
<td><?php echo $row['followed_word'&#93;; ?></td>
<td><?php echo $row['query_string'&#93;; ?></td>
<?php //Browsed Page Original contains both Proxy's Url and Proxied Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=browsed_page_original&browsed_page_original=<?php echo $row['browsed_page_original'&#93;; ?>"><?php echo $row['browsed_page_original'&#93;; ?></a></td>
<?php //Browsed Page Non-Proxied contains Direct Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=browsed_page_non_proxied&browsed_page_non_proxied=<?php echo $row['browsed_page_non_proxied'&#93;; ?>"><?php echo $row['browsed_page_non_proxied'&#93;; ?></a></td>
<?php //Browsed Page Converted contains only Proxied Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=browsed_page_converted&browsed_page_converted=<?php echo $row['browsed_page_converted'&#93;; ?>"><?php echo $row['browsed_page_converted'&#93;; ?></a></td>
<?php //Referral Page Original contains only Proxied Url. And so preceding the Proxy's Url onto the url from the followee_browser.php page. Check that page's source code. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=referral_page_original&referral_page_original=<?php echo $row['referral_page_original'&#93;; ?>"><?php echo $row['referral_page_original'&#93;; ?></a></td>
<?php //Browsed Page Non-Proxied contains Direct Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=referral_page_non_proxied&browsed_page_non_proxied=<?php echo $row['referral_page_non_proxied'&#93;; ?>"><?php echo $row['referral_page_non_proxied'&#93;; ?></a></td>
<?php //Referral Page contains only Proxied Url. ?>
<td><a href="follower_browser.php?followee_username=<?php echo $row['username'&#93;; ?>&page_type=referral_page_converted&referral_page_converted=<?php echo $row['referral_page_converted'&#93;; ?>"><?php echo $row['referral_page_converted'&#93;; ?></a></td>
<td><a href="profile.php?followee_username=<?php echo $row['username'&#93;; ?>"><?php echo $row['username'&#93;; ?></a></td>
<td><?php echo $row['gender'&#93;; ?></td>
<td><?php echo $row['age_range'&#93;; ?></td>
<td><?php echo $row['date_of_birth'&#93;; ?></td>
<td><?php echo $row['skin_complexion'&#93;; ?></td>
<td><?php echo $row['height'&#93;; ?></td>
<td><?php echo $row['weight'&#93;; ?></td>
<td><?php echo $row['sexual_orientation'&#93;; ?></td>
<td><?php echo $row['religion'&#93;; ?></td>
<td><?php echo $row['education'&#93;; ?></td>
<td><?php echo $row['profession'&#93;; ?></td>
<td><?php echo $row['marital_status'&#93;; ?></td>
<td><?php echo $row['working_status'&#93;; ?></td>
<td><?php echo $row['country_of_birth'&#93;; ?></td>
<td><?php echo $row['home_town'&#93;; ?></td>
<td><?php echo $row['home_neighbourhood'&#93;; ?></td>
<td><?php echo $row['home_borough'&#93;; ?></td>
<td><?php echo $row['home_council'&#93;; ?></td>
<td><?php echo $row['home_city'&#93;; ?></td>
<td><?php echo $row['home_county'&#93;; ?></td>
<td><?php echo $row['home_district'&#93;; ?></td>
<td><?php echo $row['home_region'&#93;; ?></td>
<td><?php echo $row['home_state'&#93;; ?></td>
<td><?php echo $row['home_country'&#93;; ?></td>
</tr>
<?php endwhile; ?>
</table>
<?php if (ceil($total_pages $num_results_on_page) > 0)&#58; ?>
<ul class="pagination">
<?php if ($page_number 1)&#58; ?>
<li class="prev"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page-1 ?>">Prev</a></li>
<?php endif; ?>

<?php if ($page_number 3)&#58; ?>
<li class="start"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=1">1</a></li>
<li class="dots">...</li>
<?php endif; ?>

<?php if ($page_number-0)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number-2 ?>"><?php echo $page_number-2 ?></a></li><?php endif; ?>
<?php if ($page_number-0)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number-1 ?>"><?php echo $page_number-1 ?></a></li><?php endif; ?>

<li class="currentpage"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?<?php echo $page_number?>"><?php echo $page_number ?></a></li>

<?php if ($page_number+ceil($total_pages $num_results_on_page)+1)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number+1 ?>"><?php echo $page_number+1 ?></a></li><?php endif; ?>
<?php if ($page_number+ceil($total_pages $num_results_on_page)+1)&#58; ?><li class="page"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number+2 ?>"><?php echo $page_number+2 ?></a></li><?php endif; ?>

<?php if ($page_number ceil($total_pages $num_results_on_page)-2)&#58; ?>
<li class="dots">...</li>
<li class="end"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo ceil($total_pages $num_results_on_page?>"><?php echo ceil($total_pages $num_results_on_page?></a></li>
<?php endif; ?>

<?php if ($page_number ceil($total_pages $num_results_on_page))&#58; ?>
<li class="next"><a href="<?php echo "{$_SERVER['PHP_SELF'&#93;}" ;?>?page_number=<?php echo $page_number+1 ?>">Next</a></li>
<?php endif; ?>
</ul>
<?php endif; ?>
</body>
</html>
<?php 
$stmt_1->close(); 

?>


<?php 
include 'footer_account.php'//Required on all webpages of the Account. 
?>



Now, I need to add the search feature and so experimenting with the mysql queries with php.
Look at my current code below.
Look at my Mysql Queries. I am making mistakes there with the "?".
(I used the "?" as place-holders for the Prepared Statements).
I am told my error lies there in the mysql queries.
Q1. How to fix this ?

Q2. For our newbies' learning purposes. Can anyone be kind enough to show a mini pagination script ?
You may leave-out the following as I am likely to manage this with Bootsrap design tutorials:
* Page Design: Responsive Web Design using Html 5 & CSS (latest).

<?php 
//https&#58;//www.w3schools.com/whatis/tryit.asp?filename=trywhatis_bootstrap_table&stacked=h
//Required PHP Files. 
include 'header_account.php'//Required on all webpages of the Account. 
?>


<?php 
if (!$conn

$error mysqli_connect_error(); 
$errno mysqli_connect_errno(); 
print "$errno&#58; $error\n"
exit(); 


$query_type $_GET['query_type'&#93;; 

//If $_GET['query_type'&#93;) is empty then show error as it must be set. 
if(!isset($_GET['query_type'&#93;) && empty($_GET['query_type'&#93;)) 

    echo 
"Invalid Query!"

/*If $_GET['query_type'&#93;) is full with value other than wild-card or "All" 
or "all" then make specific query. 
*/
elseif($query_type != 'all' OR $query_type != 'All' OR $query_type != '*'

    ${
$query_type} = $_GET[$_GET['query_type'&#93;&#93;; 
    
$followed_word = ${$query_type}; //Same as&#58; $_GET[$_GET['query_type'&#93;&#93;; 

    
$stmt_1->$total_pages $conn->query("SELECT * FROM browsing_histories WHERE username = ?")->num_rows
$stmt_1->bind_param('s'$query_type); 
$stmt_1->execute(); 

// Check if the page number is specified and check if it's a number, if not return the default page number which is 1. 
$page_number = isset($_GET['page_number'&#93;) && is_numeric($_GET['page_number'&#93;) ? $_GET['page_number'&#93; &#58; 1; 
//Number of results to show on each page. 
$num_results_on_page 25

if ($stmt_1 $conn->prepare('SELECT * FROM browsing_histories WHERE username = ? ORDER BY id LIMIT ?,?')) { 
// Calculate the page to get the results we need from our table. 
$calc_page = ($page_number 1) * $num_results_on_page
//Added this line according to stackoverflow.com suggestion.
$stmt_2->bind_param('sii'$query_type$num_results_on_page$calc_page); 
//Make the query.     
$stmt_2->execute(); 
    } 

else 
//Make general query or query for all records. 

    
//Grab "all records" from the table. 
    //Get the total number of records from the table&#58; "browsing_histories". 
    
$total_pages $conn->query("SELECT * FROM browsing_histories")->num_rows
    
//Make the query. 
    
$stmt $conn->prepare('SELECT * FROM browsing_histories ORDER BY id LIMIT ?,?'); 
    
$stmt->bind_param('ii'$num_results_on_page); 


$stmt_1->execute(); 
?>


<?php 
include 'footer_account.php'//Required on all webpages of the Account. 
?>


NOTE 1:
The header_account.php includes more files.
The $user is defined via SESSION from one of those included files. So don't worry that I have not defined the $user here. Error reporting is ON and I am not getting any error regarding the $user.


NOTE 2: I would appreciate it if someone modified my code according to my requirements mentioned on my original post and add it to this thread for all newbies to learn from.


NOTE 3: This forum is showing my codes funny. Hence, attached my code file. Attachment will show my code correctly.
1st attachment shows my 1st code that is working fine. I do not need your help on that file.
2nd attachment shows my 2nd code which is not working properly. I need your help on that file.

NOTE 4: The 2nd script is in OOP Style. I only know Procedural. Hence struggling. This is not really my code. I grabbed it from a tutorial and tried adding the search function but failing miserably.

Thanks

14
Php Folks,

I am trying to create a php script that queries my mysql database and shows results using pagination.
Here are my requirements:

REQUIREMENTS
* Language: Php
* Php Version: 7
* Programming Style: Procedural
* Php Extension: Mysqli
* Sql Injection Prevention Method: Prepared Statements

* Web Form Design: Html 5 Compatible/Compliant
* Search Feature - Exact Match & Fuzzy Match Options (Search Usernames - See attached file for mysql tbl columns)
* Pagination - Max Results (rows) per page: 25
* Page Design: Responsive Web Design using Html 5 & CSS (latest)

I have been googling for months now and found no tutorials based on my requirements.
Tutorial are either in Pdo (Oop Style) and do not use Mysqli extension.
Or tutorials are in Procedural Style but DO NOT use Prepared Statements.
Or, tutorials are in Procedural Style and DO use Prepared Statements but do not have the SEARCH function. No EXACT MATCH or FUZZY SEARCH features exist.
None of them are Responsive Web Design suitable for both computer users and mobile phone users.

For our newbies' learning purposes. Can anyone be kind enough to show a mini pagination script ?
You may leave-out the following as I am likely to manage this with Bootsrap design tutorials:
* Page Design: Responsive Web Design using Html 5 & CSS (latest).

Thank You

NOTE: Attached file will show you what my mysql table looks like.



15
Developer's Corner / Re: File Upload
« on: April 08, 2019, 03:38 PM »
Php folks,

Here is my attempt to build a php uploading script using my REQUIREMENTS mentioned above in my original post.

I have yet to do the file renaming.

Notice the comments in CAPITALS.

Also notice that, I have commented-out many code lines. That is because those lines weren't working.
I'd appreciate it if you could point-out my errors in those lines so I can see my mistakes.
And, I would most appreciate it if you could show me snippets how those lines should be. 


Q1. How should I have coded my mkdir() as that line is not working ? I get no error on my local host xamp. But I get error on my website:
Warning: mkdir(): Permission denied in /home/domain/public_html/upload.php on line 35.

mkdir($directory_path . $user, "$mode", TRUE); //IS THIS LINE CORRECT ?


Q2. How should I have coded my move_uploaded_file() as that line is not working. Not moving the file.

//Move uploaded File to newly created directory on the server.
//move_uploaded_file("$file_tmp", "$directory_path" . "$user" . "/" . "$file_name"); //IS THIS LINE CORRECT ?
//move_uploaded_file("$file_tmp", "$directory_path" . "$user/" . "$file_name"); //IS THIS LINE CORRECT ?
move_uploaded_file("$file_tmp", $directory_path . $user . '/' . $file_name); //IS THIS LINE CORRECT ?


Q3. Is my webform html 5 compatible/compliant ?

<form METHOD="POST" ACTION="" enctype="multipart/form-data">
<fieldset>
<p align="left"><h3><?php $site_name ?> ID Video Verification Form</h3></p>
<div class="form-group">
<p align="left"<label>Video File: </label>
<input type="file" name="id_verification_video_file" id="id_verification_video_file" value="uploaded 'Id Verification Video File.'"></p>
</div>
</fieldset>
<p align="left"><button type="submit" class="btn btn-default" name="id_verification_video_file_submit">Submit!</button></p>
</form>


Q4. Anything else I should know ?

Here is my code below.
NOTE:
The header_account.php includes more files.
The $user is defined via SESSION from one of those included files. So don't worry that I have not defined the $user here. Error reporting is ON and I am not getting any error regarding the $user.

<?php 

//ERROR REPORTING CODES. 
declare(strict_types=1); 
ini_set('display_errors''1'); 
ini_set('display_startup_errors''1'); 
error_reporting(E_ALL); 
mysqli_report(MYSQLI_REPORT_ERROR MYSQLI_REPORT_STRICT); 

?>


Full Code: upload.php
<?php 
//Required PHP Files. 
include 'header_account.php'//Required on all webpages of the Site. 
?>


<?php 

if (!$conn

$error mysqli_connect_error(); 
$errno mysqli_connect_errno(); 
print "$errno&#58; $error\n"
exit(); 


if(
$_SERVER["REQUEST_METHOD"&#93; == "POST") 

//Check whether the file was uploaded or not without any errors. 
if(!isset($_FILES["id_verification_video_file"&#93;) && $_FILES["id_verification_video_file"&#93;["Error"&#93; == 0) 

$Errors = Array(); 
$Errors[&#93; = "Error&#58; " . $_FILES["id_verification_video_file"&#93; ["ERROR"&#93;; 
print_r($_FILES); ?>
<br><?php 
print_r($_ERRORS); 
exit(); 

else 

//Feed Id Verification Video File Upload Directory path. 
$directory_path "uploads/videos/id_verifications/"
//Make Directory under $user in 'uploads/videos/id_verifications' Folder. 
if(!is_dir($directory_path $user)) //IS THIS LINE CORRECT ?

$mode "0644"
mkdir($directory_path $user"$mode"TRUE); //IS THIS LINE CORRECT ?


//Grab Uploading File details. 
$Errors = Array(); //SHOULD I KEEP THIS LINE OR NOT ?
$file_name $_FILES["id_verification_video_file"&#93;["name"&#93;; 
$file_tmp $_FILES["id_verification_video_file"&#93;["tmp_name"&#93;; 
$file_type $_FILES["id_verification_video_file"&#93;["type"&#93;; 
$file_size $_FILES["id_verification_video_file"&#93;["size"&#93;; 
$file_error $_FILES['id_verification_video_file'&#93;['error'&#93;; 

//Grab Uploading File Extension details. 
$file_extension pathinfo($file_namePATHINFO_EXTENSION); 
//if(file_exists("$directory_path . $user/ . $file_name")) //THIS LINE IS NOT GIVING THE ERROR THAT FILE HAS ALREADY BEEN UPLOADED. INSTEAD GIVES THE ECHO THAT IS 26 LINES BELOW HERE&#58; "Your Video File \"$file_name\" has been uploaded successfully!"
if(file_exists($directory_path $user '/' $file_name)) ////THIS LINE IS NOT GIVING THE ERROR THAT FILE HAS ALREADY BEEN UPLOADED. INSTEAD SHOWING BLANK WHITE PAGE.

$Errors[&#93; = "Error&#58; You have already uploaded a video file to verify your ID!"; 
exit(); 
    } 
else 

//Feed allowed File Extensions List. 
$allowed_file_extensions = array("mp4" => "video/mp4"); 

//Feed allowed File Size. 
$max_file_size_allowed_in_bytes 1024*1024*100//Allowed limit&#58; 100MB. 
$max_file_size_allowed_in_kilobytes 1024*100
$max_file_size_allowed_in_megabytes 100

$max_file_size_allowed "$max_file_size_allowed_in_bytes"

//Verify File Extension. 
if(!array_key_exists($file_extension$allowed_file_extensions)) die("Error&#58; Select a valid video file format. Select an Mp4 file."); 
//Verify MIME Type of the File. 
elseif(!in_array($file_type$allowed_file_extensions)) 

$Errors[&#93; = "Error&#58; There was a problem uploading your file $file_name! Make sure your file is an MP4 video file. You may try again."; //IS THIS LINE CORRECT ?

//Verify File Size. Allowed Max Limit&#58; 100MB. 
elseif($file_size>$max_file_size_allowed) die("Error&#58; Your Video File Size is larger than the allowed limit of&#58; $max_file_size_allowed_in_megabytes."); 
//Move uploaded File to newly created directory on the server. 
move_uploaded_file("$file_tmp"$directory_path $user '/' $file_name); //IS THIS LINE CORRECT ?
//move_uploaded_file("$file_tmp", "$directory_path" . "$user" . "/" . "$file_name"); //IS THIS LINE CORRECT ?
//move_uploaded_file("$file_tmp", "$directory_path" . "$user/" . "$file_name"); //IS THIS LINE CORRECT ?
//Notify user their Id Verification Video File was uploaded successfully. 
echo "Your Video File \"$file_name\" has been uploaded successfully!"
exit(); 

    } 
    } 
?>
`

<form METHOD="POST" ACTION="" enctype="multipart/form-data">
<fieldset>
<p align="left"><h3><?php $site_name ?> ID Video Verification Form</h3></p>
<div class="form-group">
<p align="left"<label>Video File: </label>
<input type="file" name="id_verification_video_file" id="id_verification_video_file" value="uploaded 'Id Verification Video File.'"></p>
</div>
</fieldset>
<p align="left"><button type="submit" class="btn btn-default" name="id_verification_video_file_submit">Submit!</button></p>
</form>

</body>
</html>

<?php 
include 'footer_account.php'//Required on all webpages of the Site. 
?>



NOTE 1: I have not used the finfo_file() and mine_content_type functions here. I'd like you to show me how to do them.
I'd appreciate a mini script from your end.

NOTE 2: I would appreciate it if someone modified my code according to my requirements mentioned on my original post and add it to this thread for all newbies to learn from.

NOTE 3: This forum is showing my codes funny. Hence, attached my file. Attachment will show my code correctly.

Thanks

Pages: prev1 2 [3] 4 5 6 7next
Go to full version