Jump to content

Search the Community

Showing results for tags 'php'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • W3Schools
    • General
    • Suggestions
    • Critiques
  • HTML Forums
    • HTML/XHTML
    • CSS
  • Browser Scripting
    • JavaScript
    • VBScript
  • Server Scripting
    • Web Servers
    • Version Control
    • SQL
    • ASP
    • PHP
    • .NET
    • ColdFusion
    • Java/JSP/J2EE
    • CGI
  • XML Forums
    • XML
    • XSLT/XSL-FO
    • Schema
    • Web Services
  • Multimedia
    • Multimedia
    • FLASH

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Languages

  1. Hello W3S! So i have some problems again, hoping you can help me clear it out. I am currently trying to make a search page where a user can search for profiles with different profiles information such as tattoos, height, etc. And i have some difficulties making it work, hoping you can spot some sort of errors that i cannot. Please note that it's been a while since i've been making a fully working searcher with php and sql, so sorry for the messed up code, if so hehe Okay. So i have 6 files, follows as such: 1. index.php (being the main file) - (LOCATION: ROOT/FILE_HERE.php), 2. PAGE_searchprofiles.php (being where the search coding begins AND output is coming) - (LOCATION: ROOT/include/files/www-files/FILE_HERE.php), 3. functions.pagination.class.php (being my pagination class, used on file PAGE_searchprofiles.php) - (LOCATION: ROOT/FILE_HERE.php), 4. functions.php (my php functions into 1 file) - location is root 5. index.search_patterns_setup.php (being used on file PAGE_searchprofiles.php, being where i use if/else statements to compile a proper sql) - location root 6. index.no_search_show_cards_profiles.php (being used on file PAGE_searchprofiles.php, showing ALL profiles if no search has been done so far.) - location root ------------------------------------------- okay, those are file names and locations. the idea is that when there is a search, the searched profiles should be shown, else, show all files. I got that part working perfectly, but now comes the actual search query where i get a little lost (i think). And please take note that this is a search query from a past coder, doing this for a company and this coder has done some terrible coding... i think... i have a hard time seeing what he has done and not. At some places he has done a quite good job, but the search part, not so much. So, i will share the code below here for ALL files, and after that coding, i will write about the problem at hand again. -------------------------------------- index.php <?php ob_start(); session_start(); define("DEFINED_FILE:DEFINES_1", TRUE); require_once("include/files/www-files/random_uncategorized_useful_files/defines.php"); // Defines require_once("include/files/www-files/random_uncategorized_useful_files/report_methods.php"); // Reportings require_once("database/connection.php"); DB_open_main_connection(); // $dblink ?> <!DOCTYPE html> <html lang="da"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <title>Release 1 - Version 1</title> <!-- Bootstrap V.4.0.0 CSS files --> <link rel="stylesheet" href="include/css/bootstrap.min.css" /> <!-- My Custom CSS Files --> <link rel="stylesheet" href="include/css/global_custom_css_design.css" /> <link rel="stylesheet" href="include/css/5.css" /> <link rel="stylesheet" href="include/css/navigation_menu_5.css" /> <!-- other css files --> <link rel="stylesheet" href="include/css/fontawesome-all.min.css"> <!-- Jquery (necessary for Bootstrap's JavaScript plugins) and Bootstrap V.4.0.0 JS Script files --> <script src="include/js/jquery-3.2.1.js"></script> <script src="include/js/bootstrap.min.js"></script> <script src="include/js/bootstrap.bundle.js"></script> <script src="include/js/5.js"></script> </head> <body> <?php # Require Navigation Menu require_once("include/files/www-files/nav-menu.php"); # Including PAGE_signup1.php include_once("include/files/www-files/PAGE_searchprofiles.php"); ?> <div class="mt-3"></div> <?php # Require Footer require_once("include/files/www-files/footer.php"); // close connection $dblink->close(); // MAIN Connection ?> </body> </html> PAGE_searchprofiles.php <?php require_once("functions.php"); //////////////////////////////////////////////////////////////////////////////////////////////////// // Notes //////////////////////////////////////////////////////////////////////////////////////////////////// //------------------------------------------------------------------------------------------------ // comma separeret DB output for ALLE checkboxes (Tatovering & Kategori - vi bruger explode!) //------------------------------------------------------------------------------------------------ /* I DB (users_info) laver jeg en "text" for både kategori og tatovering checkboxes da jeg skal bruge string til comma (sådan forstår jeg det!). Jeg indsætter komma sepereret tal, og bruger php funktionen explode til at sepererer tallene. Jeg bruger senere tallene til at "selecte" ud fra ID hos diverse tabeller, senere hen vise diverse som er blevet vist/valgt/osv. */ //////////////////////////////////////////////////////////////////////////////////////////////////// // Lists //////////////////////////////////////////////////////////////////////////////////////////////////// //------------------------------------------------------------------------------------------------ // FORM - names //------------------------------------------------------------------------------------------------ // my notes: maybe add "multiple" to the select? Style it to be a normale dropdown... look into alternatives! // FORMNAME_SogProfilBar_Keywords (Søg Profil Bar) // FORMNAME_MinAlder (Alder :: Minimum) // FORMNAME_MaxAlder (Alder :: Maximum) // FORMNAME_Landsdel (Landsdel "SelectOption") // FORMNAME_Kon (Køn "SelectOption") // FORMNAME_MinHojde (Højde :: Minimum) // FORMNAME_MaxHojde (Højde :: Maximum) // FORMNAME_Etnicitet (Etnicitet "SelectOption") // FORMNAME_Sprog (Sprog "SelectOption") // FORMNAME_MinVaegt (Vægt :: Minimum) // FORMNAME_MaxVaegt (Vægt :: Maximum) // FORMNAME_Tatoveringer (Tatoveringer "SelectOption") // FORMNAME_Kategorier (Kategorier "SelectOption") // FORMNAME_submit_search (Søg "Submit Button") //------------------------------------------------------------------------------------------------ // Queries - already being used //------------------------------------------------------------------------------------------------ // $query_1 (selecting all data from DB-Table users_info) // $query_2 (Landsdel -> SelectOption) // $query_3 (Køn -> SelectOption) // $query_4 (Etnicitet -> SelectOption) // $query_5 (Sprog -> SelectOption) // $query_6 (Tatoveringer -> SelectOption) // $query_7 (Kategori -> SelectOption) // $query_100 (outputting all cards/profiles to the "profiles" area) //------------------------------------------------------------------------------------------------ // Queries //------------------------------------------------------------------------------------------------ $query_1 = "SELECT * FROM users_info"; $result_1 = mysqli_query($dblink, $query_1) or die ( mysqli_error($dblink) ); $row_1 = mysqli_fetch_array($result_1); ?> <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <br /> <h1 class="text-muted text-center">Søg Profiler</h1> </div> </div> </div> <div class="container"> <form method="post" action="index.php"> <div class="row mb-3"> <!-- Søg Profil Bar --> <div class="input-group"> <input type="text" class="form-control" placeholder="Søg Profil" name="FORMNAME_SogProfilBar_Keywords"> <div class="input-group-append"> <button type="submit" class="btn btn-outline-secondary" name="FORMNAME_submit_search">Søg</button> <button type="button" class="btn btn-outline-secondary JQUERY_ACTION_expand_search">Udvid Søgning</button> </div> </div> </div><!-- //.row --> <div class="row"> <div class="container"> <div class="row"> <!-- Min.Alder --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <span class="input-group-text">Min.Alder</span> <span class="input-group-text">ÅR</span> </div> <input type="number" class="form-control" placeholder="Min.Alder" min="0" name="FORMNAME_MinAlder"> </div> </div> <!-- Max.Alder --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <span class="input-group-text">Max.Alder</span> <span class="input-group-text">ÅR</span> </div> <input type="number" class="form-control" placeholder="Max.Alder" min="0" name="FORMNAME_MaxAlder"> </div> </div> <!-- Landsdel --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect_LANDSDEL">Landsdel</label> </div> <select class="custom-select" id="inputGroupSelect_LANDSDEL" name="FORMNAME_Landsdel"> <option selected disabled hidden>Landsdel</option> <?php $query_2 = "SELECT * FROM users_info_landsdel"; $result_2 = mysqli_query($dblink, $query_2) or die ( mysqli_error($dblink) ); while( $row_2 = mysqli_fetch_array($result_2) ) { $selected = ($row_2['usersinfoLandsdel_id'] == $row_1['usersinfo_FK_usersinfoLandsdel_id']) ? 'selected="selected"' : ''; echo '<option value="'.$row_2['usersinfoLandsdel_id'].'" '.$selected.'>'.$row_2['usersinfoLandsdel_name'].'</option>'; } ?> </select> </div> </div> <!-- Køn --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect_KØN">Køn</label> </div> <select class="custom-select" id="inputGroupSelect_KØN" name="FORMNAME_Kon"> <option selected disabled hidden>Køn</option> <?php $query_3 = "SELECT * FROM users_gender"; $result_3 = mysqli_query($dblink, $query_3) or die ( mysqli_error($dblink) ); while( $row_3 = mysqli_fetch_array($result_3) ) { $selected = ($row_3['usersGender_id'] == $row_1['users_FK_usersGender_id']) ? 'selected="selected"' : ''; echo '<option value="'.$row_3['usersGender_id'].'" '.$selected.'>'.$row_3['usersGender_name'].'</option>'; } ?> </select> </div> </div> </div><!-- //.row --> </div><!-- //.container --> </div><!-- //.row --> <div class="row" style="display: none;"> <div class="container mt-3 mb-3"> <div class="row mb-3"> <div class="col-md-3"> &nbsp; </div> <div class="col-md-3"> &nbsp; </div> <div class="col-md-3"> &nbsp; </div> <div class="col-md-3"> <button type="button" class="btn JQUERY_ACTION_minimize_search">Minimer Søgning</button> </div> </div><!-- //.row --> <div class="row mb-3"> <!-- Min.Højde --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <span class="input-group-text">Min.Højde</span> <span class="input-group-text">CM</span> </div> <input type="number" class="form-control" placeholder="Min.Højde" min="0" name="FORMNAME_MinHojde"> </div> </div> <!-- Max.Højde --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <span class="input-group-text">Max.Højde</span> <span class="input-group-text">CM</span> </div> <input type="number" class="form-control" placeholder="Max.Højde" min="0" name="FORMNAME_MaxHojde"> </div> </div> <!-- Etnicitet --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect_ETNICITET">Etnicitet</label> </div> <select class="custom-select" id="inputGroupSelect_ETNICITET" name="FORMNAME_Etnicitet"> <option selected disabled hidden>Etnicitet</option> <?php $query_4 = "SELECT * FROM users_gender"; $result_4 = mysqli_query($dblink, $query_4) or die ( mysqli_error($dblink) ); while( $row_4 = mysqli_fetch_array($result_4) ) { $selected = ($row_4['usersinfoEtnicitet_id'] == $row_1['usersinfo_FK_usersinfoEtnicitet_id']) ? 'selected="selected"' : ''; echo '<option value="'.$row_4['usersinfoEtnicitet_id'].'" '.$selected.'>'.$row_4['usersinfoEtnicitet_name'].'</option>'; } ?> </select> </div> </div> <!-- Sprog --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect_SPROG">Sprog</label> </div> <select class="custom-select" id="inputGroupSelect_SPROG" name="FORMNAME_Sprog"> <option selected disabled hidden>Sprog</option> <?php $query_5 = "SELECT * FROM users_info_sprog"; $result_5 = mysqli_query($dblink, $query_5) or die ( mysqli_error($dblink) ); while( $row_5 = mysqli_fetch_array($result_5) ) { $selected = ($row_5['usersinfoSprog_id'] == $row_1['usersinfo_FK_usersinfoSprog_id']) ? 'selected="selected"' : ''; echo '<option value="'.$row_5['usersinfoSprog_id'].'" '.$selected.'>'.$row_5['usersinfoSprog_name'].'</option>'; } ?> </select> </div> </div> </div><!-- //.row --> <div class="row"> <!-- Min.Vægt --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <span class="input-group-text">Min.Vægt</span> <span class="input-group-text">KG</span> </div> <input type="number" class="form-control" placeholder="Min.Vægt" min="0" name="FORMNAME_MinVaegt"> </div> </div> <!-- Max.Vægt --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <span class="input-group-text">Max.Vægt</span> <span class="input-group-text">KG</span> </div> <input type="number" class="form-control" placeholder="Max.Vægt" min="0" name="FORMNAME_MaxVaegt"> </div> </div> <!-- Tatoveringer --> <div class="col-md-3"> <div class="input-group"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect_TATOVERINGER">Tatoveringer</label> </div> <select class="custom-select" id="inputGroupSelect_TATOVERINGER" name="FORMNAME_Tatoveringer"> <option selected disabled hidden>Tatoveringer</option> <?php $query_6 = "SELECT * FROM users_info_tatoveringer"; $result_6 = mysqli_query($dblink, $query_6) or die ( mysqli_error($dblink) ); while( $row_6 = mysqli_fetch_array($result_6) ) { $selected = ($row_6['usersinfoTatoveringer_id'] == $row_1['usersinfo_FK_usersinfoTatoveringer_id']) ? 'selected="selected"' : ''; echo '<option value="'.$row_6['usersinfoTatoveringer_id'].'" '.$selected.'>'.$row_6['usersinfoTatoveringer_name'].'</option>'; } ?> </select> </div> </div> <!-- Kategorier --> <div class="col-md-3"> <?php //include_once("include/files/www-files/form_parts/searchprofiles_multiselect/multiselect_kategori.php"); ?> <div class="input-group"> <div class="input-group-prepend"> <label class="input-group-text" for="inputGroupSelect_KATEGORI">Kategorier</label> </div> <select class="custom-select" id="inputGroupSelect_KATEGORI" name="FORMNAME_Kategorier"> <option selected disabled hidden>Kategorier</option> <?php $query_7 = "SELECT * FROM users_info_kategorier"; $result_7 = mysqli_query($dblink, $query_7) or die ( mysqli_error($dblink) ); while( $row_7 = mysqli_fetch_array($result_7) ) { $selected = ($row_7['usersinfoKategorier_id'] == $row_1['usersinfo_FK_usersinfoKategorier_id']) ? 'selected="selected"' : ''; echo '<option value="'.$row_7['usersinfoKategorier_id'].'" '.$selected.'>'.$row_7['usersinfoKategorier_name'].'</option>'; } ?> </select> </div> </div> </div><!-- //.row --> </div><!-- //.container --> </div><!-- //.row (udvidet søgning) --> </form> </div> <div class="mt-3"></div> <div class="container"> <?php if( isset($_POST['FORMNAME_submit_search']) ) { //include_once("functions.pagination.class.php"); // include pagination $qur = ""; @$SearchKeywords = mysqli_real_escape_string($dblink, $_POST['FORMNAME_SogProfilBar_Keywords']); // Search Bar Profil Keywords @$MinAlder = mysqli_real_escape_string($dblink, $_POST['FORMNAME_MinAlder']); // Minimum Alder @$MaxAlder = mysqli_real_escape_string($dblink, $_POST['FORMNAME_MaxAlder']); // Maximum Alder @$Landsdel = mysqli_real_escape_string($dblink, $_POST['FORMNAME_Landsdel']); // Landsdel @$Kon = mysqli_real_escape_string($dblink, $_POST['FORMNAME_Kon']); // Køn @$MinHojde = mysqli_real_escape_string($dblink, $_POST['FORMNAME_MinHojde']); // Minimum Højde @$MaxHojde = mysqli_real_escape_string($dblink, $_POST['FORMNAME_MaxHojde']); // Maximum Højde @$Etnicitet = mysqli_real_escape_string($dblink, $_POST['FORMNAME_Etnicitet']); // Etnicitet @$Sprog = mysqli_real_escape_string($dblink, $_POST['FORMNAME_Sprog']); // Sprog @$MinVaegt = mysqli_real_escape_string($dblink, $_POST['FORMNAME_MinVaegt']); // Minimum Vægt @$MaxVaegt = mysqli_real_escape_string($dblink, $_POST['FORMNAME_MaxVaegt']); // Maximum Vægt @$Tatoveringer = mysqli_real_escape_string($dblink, $_POST['FORMNAME_Tatoveringer']); // Tatoveringer @$Kategorier = mysqli_real_escape_string($dblink, $_POST['FORMNAME_Kategorier']); // Kategorier // Søgning af ALT starter her. $query = "SET SESSION sql_mode='STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION'"; $result = mysqli_query($dblink, $query) or die(mysqli_error($dblink)); $query = htmlentities(" SELECT DISTINCT users_id, users_fornavn, users_mellemnavn, users_efternavn, users_email, users_city, users_zipcode, users_birthday_date, users_address, users_tlf_telefon, users_tlf_mobil, usersinfo_profilesearch_viewable, usersinfo_hojde_cm, usersinfo_vaegt_kg, usersinfo_ErfaringKvalifikationer, usersinfo_beskaeftigelse, usersinfo_FK_usersinfoHairColor_id, usersinfo_FK_usersinfoEyeColor_id, usersinfo_FK_usersinfoBukseBredde_id, usersinfo_FK_usersinfoBukseLaengde_id, usersinfo_FK_usersinfoBluseStorrelse_id, usersinfo_FK_usersinfoSkoStorrelse_id, usersinfo_FK_usersinfoLandsdel_id, usersinfo_FK_usersinfoEtnicitet_id, usersinfo_FK_usersinfoTatoveringer_id, usersinfo_FK_usersinfoKategorier_id, usersinfo_FK_usersinfoSprog_id, usersGender_id, usersGender_name, usersinfoLandsdel_id, usersinfoLandsdel_name, usersinfoEtnicitet_id, usersinfoEtnicitet_name, usersinfoTatoveringer_id, usersinfoTatoveringer_name, usersinfoSprog_id, usersinfoSprog_name, usersinfoKategorier_id, usersinfoKategorier_name FROM users INNER JOIN users_info ON users.users_id = users_info.usersinfo_FK_users_id INNER JOIN users_gender ON users.users_FK_usersGender_id = users_gender.usersGender_id INNER JOIN users_info_landsdel ON users_info.usersinfo_FK_usersinfoLandsdel_id = users_info_landsdel.usersinfoLandsdel_id INNER JOIN users_info_etnicitet ON users_info.usersinfo_FK_usersinfoEtnicitet_id = users_info_etnicitet.usersinfoEtnicitet_id INNER JOIN users_info_tatoveringer ON users_info.usersinfo_FK_usersinfoTatoveringer_id = users_info_tatoveringer.usersinfoTatoveringer_id INNER JOIN users_info_sprog ON users_info.usersinfo_FK_usersinfoSprog_id = users_info_sprog.usersinfoSprog_id INNER JOIN users_info_kategorier ON users_info.usersinfo_FK_usersinfoKategorier_id = users_info_kategorier.usersinfoKategorier_id "); // Search patterns - needs editing! from old-original to my version so it fits! include_once("index.search_patterns_setup.php"); // fortsætter herunder $query .= " GROUP BY users_id, usersinfo_FK_users_id"; $result = mysqli_query($dblink, $query) or die(mysqli_error($dblink)); // hvis der ikke er EN række i udtrækket, vises en fejlbesked (??? på search eller ???) //$searchCount=mysqli_num_rows($result); // Behøver jeg denne del (???) // OG START PÅ "<?PHP ?\>" - HTML KOMMER HER IFØLGE TIDLIGERE KODE! (tror jeg skipper den del!) if( mysqli_num_rows($result) > 0 ) { while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC)) { echo '<p>her er jeg!</p>'; // indsæt søge resultater her! } } else { $row = '<p>Der var desværre ingen resultater på din søgning. Prøv igen.</p>'; echo '<h3>'.$row.'</h3>'; die(); } } else { //include_once("functions.pagination.class.php"); // include pagination include_once("index.no_search_show_cards_profiles.php"); } ?> </div> <script> $('.JQUERY_ACTION_expand_search').on('click', function () { $(this).parent().parent().parent().next().next().show(1000); }); $('.JQUERY_ACTION_minimize_search').on('click', function () { $(this).parent().parent().parent().parent().hide(1000); }); </script> functions.pagination.class.php <?php class pagination { /* Properties array @var array @access private */ private $_properties = array(); /* Default configurations @var array @access public */ public $_defaults = array( 'page' => 1, 'perPage' => 10 ); /* Constructor @param array $array Array of results to be paginated @param int $curPage The current page interger that should used @param int $perPage The amount of items that should be show per page @return void @access public */ public function __construct($array, $curPage = null, $perPage = null) { $this->array = $array; $this->curPage = ($curPage == null ? $this->defaults['page'] : $curPage); $this->perPage = ($perPage == null ? $this->defaults['perPage'] : $perPage); } /* Global setter Utilises the properties array @param string $name The name of the property to set @param string $value The value that the property is assigned @return void @access public */ public function __set($name, $value) { $this->_properties[$name] = $value; } /* Global getter Takes a param from the properties array if it exists @param string $name The name of the property to get @return mixed Either the property from the internal properties array or false if isn't set @access public */ public function __get($name) { if (array_key_exists($name, $this->_properties)) { return $this->_properties[$name]; } return false; } /* Set the show first and last configuration This will enable the "<< first" and "last >>" style links @param boolean $showFirstAndLast True to show, false to hide. @return void @access public */ public function setShowFirstAndLast($showFirstAndLast) { $this->_showFirstAndLast = $showFirstAndLast; } /* Set the main seperator character By default this will implode an empty string @param string $mainSeperator The seperator between the page numbers @return void @access public */ public function setMainSeperator($mainSeperator) { $this->mainSeperator = $mainSeperator; } /* Get the result portion from the provided array @return array Reduced array with correct calculated offset @access public */ public function getResults() { // Assign the page variable if (empty($this->curPage) !== false) { $this->page = $this->curPage; // using the get method } else { $this->page = 1; // if we don't have a page number then assume we are on the first page } // Take the length of the array $this->length = count($this->array); // Get the number of pages $this->pages = ceil($this->length / $this->perPage); // Calculate the starting point $this->start = ceil(($this->page - 1) * $this->perPage); // return the portion of results return array_slice($this->array, $this->start, $this->perPage); } /* Get the html links for the generated page offset @param array $params A list of parameters (probably get/post) to pass around with each request @return mixed Return description (if any)... @access public */ public function getLinks($params = array()) { // Initiate the links array $plinks = array(); $links = array(); $slinks = array(); // Concatenate the get variables to add to the page numbering string $queryUrl = ''; if (!empty($params) === true ) { unset($params['page']); $queryUrl = '&amp;'.http_build_query($params); } // If we have more then one pages if (($this->pages) > 1) { // Assign the 'previous page' link into the array if we are not on the first page if ($this->page != 1) { if ($this->_showFirstAndLast) { $plinks[] = ' <a href="?page=1'.$queryUrl.'">&laquo;&laquo; First </a> '; } $plinks[] = ' <a href="?page='.($this->page - 1).$queryUrl.'">&laquo; Prev</a> '; } // Assign all the page numbers & links to the array for ($j = 1; $j < ($this->pages + 1); $j++) { if ($this->page == $j) { $links[] = ' <a class="selected">'.$j.'</a> '; // If we are on the same page as the current item } else { $links[] = ' <a href="?page='.$j.$queryUrl.'">'.$j.'</a> '; // add the link to the array } } // Assign the 'next page' if we are not on the last page if ($this->page < $this->pages) { $slinks[] = ' <a href="?page='.($this->page + 1).$queryUrl.'"> Next &raquo; </a> '; if ($this->_showFirstAndLast) { $slinks[] = ' <a href="?page='.($this->pages).$queryUrl.'"> Last &raquo;&raquo; </a> '; } } // Push the array into a string using any some glue return implode(' ', $plinks).implode($this->mainSeperator, $links).implode(' ', $slinks); } return; } } functions.php <?php // clause CHECK AND function // function clauseCHECK_AND () { global $clause; if( isset($clause) ) { $clause = " AND "; //echo "CLAUSE ER WHERE:"; } else { $clause = " WHERE "; } } // clause CHECK OR function // function clauseCHECK_OR () { global $clause; if( isset($clause) ) { $clause = " OR "; //echo "CLAUSE ER WHERE:"; } else { $clause = " WHERE "; } } ?> index.no_search_show_cards_profiles.php <div class="container"> <div class="card-columns"> <?php $query_100 = "SELECT * FROM users ORDER BY users_id DESC"; $result_100 = mysqli_query($dblink, $query_100) or die(mysqli_error($dblink)); if( mysqli_num_rows($result_100) > 0 ) { if( mysqli_num_rows($result_100) > 0 ) { while( $row_100 = mysqli_fetch_array($result_100) ) { $user_id = $row_100['users_id']; $user_fornavn = $row_100['users_fornavn']; $dateOfBirth = $row_100['users_birthday_date']; // output: Y-m-d (Year-Month-Day) $today = date("Y-m-d"); // current date today $diff = date_diff(date_create($dateOfBirth), date_create($today)); // difference between the two dates ?> <div class="card"> <a href="#" title="Profil"> <img class="card-img-top img-responsive img-rounded" src="https://dummyimage.com/250x330/000/fff.jpg" alt="Billede"> </a> <div class="card-body"> <h5 class="card-title"><b><?php echo $user_fornavn.',&nbsp;'.$diff->format('%y'); ?></b></h5> <p class="card-text">#<?php echo $user_id; ?></p> </div><!-- //.card-body --> </div><!-- //.card --> <?php } } } else { echo 'Intet at vise lige nu.'; } ?> </div> </div> index.search_patterns_setup.php <?php /////////////////////////// ALDER /////////////////////////// // ORIGINAL /* if( $minAlder > 0 ) { $time = new DateTime('now'); $newtime = $time->modify('-'.$minAlder.' year')->format('Y-m-d'); //echo $newtime; echo clauseCHECK(); $query .= $clause." user_dob <= '$newtime' "; //$clause .= " OR ";//Change to OR after 1st WHERE } if( $maxAlder > 0 ) { echo clauseCHECK(); $time = new DateTime('now'); $newtime = $time->modify('-'.$maxAlder.' year')->format('Y-m-d'); //echo $newtime; $query .= $clause." user_dob >= '$newtime' "; //$clause .= " OR ";//Change to OR after 1st WHERE } */ // MY VERSION if( $MinAlder > 0 ) { //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; // dob = Date Of Birth $time = new DateTime('now'); $newtime = $time->modify('-'.$MinAlder.' year')->format('Y-m-d'); $query .= $clause." users_birthday_date <= '$newtime' "; } if( $MaxAlder > 0 ) { //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; // dob = Date Of Birth $time = new DateTime('now'); $newtime = $time->modify('-'.$MaxAlder.' year')->format('Y-m-d'); $query .= $clause." users_birthday_date >= '$newtime' "; } /////////////////////////// KØN /////////////////////////// // ORIGINAL /* if( !empty($reg_koen) ) { echo clauseCHECK(); $query .= $clause." user_koen = '$reg_koen' "; //$clause .= " OR ";//Change to OR after 1st WHERE } */ // MY VERSION if( !empty($Kon) ) { //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause." usersGender_id = '$Kon' "; } /////////////////////////// LANDSDEL /////////////////////////// // ORIGINAL /* if( !empty($reg_Landsdel) ) { echo clauseCHECK(); $query .= $clause." user_landsdel = '$reg_Landsdel' "; //$clause .= " OR ";//Change to OR after 1st WHERE } */ // MY VERSION if( !empty($Landsdel) ) { //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause." usersinfoLandsdel_id = '$Landsdel' "; } /////////////////////////// ETNICITET /////////////////////////// // ORIGINAL /* if( !empty($reg_etnic) ) { echo clauseCHECK(); $query .= $clause." user_etnicitet = '$reg_etnic' "; //$clause .= " OR ";//Change to OR after 1st WHERE } */ // MY VERSION if( !empty($Etnicitet) ) { //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause." usersinfoEtnicitet_id = '$Etnicitet' "; } /////////////////////////// TATOVERINGER /////////////////////////// // ORIGINAL /* if( !empty($_POST['check_listTat']) ) { // Loop to store and display values of individual checked checkbox. foreach($_POST['check_listTat'] as $c) { if( !empty($c) ) { echo clauseCHECKor(); $qur = "userPers_fk_tat_id"; $query .= $clause."".$qur." LIKE '%{$c}%'"; //$clause = " OR ";//Change to OR after 1st WHERE } } } */ // MY VERSION if( !empty($Tatoveringer) ) { // når jeg skifter til checkboxes, bruger jeg clauseCHECK_OR()! Som den bruges i de originale! Tjek for eksempler! //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause." usersinfoTatoveringer_id = '$Tatoveringer' "; } /////////////////////////// SPROG /////////////////////////// // ORIGINAL /* if( !empty($_POST['check_listSprog']) ) { // Loop to store and display values of individual checked checkbox. foreach($_POST['check_listSprog'] as $c) { if( !empty($c) ) { echo clauseCHECKor(); $qur = "userPers_fk_sprog_id"; $query .= $clause."".$qur." LIKE '%{$c}%'"; $clause = " OR "; //Change to OR after 1st WHERE } } //echo $query;//Remove after testing } */ // MY VERSION if( !empty($Sprog) ) { // når jeg skifter til checkboxes, bruger jeg clauseCHECK_OR()! Som den bruges i de originale! Tjek for eksempler! //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause." usersinfoSprog_id = '$Sprog' "; } /////////////////////////// KATEGORIER /////////////////////////// // ORIGINAL /* if( !empty($_POST['check_listKat']) ) { // Loop to store and display values of individual checked checkbox. // Loop to store and display values of individual checked checkbox. foreach($_POST['check_listKat'] as $c) { if( !empty($c) ) { echo clauseCHECKor(); $qur = "userPers_fk_kat_id"; $query .= $clause."".$qur." LIKE '%{$c}%'"; $clause = " OR ";//Change to OR after 1st WHERE } } } */ // MY VERSION if( !empty($Kategorier) ) { // når jeg skifter til checkboxes, bruger jeg clauseCHECK_OR()! Som den bruges i de originale! Tjek for eksempler! //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause." usersinfoKategorier_id = '$Kategorier' "; } /////////////////////////// VÆGT /////////////////////////// // ORIGINAL /* if( $reg_vaegt_min>0 && $reg_vaegt_max<1 ) { $reg_vaegt_max="999"; } if( $reg_vaegt_max>0 && $reg_vaegt_min<1 ) { $reg_vaegt_min="1"; } if( $reg_vaegt_min>0 || $reg_vaegt_min>0 ) { echo clauseCHECK(); //echo "<br><hr><br>HER er vægt.<br><br>"; $query .= $clause."user_vaegt BETWEEN $reg_vaegt_min AND $reg_vaegt_max "; $clause = " OR "; } */ // MY VERSION if( $MinVaegt>0 && $MaxVaegt<1 ) { $reg_vaegt_max="999"; } if( $MaxVaegt>0 && $MinVaegt<1 ) { $reg_vaegt_min="1"; } if( $MinVaegt>0 || $MinVaegt>0 ) { // når jeg skifter til checkboxes, bruger jeg clauseCHECK_OR()! Som den bruges i de originale! Tjek for eksempler! //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause."userinfo_vaegt_kg BETWEEN $MinVaegt AND $MaxVaegt "; $clause = " OR "; } /////////////////////////// HØJDE /////////////////////////// // ORIGINAL /* if( $reg_hoejde_min>0 && $reg_hoejde_max<1 ) { $reg_hoejde_max="999"; } if( $reg_hoejde_max>0 && $reg_hoejde_min<1 ) { $reg_hoejde_min="1"; } if( $reg_hoejde_min>0 || $reg_hoejde_min>0 ) { echo clauseCHECK(); //echo "<br><hr><br>HER er vægt.<br><br>"; $query .= $clause."user_hoejde BETWEEN $reg_hoejde_min AND $reg_hoejde_max "; $clause = " OR "; } */ // MY VERSION if( $MinHojde>0 && $MaxHojde<1 ) { $reg_hoejde_max="999"; } if( $MaxHojde>0 && $MinHojde<1 ) { $reg_hoejde_min="1"; } if( $MinHojde>0 || $MinHojde>0 ) { // når jeg skifter til checkboxes, bruger jeg clauseCHECK_OR()! Som den bruges i de originale! Tjek for eksempler! //echo clauseCHECK_AND(); echo "<p>".clauseCHECK_AND()."</p>"; $query .= $clause."usersinfo_hojde_cm BETWEEN $MinHojde AND $MaxHojde "; $clause = " OR "; } /////////////////////////// KEYWORDS /////////////////////////// // ORIGINAL /* //if keyword set, goes here if( !$keyword=="" ) { echo clauseCHECK();//Initial clause $c=" user_unikID LIKE '%$keyword%' OR user_fornavn LIKE '%$keyword%' OR user_efternavn LIKE '%$keyword%' OR user_faerdigheder LIKE '%$keyword%' OR user_etnicitet LIKE '%$keyword%' OR user_haarfarve LIKE '%$keyword%' OR user_haartype LIKE '%$keyword%' OR user_ojenfarve LIKE '%$keyword%' "; $query .= $clause." $c"; } */ // MY VERSION //if keyword set, goes here if( !$SearchKeywords=="" ) { //echo clauseCHECK_AND(); // Initial clause echo "<p>".clauseCHECK_AND()."</p>"; // Initial clause // unikID = old wwww-files :: ROOT/call/reg_sessioncall.php :: line ~290+ (cirka) // search query /* $c = " user_unikID LIKE '%$SearchKeywords%' OR users_fornavn LIKE '%$SearchKeywords%' OR users_mellemnavn LIKE '%$SearchKeywords%' OR users_efternavn LIKE '%$SearchKeywords%' OR users_faerdigheder LIKE '%$SearchKeywords%' OR user_etnicitet LIKE '%$SearchKeywords%' OR user_haarfarve LIKE '%$SearchKeywords%' OR user_haartype LIKE '%$SearchKeywords%' OR user_ojenfarve LIKE '%$SearchKeywords%' "; */ $c = " user_unikID LIKE '%$SearchKeywords%' OR users_fornavn LIKE '%$SearchKeywords%' OR users_mellemnavn LIKE '%$SearchKeywords%' OR users_efternavn LIKE '%$SearchKeywords%' "; $query .= $clause." $c"; } ?> ----------------------------------------------------------------- Okay, as you might have guessed, the code is a little long. (yay). Okay, so i have "tried" to clean up the past coding the best i could, BUT, here is where i get lost a bit. In the main query on PAGE_searchprofiles.php - am i supposed to make a lot of inner joins? I did that one myself, but wonna make sure BECAUSE! I have a LOT of tables and rows in the DB. I have a main table, users, where basic info is like firstname, etc. Then i have another called users_info, having a lot of integers with 1ns and zeros... those numbers are supposed to go to another table, for each table with Foreign Keys (FK), containing names, etc of forms and so on. I thought it would be better this way for the select at the time, and it was, but also worse for the search query because i have no idea if i am doing that part correct. Also with the file (index.search_patterns_setup.php) - not sure if i do the if/else's correct, since i just reused the old coders parameters and just changed the variables and queries to my database and variable names so they would look perfectly, and they do, only not sure if it's working or not :/ Mostly because whenever i make a search, nothing comes out, no errors either, just no rows. Not sure if i pinpoint the whole thing at different ways with id's etc with inner joins at the main query and the parameters if/else's statements. This is my current DB (query a little bit, but if you can check it out, go for it, just remember, it is in Danish some of it and some in English... combined the 2 languages for some text hehe): -- phpMyAdmin SQL Dump -- version 4.7.0 -- https://www.phpmyadmin.net/ -- -- Host: localhost -- Generation Time: Mar 10, 2018 at 10:35 AM -- Server version: 5.7.18 -- PHP Version: 7.1.5 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET AUTOCOMMIT = 0; START TRANSACTION; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `u1d4zzx` -- -- -------------------------------------------------------- -- -- Table structure for table `carousel1` -- CREATE TABLE `carousel1` ( `carousel1_id` int(11) NOT NULL, `carousel1_img_url` text NOT NULL, `carousel1_title` text NOT NULL, `carousel1_description` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `carousel1` -- INSERT INTO `carousel1` (`carousel1_id`, `carousel1_img_url`, `carousel1_title`, `carousel1_description`) VALUES (1, '1.PNG', 'No Title 1', 'No Description 1'), (2, '2.jpg', 'No Title 2', 'No Description 2'), (3, '3.jpg', 'No Title 3', 'No Description 3'), (4, '4.jpeg', 'No Title 4', 'No Description 4'); -- -------------------------------------------------------- -- -- Table structure for table `page_work1_videos` -- CREATE TABLE `page_work1_videos` ( `pw1videos_id` int(11) NOT NULL, `pw1videos_link` text NOT NULL, `pw1videos_director` text NOT NULL, `pw1videos_title` text NOT NULL, `pw1videos_text` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `page_work1_videos` -- INSERT INTO `page_work1_videos` (`pw1videos_id`, `pw1videos_link`, `pw1videos_director`, `pw1videos_title`, `pw1videos_text`) VALUES (6, 'DxiOVmuZyw4', 'Simon Bonde', 'Tuborg Classic', 'All Cast'), (7, 'BDhC7DU0yYE', ' ', 'Hi-Fi Klubben', 'Extras'), (8, 'nN1GLigSw40', 'Jannik Vestmar', 'Krifa', 'All Cast'), (9, 'wBC1WWO9AUc', 'Stevan Treshow', 'Oddset', 'All Cast'), (10, 'FH5cw-n00T8', 'Stevan Treshow', 'Oddset', 'All Cast'), (11, 'L7D1G8vgkEQ', 'Stevan Treshow', 'Oddset', 'All Cast'), (12, '_kASjW_aPbQ', 'Nadia Marquard', 'Emelie Sandé Wonder', 'Cast & Extras'), (14, '0rbA2qBDn8A', ' ', 'Ikano Bank', 'Cast '), (15, 'NYndyqp1gDU', ' ', 'Just Eat', 'All Cast'), (16, 't9diF_GKImA', ' ', 'Just Eat', 'All Cast'), (17, 'zvK8WL43kdY', 'Jonas Elmer', 'Betsafe', 'Cast '), (18, '0bPWGoTRFc0', 'Michael Langhoff', 'Øresundsbroen', 'Extras'), (19, 'MBcU7VCh_MM', 'Michael Langhoff', 'Øresundsbroen', 'Extras'), (20, '_m_KUK6QFS0', 'Michael Langhoff', 'Øresundsbroen', 'Extras'), (21, 'p7QrsVAEwIU', 'Michael Langhoff', 'Øresundsbroen', 'Extras'), (23, 'hmdlCmLrD8A', 'Simon Bonde & Michael Spooner', 'Ladbrokes', 'Cast & Extras'), (29, 'TjHSXd0CcNI', 'Fredrik Callinggard', 'Ofir', 'All Cast'), (30, 'CfAyPqhbeCM', 'Mats Stenberg', 'Casino.dk', 'Ekstra'), (31, 'Aml0d-e6czg', 'Michael Langhoff', 'DayDose', 'Extras'), (32, '5AdMpkKrlDE', '', 'Unibet ', 'Extras'), (33, 'jY-PZ4tMwXU', '', 'Unibet', 'Extras'), (38, '7Cd3UbueGzM', 'Fredrik Callinggard', 'Ofir', 'All Cast'), (42, 'R3JqzsNuer8', 'Gaute Hesthagen ', 'Telenor', 'All Cast'), (46, 'mmHpWlTZEk4', 'Gaute Hesthagen ', 'Telenor', 'All Cast'), (47, 'W3p0yzLc_js', 'Gaute Hesthagen ', 'Telenor', 'All Cast'), (49, '8IIGUBV-jqo', ' ', 'Mobilepay', 'All Cast'), (50, 'MQ_uMGxRvH8', '', 'Bygma', 'Extras'); -- -------------------------------------------------------- -- -- Table structure for table `users` -- CREATE TABLE `users` ( `users_id` int(11) NOT NULL, `users_ActiveState` int(11) NOT NULL DEFAULT '0', `users_fornavn` varchar(255) NOT NULL, `users_mellemnavn` varchar(255) NOT NULL, `users_efternavn` varchar(255) NOT NULL, `users_email` text NOT NULL, `users_password` text NOT NULL, `users_FK_usersGender_id` int(11) NOT NULL DEFAULT '0', `users_city` varchar(255) NOT NULL, `users_zipcode` int(11) NOT NULL, `users_birthday_date` date DEFAULT NULL, `users_address` text NOT NULL, `users_tlf_telefon` int(11) NOT NULL DEFAULT '0', `users_tlf_mobil` int(11) NOT NULL DEFAULT '0', `users_FK_usersSubscription_id` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users` -- INSERT INTO `users` (`users_id`, `users_ActiveState`, `users_fornavn`, `users_mellemnavn`, `users_efternavn`, `users_email`, `users_password`, `users_FK_usersGender_id`, `users_city`, `users_zipcode`, `users_birthday_date`, `users_address`, `users_tlf_telefon`, `users_tlf_mobil`, `users_FK_usersSubscription_id`) VALUES (2, 1, 'd', 'd', 'd', 'd@yahoo.co.uk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 2, 'FREDERIKSBERG C', 1851, '1992-11-08', 'Nyvej 16, 2TV', 44444444, 44444444, 3), (3, 0, 'dwjioj', 'odj', 'woidjo', 'derp@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 2, 'd C', 1851, '1992-11-08', 'diwjdo, 2TV', 44444444, 44444444, 2), (4, 0, 'Danie', ' ', 'Pedersen', 'd@yahoo.com', '4c65f054573c27e35eefcdd5d6b31091516827fa', 2, 'd C', 1851, '1992-11-08', ' ', 44444444, 44444444, 1), (5, 0, 'Uglen', ' ', 'Elsker', 'demo1@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 1, 'd C', 6666, '1992-11-08', ' ', 44444444, 44444444, 1), (6, 0, 'Ugleerne', ' ', 'Elskerne', 'demo2@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 1, 'd C', 6666, '1992-11-08', ' ', 44444444, 44444444, 1), (7, 0, 'derpy', ' ', 'derp', 'demo3@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 1, 'd C', 2000, '1992-11-08', ' ', 44444444, 51444379, 3), (8, 0, 'wdwe', '', 'dwad', 'demo4@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 1, 'd C', 5151, '2018-12-31', '', 51444379, 44444444, 1), (9, 0, 'wdwe', '', 'dwad', 'demo5@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 1, 'd C', 5151, '2018-12-31', '', 44444444, 51444379, 1), (10, 0, 'Karsten', '', 'Larsen', 'demo7@yahoo.dk', '4c65f054573c27e35eefcdd5d6b31091516827fa', 2, 'd C', 1851, '1992-11-08', '', 51444379, 44444444, 1); -- -------------------------------------------------------- -- -- Table structure for table `users_files` -- CREATE TABLE `users_files` ( `usersFiles_id` int(11) NOT NULL, `usersFiles_FK_users_id` int(11) NOT NULL DEFAULT '0', `usersFiles_avatar_1` text NOT NULL, `usersFiles_image_1` text NOT NULL, `usersFiles_image_2` text NOT NULL, `usersFiles_image_3` text NOT NULL, `usersFiles_image_4` text NOT NULL, `usersFiles_image_5` text NOT NULL, `usersFiles_image_6` text NOT NULL, `usersFiles_image_7` text NOT NULL, `usersFiles_image_8` text NOT NULL, `usersFiles_image_9` text NOT NULL, `usersFiles_image_10` text NOT NULL, `usersFiles_video_1` text NOT NULL, `usersFiles_video_2` text NOT NULL, `usersFiles_video_3` text NOT NULL, `usersFiles_video_4` text NOT NULL, `usersFiles_video_5` text NOT NULL, `usersFiles_video_6` text NOT NULL, `usersFiles_video_7` text NOT NULL, `usersFiles_video_8` text NOT NULL, `usersFiles_video_9` text NOT NULL, `usersFiles_video_10` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_files` -- INSERT INTO `users_files` (`usersFiles_id`, `usersFiles_FK_users_id`, `usersFiles_avatar_1`, `usersFiles_image_1`, `usersFiles_image_2`, `usersFiles_image_3`, `usersFiles_image_4`, `usersFiles_image_5`, `usersFiles_image_6`, `usersFiles_image_7`, `usersFiles_image_8`, `usersFiles_image_9`, `usersFiles_image_10`, `usersFiles_video_1`, `usersFiles_video_2`, `usersFiles_video_3`, `usersFiles_video_4`, `usersFiles_video_5`, `usersFiles_video_6`, `usersFiles_video_7`, `usersFiles_video_8`, `usersFiles_video_9`, `usersFiles_video_10`) VALUES (1, 2, '9e711fd22a826bf711a2f748692cf781.jpg', '', '', '', '', '', '', '', '', '', '16b72540e572da3f3ab5753e6034ab2d--rubber-catsuit-fetish-fashion.jpg', '', '', '', '', '', '', '', 'C3322_B_1.jpg', '', ''), (2, 10, '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', ''); -- -------------------------------------------------------- -- -- Table structure for table `users_gender` -- CREATE TABLE `users_gender` ( `usersGender_id` int(11) NOT NULL, `usersGender_name` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_gender` -- INSERT INTO `users_gender` (`usersGender_id`, `usersGender_name`) VALUES (1, 'Andet'), (2, 'Mand'), (3, 'Kvinde'); -- -------------------------------------------------------- -- -- Table structure for table `users_info` -- CREATE TABLE `users_info` ( `usersinfo_id` int(11) NOT NULL, `usersinfo_FK_users_id` int(11) NOT NULL DEFAULT '0', `usersinfo_hojde_cm` int(11) NOT NULL DEFAULT '0', `usersinfo_vaegt_kg` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoHairColor_id` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoEyeColor_id` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoBukseBredde_id` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoBukseLaengde_id` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoBluseStorrelse_id` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoSkoStorrelse_id` int(11) NOT NULL DEFAULT '0', `usersinfo_ErfaringKvalifikationer` text NOT NULL, `usersinfo_beskaeftigelse` text NOT NULL, `usersinfo_profilesearch_viewable` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoTatoveringer_id` varchar(255) NOT NULL, `usersinfo_FK_usersinfoKategorier_id` varchar(255) NOT NULL, `usersinfo_FK_usersinfoSprog_id` varchar(255) NOT NULL, `usersinfo_FK_usersinfoLandsdel_id` int(11) NOT NULL DEFAULT '0', `usersinfo_FK_usersinfoEtnicitet_id` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info` -- INSERT INTO `users_info` (`usersinfo_id`, `usersinfo_FK_users_id`, `usersinfo_hojde_cm`, `usersinfo_vaegt_kg`, `usersinfo_FK_usersinfoHairColor_id`, `usersinfo_FK_usersinfoEyeColor_id`, `usersinfo_FK_usersinfoBukseBredde_id`, `usersinfo_FK_usersinfoBukseLaengde_id`, `usersinfo_FK_usersinfoBluseStorrelse_id`, `usersinfo_FK_usersinfoSkoStorrelse_id`, `usersinfo_ErfaringKvalifikationer`, `usersinfo_beskaeftigelse`, `usersinfo_profilesearch_viewable`, `usersinfo_FK_usersinfoTatoveringer_id`, `usersinfo_FK_usersinfoKategorier_id`, `usersinfo_FK_usersinfoSprog_id`, `usersinfo_FK_usersinfoLandsdel_id`, `usersinfo_FK_usersinfoEtnicitet_id`) VALUES (1, 2, 176, 130, 4, 1, 14, 21, 6, 29, ' Info tekst mangler. ', ' Info tekst mangler. ', 0, '', '', '', 0, 0); -- -------------------------------------------------------- -- -- Table structure for table `users_info_bluse_storrelse` -- CREATE TABLE `users_info_bluse_storrelse` ( `usersinfoBluseStorrelse_id` int(11) NOT NULL, `usersinfoBluseStorrelse_storrelse` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_bluse_storrelse` -- INSERT INTO `users_info_bluse_storrelse` (`usersinfoBluseStorrelse_id`, `usersinfoBluseStorrelse_storrelse`) VALUES (1, 'X-Small'), (2, 'Small'), (3, 'Medium'), (4, 'Large'), (5, 'X-Large'), (6, 'XX-Large'), (7, 'XXX-Large'); -- -------------------------------------------------------- -- -- Table structure for table `users_info_bukse_bredde` -- CREATE TABLE `users_info_bukse_bredde` ( `usersinfoBukseBredde_id` int(11) NOT NULL, `usersinfoBukseBredde_bredde` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_bukse_bredde` -- INSERT INTO `users_info_bukse_bredde` (`usersinfoBukseBredde_id`, `usersinfoBukseBredde_bredde`) VALUES (1, 24), (2, 25), (3, 26), (4, 27), (5, 28), (6, 29), (7, 30), (8, 31), (9, 32), (10, 33), (11, 34), (12, 35), (13, 36), (14, 37), (15, 38), (16, 39), (17, 40), (18, 41), (19, 42), (20, 43), (21, 44), (22, 45); -- -------------------------------------------------------- -- -- Table structure for table `users_info_bukse_laengde` -- CREATE TABLE `users_info_bukse_laengde` ( `usersinfoBukseLaengde_id` int(11) NOT NULL, `usersinfoBukseLaengde_laengde` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_bukse_laengde` -- INSERT INTO `users_info_bukse_laengde` (`usersinfoBukseLaengde_id`, `usersinfoBukseLaengde_laengde`) VALUES (1, 24), (2, 25), (3, 26), (4, 27), (5, 28), (6, 29), (7, 30), (8, 31), (9, 32), (10, 33), (11, 34), (12, 35), (13, 36), (14, 37), (15, 38), (16, 39), (17, 40), (18, 41), (19, 42), (20, 43), (21, 44), (22, 45), (23, 46), (24, 47), (25, 48); -- -------------------------------------------------------- -- -- Table structure for table `users_info_etnicitet` -- CREATE TABLE `users_info_etnicitet` ( `usersinfoEtnicitet_id` int(11) NOT NULL, `usersinfoEtnicitet_name` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- -- -- Table structure for table `users_info_eye_color` -- CREATE TABLE `users_info_eye_color` ( `usersinfoEyeColor_id` int(11) NOT NULL, `usersinfoEyeColor_name` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_eye_color` -- INSERT INTO `users_info_eye_color` (`usersinfoEyeColor_id`, `usersinfoEyeColor_name`) VALUES (1, 'Blå'), (2, 'Grønne'), (3, 'Brune'), (4, 'Grå'); -- -------------------------------------------------------- -- -- Table structure for table `users_info_hair_color` -- CREATE TABLE `users_info_hair_color` ( `usersinfoHairColor_id` int(11) NOT NULL, `usersinfoHairColor_color` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_hair_color` -- INSERT INTO `users_info_hair_color` (`usersinfoHairColor_id`, `usersinfoHairColor_color`) VALUES (1, 'Hvidt'), (2, 'Platinblond'), (3, 'Lysblond'), (4, 'Mellemblond'), (5, 'Mørkeblond'), (6, 'Rødblond'), (7, 'Rød'), (8, 'Lysebrunt'), (9, 'Brunt'), (10, 'Mørkebrunt'), (11, 'Sort'), (12, 'Gråt'), (13, 'Grå stænk'), (14, 'Anden'); -- -------------------------------------------------------- -- -- Table structure for table `users_info_kategorier` -- CREATE TABLE `users_info_kategorier` ( `usersinfoKategorier_id` int(11) NOT NULL, `usersinfoKategorier_name` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_kategorier` -- INSERT INTO `users_info_kategorier` (`usersinfoKategorier_id`, `usersinfoKategorier_name`) VALUES (1, 'Uddannet skuespiller'), (2, 'Autodidakt skuespiller'), (3, 'Ingen erfaring (indenfor film, reklamer, TV)'), (4, 'Statist'), (5, 'Sanger'), (6, 'Danser'), (7, 'Tvilling'), (8, 'Mor til børn'), (9, 'Far til børn'); -- -------------------------------------------------------- -- -- Table structure for table `users_info_landsdel` -- CREATE TABLE `users_info_landsdel` ( `usersinfoLandsdel_id` int(11) NOT NULL, `usersinfoLandsdel_name` text NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_landsdel` -- INSERT INTO `users_info_landsdel` (`usersinfoLandsdel_id`, `usersinfoLandsdel_name`) VALUES (1, 'Sjælland'), (2, 'Jylland'), (3, 'Odense'), (4, 'Bornholm'); -- -------------------------------------------------------- -- -- Table structure for table `users_info_sko_storrelse` -- CREATE TABLE `users_info_sko_storrelse` ( `usersinfoSkoStorrelse_id` int(11) NOT NULL, `usersinfoSkoStorrelse_storrelse` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_sko_storrelse` -- INSERT INTO `users_info_sko_storrelse` (`usersinfoSkoStorrelse_id`, `usersinfoSkoStorrelse_storrelse`) VALUES (1, 17), (2, 18), (3, 19), (4, 20), (5, 21), (6, 22), (7, 23), (8, 24), (9, 25), (10, 26), (11, 27), (12, 28), (13, 29), (14, 30), (15, 31), (16, 32), (17, 33), (18, 34), (19, 35), (20, 36), (21, 37), (22, 38), (23, 39), (24, 40), (25, 41), (26, 42), (27, 43), (28, 44), (29, 45), (30, 46), (31, 47), (32, 48), (33, 49), (34, 50); -- -------------------------------------------------------- -- -- Table structure for table `users_info_sprog` -- CREATE TABLE `users_info_sprog` ( `usersinfoSprog_id` int(11) NOT NULL, `usersinfoSprog_name` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_info_sprog` -- INSERT INTO `users_info_sprog` (`usersinfoSprog_id`, `usersinfoSprog_name`) VALUES (1, 'Dansk'), (2, 'Engelsk (US)'), (3, 'Engelsk (UK)'), (4, 'Norsk'), (5, 'Svensk'), (6, 'Tysk'), (7, 'Fransk'); -- -------------------------------------------------------- -- -- Table structure for table `users_info_tatoveringer` -- CREATE TABLE `users_info_tatoveringer` ( `usersinfoTatoveringer_id` int(11) NOT NULL, `usersinfoTatoveringer_name` varchar(255) NOT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -------------------------------------------------------- -- -- Table structure for table `users_subscription` -- CREATE TABLE `users_subscription` ( `usersSubscription_id` int(11) NOT NULL, `usersSubscription_name` varchar(255) NOT NULL, `usersSubscription_months` int(11) NOT NULL DEFAULT '0', `usersSubscription_price` int(11) NOT NULL DEFAULT '0' ) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- -- Dumping data for table `users_subscription` -- INSERT INTO `users_subscription` (`usersSubscription_id`, `usersSubscription_name`, `usersSubscription_months`, `usersSubscription_price`) VALUES (1, '1 MDR 35,-', 1, 35), (2, '6 MDR 198,-', 6, 198), (3, '12 MDR 349,-', 12, 349); -- -- Indexes for dumped tables -- -- -- Indexes for table `carousel1` -- ALTER TABLE `carousel1` ADD PRIMARY KEY (`carousel1_id`); -- -- Indexes for table `page_work1_videos` -- ALTER TABLE `page_work1_videos` ADD PRIMARY KEY (`pw1videos_id`); -- -- Indexes for table `users` -- ALTER TABLE `users` ADD PRIMARY KEY (`users_id`); -- -- Indexes for table `users_files` -- ALTER TABLE `users_files` ADD PRIMARY KEY (`usersFiles_id`); -- -- Indexes for table `users_gender` -- ALTER TABLE `users_gender` ADD PRIMARY KEY (`usersGender_id`); -- -- Indexes for table `users_info` -- ALTER TABLE `users_info` ADD PRIMARY KEY (`usersinfo_id`); -- -- Indexes for table `users_info_bluse_storrelse` -- ALTER TABLE `users_info_bluse_storrelse` ADD PRIMARY KEY (`usersinfoBluseStorrelse_id`); -- -- Indexes for table `users_info_bukse_bredde` -- ALTER TABLE `users_info_bukse_bredde` ADD PRIMARY KEY (`usersinfoBukseBredde_id`); -- -- Indexes for table `users_info_bukse_laengde` -- ALTER TABLE `users_info_bukse_laengde` ADD PRIMARY KEY (`usersinfoBukseLaengde_id`); -- -- Indexes for table `users_info_etnicitet` -- ALTER TABLE `users_info_etnicitet` ADD PRIMARY KEY (`usersinfoEtnicitet_id`); -- -- Indexes for table `users_info_eye_color` -- ALTER TABLE `users_info_eye_color` ADD PRIMARY KEY (`usersinfoEyeColor_id`); -- -- Indexes for table `users_info_hair_color` -- ALTER TABLE `users_info_hair_color` ADD PRIMARY KEY (`usersinfoHairColor_id`); -- -- Indexes for table `users_info_kategorier` -- ALTER TABLE `users_info_kategorier` ADD PRIMARY KEY (`usersinfoKategorier_id`); -- -- Indexes for table `users_info_landsdel` -- ALTER TABLE `users_info_landsdel` ADD PRIMARY KEY (`usersinfoLandsdel_id`); -- -- Indexes for table `users_info_sko_storrelse` -- ALTER TABLE `users_info_sko_storrelse` ADD PRIMARY KEY (`usersinfoSkoStorrelse_id`); -- -- Indexes for table `users_info_sprog` -- ALTER TABLE `users_info_sprog` ADD PRIMARY KEY (`usersinfoSprog_id`); -- -- Indexes for table `users_info_tatoveringer` -- ALTER TABLE `users_info_tatoveringer` ADD PRIMARY KEY (`usersinfoTatoveringer_id`); -- -- Indexes for table `users_subscription` -- ALTER TABLE `users_subscription` ADD PRIMARY KEY (`usersSubscription_id`); -- -- AUTO_INCREMENT for dumped tables -- -- -- AUTO_INCREMENT for table `carousel1` -- ALTER TABLE `carousel1` MODIFY `carousel1_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; -- -- AUTO_INCREMENT for table `page_work1_videos` -- ALTER TABLE `page_work1_videos` MODIFY `pw1videos_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=51; -- -- AUTO_INCREMENT for table `users` -- ALTER TABLE `users` MODIFY `users_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11; -- -- AUTO_INCREMENT for table `users_files` -- ALTER TABLE `users_files` MODIFY `usersFiles_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3; -- -- AUTO_INCREMENT for table `users_gender` -- ALTER TABLE `users_gender` MODIFY `usersGender_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4; -- -- AUTO_INCREMENT for table `users_info` -- ALTER TABLE `users_info` MODIFY `usersinfo_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; -- -- AUTO_INCREMENT for table `users_info_bluse_storrelse` -- ALTER TABLE `users_info_bluse_storrelse` MODIFY `usersinfoBluseStorrelse_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; -- -- AUTO_INCREMENT for table `users_info_bukse_bredde` -- ALTER TABLE `users_info_bukse_bredde` MODIFY `usersinfoBukseBredde_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23; -- -- AUTO_INCREMENT for table `users_info_bukse_laengde` -- ALTER TABLE `users_info_bukse_laengde` MODIFY `usersinfoBukseLaengde_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=26; -- -- AUTO_INCREMENT for table `users_info_etnicitet` -- ALTER TABLE `users_info_etnicitet` MODIFY `usersinfoEtnicitet_id` int(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT for table `users_info_eye_color` -- ALTER TABLE `users_info_eye_color` MODIFY `usersinfoEyeColor_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; -- -- AUTO_INCREMENT for table `users_info_hair_color` -- ALTER TABLE `users_info_hair_color` MODIFY `usersinfoHairColor_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=15; -- -- AUTO_INCREMENT for table `users_info_kategorier` -- ALTER TABLE `users_info_kategorier` MODIFY `usersinfoKategorier_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10; -- -- AUTO_INCREMENT for table `users_info_landsdel` -- ALTER TABLE `users_info_landsdel` MODIFY `usersinfoLandsdel_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=5; -- -- AUTO_INCREMENT for table `users_info_sko_storrelse` -- ALTER TABLE `users_info_sko_storrelse` MODIFY `usersinfoSkoStorrelse_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=35; -- -- AUTO_INCREMENT for table `users_info_sprog` -- ALTER TABLE `users_info_sprog` MODIFY `usersinfoSprog_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8; -- -- AUTO_INCREMENT for table `users_info_tatoveringer` -- ALTER TABLE `users_info_tatoveringer` MODIFY `usersinfoTatoveringer_id` int(11) NOT NULL AUTO_INCREMENT; -- -- AUTO_INCREMENT for table `users_subscription` -- ALTER TABLE `users_subscription` MODIFY `usersSubscription_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;COMMIT; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; please note with this SQL, i have removed some names pre-made But that is my SQL never the less. Hoping you can help. And it is to my believes that it is with the queries my problems are, mainly, unsure about the if/else's statements, they look good to my eye, it is mostly the SQL i am not the best at making when it comes to searchers. Hope you can help, as always, thanks, and sorry if i left any info out. Please ask if you need more information! Thanks again!
  2. Suggestion 1: I had an idea for w3school for a very long time and this idea will help people learn better and even make school suggest it more. Add in a tutorial where people will have to figure how how to fix codes like it's almost like the try-it-out but you have to go through courses and learn programming through that, almost like khan academy almost except with programming except khan academy only teaches html and not PHP. And also it wouldn't hurt to show videos of how to understand PHP more. And also how to create websites like facebook and youtube and have interactive videos as well like khan academy and those interactive videos on there was actually cool, I was amazed of how they did that when I first learned html. W3school.com actually taught me more about html and CSS more than khan academy. I just hope this forum in connecting to the website I am talking about. But w3school did have a link to this forum so I am guessing so. Suggestion 2: Also I notice some websites has custom context menus and wondering if somehow they can teach how to create that as well because I tried searching how and had to program it and I looked at other websites and it was accurate and w3school shows more accurate html and CSS. Can it be added
  3. I'm learning php & sql. I can do the programming and logic, but how to put it all together is where I get confused. I have copied, from the w3 tutorial, the php form validation complete, and it worked fine. I have also used the php/sql database tutorial to copy the 'insert into' code and it works fine with a Db I set up on the local host. Now I would like to save the info in the form to a database table, but I'm not sure where to insert the code to connect to the database. I tried just adding the code at the bottom of the 'Form Complete' code but it didn't seem to take - no error codes but didn't get saved to the table. If I should keep it as a separate file, how and where do I call that file with the parameters I want to insert into the database? Is there anything on the w3 site that deals with this 'real life' situation. The tutorials are very good, but (everybody's got a big butt) the examples all use literals and they don't relate to a problem like I've explained here. I mean, why else would you have somebody fill in a form except to save the info in a table for future reference?? Any help going forward would be greatly appreciated. I didn't post the code here to save space, so if you're not sure what code I'm talking about, it's at w3schools and under PHP tutorial goto PHP forms 'Form Complete' and just below that in the SQL section is the code for Inserting data into a mySQL database. If I need to, I will post it. Thanx, Gil
  4. Hallo everyone. Thanks for a great website. I have been trying for a few days to get a safe, working php form that saves input to mysql. I have looked at several examples from different websites. The problem is that the form values are being stored to the database before the form validation process is complete. I have tried wrapping the process.php code in a function and only calling the function after the validation code is done and implemented some checks in a desperate attempt to resolve the matter using some global variables and a function that checks if the validation has done their work. But even with all this.. the user input is written to the database before validation is complete. for example.. if the user inputs his name with a preceding space, and submits the form, the preceding space ends up in the database. also a user can press the submit button multiple times and with every press, the information is stored to the database.. I imagine someone could write code to click that submit button millions of times until my server storage space runs out.. Any help would be much appreciated. Thanks. Einston I only have two files.. currently: 1: index.php and 2: testreqfields.php <html> <head> <title>Registration Form</title> </head> <body> <?php $inputisgood = false; $nameisgood = false; $surnameisgood = false; $emailisgood = false; $passwordisgood = false; include "testreqfields.php"; ?> <link href = "registration.css" type = "text/css" rel = "stylesheet" /> <h2>Sign Up</h2> <form name = "form1" action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method = "post" enctype = "multipart/form-data" > <div class = "container"> <div class = "form_group"> <label>First Name:</label> <input type = "text" name = "name" value = "<?php echo $name;?>" required/> <span class="error">* <?php echo $nameErr;?></span> </div> <div class = "form_group"> <label>Surname:</label> <input type = "text" name = "surname" value = "<?php echo $surname;?>" required/> <span class="error">* <?php echo $surnameErr;?></span> </div> <div class = "form_group"> <label>Email:</label> <input type = "text" name = "email" value = "<?php echo $email;?>" required/> <span class="error">* <?php echo $emailErr;?></span> </div> <div class = "form_group"> <label>Password:</label> <input type = "password" name = "pwd" value = "<?php echo $pwd;?>" required/> <span class="error">* <?php echo $pwdErr;?></span> </div> <div class = "form_group"> <label>Gender:</label> <input type="radio" name="gender" value="female">Female <input type="radio" name="gender" value="female">Male </div> <input type = "submit" name = "enq_submit" value = "Submit" /> </div> </form> </body> </html> <?php function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } function sql_process() { //reset the global variable to be sure all code run again if there are errors in input. global $inputisgood; $inputisgood = false; //establish connection $servername = "localhost"; $config = parse_ini_file('../db_credentials/config.ini'); //create the connection $conn = mysqli_connect ($servername, $config['username'], $config['password'], $config['dbname']); //check connection if (!$conn){ die('Could not connect: ' . mysqli_connect_error()); } $sql = mysqli_select_db ($conn, $config['dbname']) or die("unable to connect to database"); //process if (isset($_POST['enq_submit'])){ $reg_name = $_POST['name']; $reg_surname = $_POST['surname']; $reg_email = $_POST['email']; $reg_pwd = $_POST['pwd']; $sql = "INSERT INTO registration (reg_name, reg_surname, reg_email, reg_pwd) VALUES ('$reg_name', '$reg_surname', '$reg_email', '$reg_pwd')"; echo("You have been signed up."); if (!mysqli_query($conn,$sql)){ die('Error: ' . mysqli_error($conn)); } } else { echo("Kindly use the form to sign up:"); }; } function ready_to_process () { global $nameisgood, $surnameisgood, $emailisgood, $passwordisgood, $inputisgood; if ($nameisgood) { echo ("##Name is good"); } if ($surnameisgood) { echo ("##Surnameame is good"); } if ($emailisgood) { echo ("##Email is good"); } if ($passwordisgood) { echo ("##Password is good"); } if ($nameisgood and $surnameisgood and $emailisgood and $passwordisgood) { echo ("##All input is good!"); $inputisgood = true; $nameisgood = $surnameisgood = $emailisgood = $passwordisgood = false; } } // define variables and set to empty values $nameErr = $surnameErr = $emailErr = $pwdErr = ""; $name = $surname = $email = $pwd = ""; if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST["name"])) { $nameErr = "Name is required"; } else { $name = test_input($_POST["name"]); if (!preg_match("/^[a-zA-Z ]*$/",$name)) { $nameErr = "Only letters and spaces allowed"; } else { $nameisgood = true; } } if (empty($_POST["surname"])) { $surnameErr = "Surname is required"; } else { $surname = test_input($_POST["surname"]); if (!preg_match("/^[a-zA-Z ]*$/",$surname)) { $surnameErr = "Only letters and spaces allowed"; } else { $surnameisgood = true; } } if (empty($_POST["email"])) { $emailErr = "Email is required"; } else { $email = test_input($_POST["email"]); if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = "Invalid email format"; } else { $emailisgood = true; } } if (empty($_POST["pwd"])) { $pwdErr = "Password is required"; } else { $passwordisgood = true; } ready_to_process(); if ($inputisgood) { sql_process(); } } ?>
  5. Hi I have a question, but no real example yet. I wonder if someone can tell how to create a serial number that counts from 10000 to 100000 en divide it as a unique id over several databases and table.columns? I dont want to have an example with uniqid() , but counting up with one. I have no clue how to do this can someone please give any suggestion?
  6. I made a website using HTML and some javascript. I tried to make a contact form with PHP, but something goes wrong when submitting and I don't understand why. I followed a tutorial and can't see any mistakes (first time using PHP, so there might be a lot I can't see). Here is the HTML-code and PHP-file. I also uploaded the original, in case you prefer to open it that way.. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"><head> <link rel="stylesheet" type="text/css" href="sample.css"> <style type="text/css" media="all"> @import "sample.css"; </style> <title>Yan Zhou | CONTACT</title> </head> <body> <div id="container"> <div id="header_home"></div> <div id="navigatie"> <ul> <li id="linkabout"><a href="Yan Zhou - About.html"><img src="images/link_about.png" alt="ABOUT"></a></li> <li id="linkportfolio"><a href="Yan Zhou - Portfolio.html"><img src="images/link_portfolio.png" alt="PORTFOLIO"></a></li> <li id="linkcontact"><a href="Yan Zhou - Contact.html"><img src="images/link_contact.png" alt="CONTACT"></a></li> </ul> </div> <div id="supportingText"> <form action="contact_form.php"> <label for="name">Name</label> <input type="text" id="name" name="name" placeholder="I will need your name for contacting you. ^^"> <label for="company">Company</label> <input type="text" id="company" name="company" placeholder="If you contact me on behalf of a company, type it here. Otherwise type 'None'."> <label for="email">Email</label> <input type="text" id="email" name="email" placeholder="How else could I answer you?"> <label for="message">Message</label> <textarea id="message" name="message" placeholder="Who are you, where are you from, what do you wish to say? :-)" style="height:200px"> </textarea> <input type="submit" value="Submit"> </form> </div> </body></html> <?php if(isset($_POST['email'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "rakkermans@hotmail.com"; $email_subject = "Yan Zhou Website - Contactformulier"; function died($error) { // your error code can go here echo "I'm sorry, but there were error(s) found with the form you submitted. "; echo $error."<br /><br />"; echo "Please fix these errors and retry submitting.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['name']) || !isset($_POST['company']) || !isset($_POST['email']) || !isset($_POST['message'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $name = $_POST['name']; // required $company = $_POST['company']; // required $email = $_POST['email']; // required $message = $_POST['message']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(!preg_match($string_exp,$company)) { $error_message .= 'The Company you entered does not appear to be valid.<br />'; } if(strlen($message) < 2) { $error_message .= 'The message you entered does not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Name: ".clean_string($name)."\n"; $email_message .= "Company: ".clean_string($company)."\n"; $email_message .= "Email: ".clean_string($email)."\n"; $email_message .= "Message: ".clean_string($message)."\n"; ?> <?php ?> The following error message appears Thanks for looking into it! Rob Yan Zhou - Contact.html contact_form.php
  7. Hi. I have a doubt with the proper way of sanitize the forms with php. In the php form validation lesson https://www.w3schools.com/php/php_form_validation.asp is used a function for this purpose: function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } But in the filters lesson, https://www.w3schools.com/php/php_filter.asp I understand that filters can do the same task. Is this correct? Are two approaches valid? Which one should be used nowadays? Thanks in advance!
  8. hey w3s... so i have this code: <div class="container-fluid"> <div class="row"> <div class="col-md-12"> <h2 class="font-weight-bold text-center">WORK</h2> <div class="border"></div> <br /> </div> </div> </div> <div class="container main_wrapper"> <section> <div class="container"> <div class="row" id="work-grid"> <?php $query_1 = "SELECT * FROM admvideo ORDER BY video_id DESC"; $result_1 = mysqli_query($dblink, $query_1) or die(mysqli_error($dblink)); if( mysqli_num_rows($result_1) > 0 ) { while( $row_1 = mysqli_fetch_array($result_1) ) { $video_id = $row_1['video_id']; $video_title = $row_1['video_title']; $video_link = $row_1['video_link']; $video_director = $row_1['video_director']; $video_text = $row_1['video_text']; ?> <div class="col-sm-4 col-xs-12 work_panels"> <div class="panel panel-default Panel_ModalVideoID-<?php echo $video_id; ?>"> <div class="panel-thumbnail"> <a href="#" title="Video" class="thumb"> <img src="https://img.youtube.com/vi/<?php echo $video_link; ?>/0.jpg" class="img-responsive img-rounded" data-toggle="modal" data-target=".modalVideo"> </a> </div> <div class="panel-body"> <p class="work-name"><?php echo $video_director; ?></p> <p class="work-video-text"><?php echo $video_text; ?></p> </div> </div> </div> <?php } } else { // hvis der ikke er EN række i udtrækket, vises en fejlbesked echo 'Ingen videoer at vise i nu.'; } ?> </div> </div> </section> <div class="modal fade customModal_1 modalVideo" tabindex="-1" role="dialog" aria-labelledby="modalVideo_LabelledBy" aria-hidden="true"> <div class="modal-dialog modal-lg"> <div class="modal-content"> <div class="modal-header"> <h3 class="modal-title customModal_2">Video Title 1</h3> <button class="close" type="button" data-dismiss="modal">×</button> </div> <div class="modal-body"></div> <div class="modal-footer"> <h4 class="customModal_3">Video Title 2</h4> <p class="customModal_4"> Video in here. </p> <!--<iframe width="100%" height="350" src="" frameborder="0" allowfullscreen></iframe>--> </div> </div> </div> </div><!-- //.modal-Youtube_1 --> </div> <script> $('[class^=Panel_ModalVideoID-]').click(function(event) { event.preventDefault(); // Step 1 - The Variables //----------------------------------------------- var e = $(this); // e = event of the function happening via class/id "class^=Panel_ModalVideoID-*" (working?) var modal = $('.customModal_1'); var modalTitle = $('.customModal_2'); var videoTitle = $('.customModal_3'); var videoEmbed = $('.customModal_4'); var modal_body = $('.modal-body'); var INSERTDATA_modalTitle; $('a.thumb').click(function() { INSERTDATA_modalTitle = $(this).Attr( 'title' ); }); //var INSERTDATA_modalTitle = e.$('a.thumb').Attr("title"); // working? // Step 2 - Clear different areas //----------------------------------------------- modal_body.empty(); // empty area // Step 3 - insert data into different areas //----------------------------------------------- $(modalTitle).html(INSERTDATA_modalTitle); // Step 4 - show the modal //----------------------------------------------- $(".customModal_1").modal({ show: true; }); }); </script> Currently i'm using bootstrap 4 and trying to make a modal appear. So far it is working BUT i am trying to edit the following inside of the modal: Modal title, and the 2 <p> items inside modal-footer for youtube embed and youtube title etc. All of the replacements at different areas should come from the "while loop" at the upper of the page coding with php. Can you help me somehow? Not sure what to do with js/jquery really, a little bit of a newbie... even after years, i still dont get much of it :/ Hoping you guys can help me out a bit. If more information is needed, please ask. Using jQuery 3.2.1, included ALL of the bootstrap 4 bundle etc, so i know that is not the problem here. Maybe it is the way i am using my JS/jQuery code. Thanks a lot. And ohh... the title should be from the "a.thumb -> title attribute", saying video... will edit it later with php so that it will be dynamic. Hope you can help. Thanks!
  9. Hello , I have a problem , I want to wirte HTML code that only refreshes the <div> test , so just the code between de <div>...</div> I was thinking to use some Javascript but I'm not sure this works in PHP , because my in HTML div there's PHP code. My HTML code: <HTML> <HEAD> </HEAD> <BODY> <div id = "other div"> </div> <div id="test"> <?php refresh this code ?> </div> </BODY> </HTML>
  10. BACKGROUND: I recently upgraded my version of PHP from 5.5.38 to 5.6.33. PHP code that functioned perfectly well now fails with imposed notifications complaining about undefined variables. Mind you, my error logs and notifications are turned off. This suggests that I must either learn how to turn off these imposed intrusions or learn to write PHP properly and modify all of my PHP processing files accordingly. In the belief that I will be better served by the latter, I am appealing to W3Schools to set me straight. REQUEST: Please examine the following two pieces of code and correct then so that I do not receive a notice from PHP telling me that the variable is undefined, when indeed no value was intended. This is just a sampling of the problem that I am now confronted with. Sampling One - The CODE My Action: I selected webinar, but not newsletter before the form was submitted. <?php // ini_set('display_errors', 1); // ini_set('display_startup_errors', 1); // error_reporting(E_ALL); require_once '../../_utilities/php/php_mailer/PHPMailerAutoload.php'; // var_dump(class_exists('PHPMailer')); $name = $email = $newsletter = $webinar = $language = $error_msg = '' ; /* function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } */ if ($_SERVER["REQUEST_METHOD"] == "POST") { if (empty($_POST['language'])) { $error_msg = "Please select your first language or add another, if yours is not listed."; } else if ($_POST['language'] == 'other_tongue') { if (empty($_POST['other'])) { $error_msg = "Please enter your first language."; } else { $language = filter_var($_POST["other"], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); } } else { $language = filter_var($_POST["language"], FILTER_SANITIZE_STRING, FILTER_FLAG_STRIP_LOW); } if (!($_POST["newsletter"]) && !($_POST["webinar"])) { $error_msg = "Have you forgotten to select a gift?"; } else { $newsletter = filter_var($_POST["newsletter"], FILTER_SANITIZE_NUMBER_INT, FILTER_VALIDATE_INT); $newsletter = !empty($newsletter) ? "$newsletter" : 0; $webinar = filter_var($_POST["webinar"], FILTER_SANITIZE_NUMBER_INT, FILTER_VALIDATE_INT); $webinar = !empty($webinar) ? "$webinar" : 0; } ... The ERROR MESSAGE: Sampling Two - The CODE My Action: I opened the page directly. There was no referral. <?php /* ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); */ if (filter_var($_GET['refer_type'], FILTER_VALIDATE_INT)) { $refer_type = $_GET['refer_type']; } else { $refer_type = 0; } ... The ERROR MESSAGE: Please advise. Roddy
  11. Hi I would like to know how to fetch all columns from a table. Not the data in the table, but only the names of the columns. I made a script. I tested the query first in the console giving me a good result in the section Field . Can someone please explain how to use this in PHP ? code example: <?php // test set up for fetching column names $servername = "localhost"; $username = "name"; $password = "pass123"; $dbname = "test_database"; // $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } if ($stmt = $conn->prepare("SHOW COLUMNS FROM test_table ")) { $stmt->execute(); $row = $stmt->fetch(); var_dump($stmt); var_dump($row); foreach ($row as $value) { var_dump($value); } } $stmt->close(); $conn->close(); ?> EDIT: I solved the script in the following way. <?php $stmt = $conn->prepare("SHOW COLUMNS FROM test_table"); $stmt->execute(); $res = $stmt->get_result(); var_dump($res); foreach ($res as $val){ $col = $val['Field']; var_dump($col); } ?> You have to remove the if part and the {} and replace it with the code above.
  12. I can not fix this script, because the output is not in sync. I have 3 arrays. 1) present column names. 2) prefix (fixed name). 3) suffix (uniqid value). Can someone explain how exactly I should create a foreach loop in a foreach loop with 3 arrays and fetching the field value from the get_result command as the the value it is related to. This would result in: <---->Present Column Name <-----> New Column Name <---->value1 <--------------------------------> value1_abcd <---->value2 <------------------------------> value2_abcd etc. <?php $prefix_arr = array( 'col_a' , 'col_b' ,'col_c' , 'col_d', 'col_e' , 'col_f' , 'col_g' , ) ; $col2 = uniqid(); $suffix = substr($col2, 5, 11); $servername = "localhost"; $username = "userx"; $password = "pass12345"; $dbname = "test_database"; $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } $stmt = $conn->prepare("SHOW COLUMNS FROM table_xyz"); $stmt->execute(); $res = $stmt->get_result(); $pres_colname = $res; // var_dump($prefix_arr); foreach ($prefix_arr as $los_ele){ $prefix = $los_ele; // var_dump($prefix); // var_dump($suffix); $col_new = $prefix."_".$suffix; //var_dump($col_new); foreach ($pres_colname as $val){ $col = $val['Field']; // var_dump($col); ?> <br><input type="text" value =" <?php echo $col; ?>"><input type="text" value ="<?php echo $col_new;?>"> <?php $stmt = $conn->prepare("ALTER TABLE `table_xyz` CHANGE COLUMN `$col` `$col_new` VARCHAR(30) NOT NULL;"); $stmt->execute(); } } //$stmt->close(); $conn->close(); ?> The complicated thing this time is that I need the exact 'Field' value which is an output of get_result, so I can not fit it in.
  13. I am new to php and am having a real problem getting it to write to SQL tables from form input. I finally managed to get a 3 column test form to insert the data into a test table, so moved on to the next test of inserting a 10 column form that includes 4 check boxes following the script of the one I got to insert. But I cannot get it to insert the data. I also have the problem that my localhost is running php 7.1 while the SQL side of the server is using php 5.6, thus the many single quotes versus double quotes or no quotes. With the first test script, I debugged line by line, and figured out if I get a bunch of warnings in netbeans and my local server but no red flags it most likely will work on the server. But this script has me at a loss. I have stripped out anything superfluous such as the thank you html, the email send portion, and debugged it line by line with the server. The connection is good, it takes a second as if it is inserting, I get zero warnings or errors at this point, but in the end it has not inserted the data into the table. I have checked and rechecked the database name, table name, columns etc and nothing. I appreciate any ideas and help from anyone here. Thanks so much! This is the form portion of the html: <form class="contact-form" role="form" action="volunteers2remote.php" method="post" onsubmit="document.getElementById('updatesButton').disabled=true; document.getElementById('updatesButton').value='Submitting, please wait...';"> <div class="form-group"> <label for="firstname" class="hidden">First Name</label> <input type="text" class="form-control" name="firstname" id="firstname" value="" required="required" placeholder="First Name"> </div> <div class="form-group"> <label for="lastname" class="hidden">Last Name</label> <input type="text" class="form-control" id="lastname" name="lastname" value="" required="required" placeholder="Last Name"> </div> <div class="form-group"> <label for="email" class="hidden">Email</label> <input type="email" class="form-control" id="email" name="email" value="" required="required" placeholder="Email"> </div> <div class="form-group"> <label for="zip" class="hidden">ZIP</label> <input type="text" class="form-control field-half-width" id="zip" name="zip" placeholder="ZIP"> </div> <div class="form-group"> <label for="phone" class="hidden">Phone</label> <input type="text" class="form-control field-half-width" id="phone" name="phone" value="" required="required" placeholder="Phone"> </div> <div class="form-inline"> I will: (uncheck those which you prefer not to do)<br> <input type="checkbox" name="house_party" class="cbox" id="house_party" placeholder="House Party" value="yes" checked><label for="party" type="text" class="special">Host a house party</label> <input type="checkbox" name="canvass" class="cbox" id="canvass" placeholder="Canvass" value="yes" checked><label for="canvass" type="text" class="special">Knock on doors</label><br> <input type="checkbox" name="phonebank" class="cbox" id="phonebank" placeholder="Phonebank" value="yes" checked><label for="phonebank" class="special">Make phone calls</label> <input type="checkbox" name="anything" value="anything" class="cbox" id="any" placeholder="Anything" value="yes" checked><label for="any" class="special">Help with anything you need</label> </div> <div class="form-group"> <label for="comments" class="hidden">Comments</label> <textarea name="comments" id="comments" class="form-control" rows="5" placeholder="Comments"></textarea> </div> <button type="submit" class="btn btn-default" value="Send" id="sendButton">Send</button> </form> <!-- volunteer-form --> This is the stripped down php: <?php ini_set('display_errors', '1'); ?> <?php deleted connection info $link = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); if (!$link) { die('Could not connect to database: ' . mysqli_error()); } // define variables $firstname = $_POST[firstname]; $lastname = $_POST[lastname]; $email= $_POST; $zip= $_POST[zip]; $phone= $_POST[phone]; $house_party= $_POST[house_party]; $canvass= $_POST[canvass]; $phonebank= $_POST[phonebank]; $anything= $_POST[anything]; $comments= $_POST[comments]; if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[firstname])) { $nameErr = 'First name is required'; } else { $firstname = test_input($_POST[firstname]); } // check if name only contains letters and whitespace if (!preg_match('/^[a-zA-Z ]*$/',$firstname)) { $firstnameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST[lastname])) { $nameErr = 'Last name is required'; } else { $lastname = test_input($_POST[lastname]); } // check if name only contains letters and whitespace if (!preg_match('/^[a-zA-Z ]*$/',$lastname)) { $lastnameErr = 'Only letters and white space allowed'; } if ($_SERVER[REQUEST_METHOD] == 'POST') if (empty($_POST)) { $emailErr = 'Email is required'; } else { $email = test_input($_POST); } // check if e-mail address is well-formed if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { $emailErr = 'Invalid email format'; } /* Check all form inputs using test_input function */ if ($_SERVER[REQUEST_METHOD] == 'POST') { $firstname = test_input($_POST[firstname]); $lastname = test_input($_POST[lastname]); $email = test_input($_POST); $phone = test_input($_POST[phone]); $comments = test_input($_POST[comments]); } if (isset($_POST['myCheckbox'])) { $checkBoxValue = "yes"; } else { $checkBoxValue = "no"; } if(!empty($_POST['check'])) { foreach($_POST['check'] as $value) { $check_msg .= "Checked:".$value."\n"; } } if (isset($_POST[house_party])) { $anything = 'yes'; } else { $anything = 'no'; } if (isset($_POST[canvass])) { $canvass = 'yes'; } else { $canvass = 'no'; } if (isset($_POST[phonebank])) { $anything = 'yes'; } else { $anything = 'no'; } if (isset($_POST[anything])) { $anything = 'yes'; } else { $anything = 'no'; } $check = isset($_POST[check]) ? $_POST[check] : ''; function test_input($data) { $data = trim($data); $data = stripslashes($data); $data = htmlspecialchars($data); return $data; } //inserting data into database if (isset($_POST[firstname], $_POST[lastname], $_POST, $_POST[zip], $_POST[phone], $_POST[house_party], $_POST[canvass], $_POST[phonebank], $_POST[anything], $_POST[comments])){ if ($stmt = $link->prepare('INSERT INTO `volunteerstest`(`firstname`, `lastname`, `email`, `zip`, `phone`, `house_party`, `canvass`, `phonebank`, `anything`, `comments`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)')) { $stmt->bind_param('ssssssssss', $_POST[firstname], $_POST[lastname], $_POST, $_POST[zip], $_POST[phone], $_POST[house_party], $_POST[canvass], $_POST[phonebank], $_POST[anything], $_POST[comments]); if (!$stmt->execute()) { error_log('Execute failed '.$stmt->error); } else { echo 'Data successfully inserted! firstname '.$_POST[firstname].' lastname '.$_POST[lastname].' email '.$_POST.' ZIP '.$_POST[zip].' phone '.$_POST[phone].' house_party '.$_POST[house_party].' canvass '.$_POST[canvass].' phonebank '.$_POST[phonebank].' anything '.$_POST[anything].' and comments '.$_POST[comments].''; } $stmt->close(); } else { echo "data insertion failed"; } } ?>
  14. BACKGROUND: I have a confirmation page to which I would like to pass the values of two PHP variables via PHP's header( ) function. QUESTION: Can this be done with normal query statement say something on the following order: header('Location: ../../gate_confirmation.html?name=w3schools&msg=msg_success'); Roddy
  15. BACKGROUND: I am in the process of writing a class that will match and update rows in a MySQL data base. The field that contains the values against which a match is to be discovered must be indefinite. The values that it can contain are either 0 or 1 as defined by an ENUM field type. I know both the desired field and value before the matching routine commences. I want the UPDATE routine to set the value of the field to its opposite: 0 => 1 or 1 => 0. CURRENT STATE OF THE CODE: <?php class VeriFirm { private $mysqli_obj; private $username; private $email; private $hash; private $action = 0; private $field; private $tbl_name = 'captive_roster'; public $link = 'admin@grammarcaptive.com'; public $subject = 'Grammar%20Captive%20-%20Verify%20and%20Confirm%20User%20Action'; public $msg_mismatch = "Sorry, " . $this->username . ", but no matching entry in the Grammar Captive database was found. Please try again! If the problem persists, contact the Grammar Captive <a class='link_style' href='" . create_link() . "' title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a reply in response to your additional effort!"; public $msg_success = "Congratulations, " . $this->username . ", your desired action was successfully processed. No further action is required on your part."; public $msg_failure = "Sorry, " . $this->username . ", but Grammar Captive was unable to process your desired action. It appears that your account status has already been reset. If the problem persists, please contact the Grammar Captive <a class='link_style' href='" . create_link() . "' title='Grammar Captive Online Administrator' target='_top'>webmaster</a> and expect a reply in response to your additional effort!"; function __construct($mysqli_obj, $_GET, $field) { $this->mysqli_obj = $mysqli_obj; $this->field = $field; if((isset($_GET['username']) && !empty($_GET['username'])) AND (isset($_GET['email']) && !empty($_GET['email'])) AND (isset($_GET['hash']) && !empty($_GET['hash']))){ $this->$username = $mysqli_obj->real_escape_string($_GET['name']);; $this->$email = $mysqli_obj->real_escape_string($_GET['email']); $this->$hash = $mysqli_obj->real_escape_string($_GET['hash']); $this->$action = $mysqli_obj->real_escape_string($_GET['action']); } } function create_link() { return $mailto = "mailto:" . $this->link . "?Subject=" . $this->subject; } function match_data() { $sql_select = "SELECT user_name, email_address, hash, " . $this->field . " FROM " . $this->tbl_name . " WHERE user_name=? AND email_address=? AND hash=? AND " . $this->field . "=" . $this->action; $mysqli_stmt = $this->mysqli_obj->stmt_init(); $mysqli_stmt->prepare($sql_select); $mysqli_stmt->bind_param("ssss", $this->username, $this->email, $this->hash, $this->field); $mysqli_stmt->execute(); $mysqli_result = $mysqli_stmt->get_result(); $match = mysqli_num_rows($mysqli_result); if($match > 0){ update_record(); } else { return $msg_mismatch; } } function update_record() { if ($this->action == 0) { $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='1' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=0"; $mysqli_stmt->prepare($sql_update); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); if ($mysqli_stmt->execute()) { return $msg_success; } else { return $msg_failure; } } else if ($this->action == 1) { $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='0' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=1"; $mysqli_stmt->prepare($sql_update); $mysqli_stmt->bind_param("sss", $this->username, $this->email, $this->hash); if ($mysqli_stmt->execute()) { return $msg_success; } else { return $msg_failure; } } function get_link_and_subject() { return $this->link . ' and ' . $this->subject; } function set_link_and_subject($link, $subject) { $this->link = $link; $this->subject = $subject; } function get_tablename() { return $this->tbl_name; } function set_tablename($tbl_name) { $this->tbl_name = $tbl_name; } function get_msg_mismatch() { return $this->msg_mismatch; } function set_msg_mismatch($msg_mismatch) { $this->msg_mismatch = $msg_mismatch; } function get_msg_success() { return $this->msg_success; } function set_msg_success($msg_success) { $this->msg_success = $msg_success; } function get_msg_failure() { return $this->msg_failure; } function set_msg_failure($msg_failure) { $this->msg_failure = $msg_failure; } } ?> I am primarily concerned about the following: if((isset($_GET['username']) && !empty($_GET['username'])) AND (isset($_GET['email']) && !empty($_GET['email'])) AND (isset($_GET['hash']) && !empty($_GET['hash']))){...} Is this a proper use of the $_GET superglobal or would a $_POST or $_REQUEST superglobal be more appropriate. I am concerned about making user's private information public. This said, all communication with the Grammar Captive website is now available to TLS/SSL protocol -- namely, the https:// prefix. $sql_select = "SELECT user_name, email_address, hash, " . $this->field . " FROM " . $this->tbl_name . " WHERE user_name=? AND email_address=? AND hash=? AND " . $this->field . "=" . $this->action; Is this statement properly specified? I am concerned about the placement of the quotation marks and the ability of the mysqli_stmt object to read properly the intended SQL statement. $mysqli_stmt = $this->mysqli_obj->stmt_init(); Is this proper use of the -> operator in the construction of a PHP Class. $sql_update = "UPDATE " . $this->tbl_name . " SET " . $this->field . "='1' WHERE user_name=? AND email_address=? AND hash=? AND ". $this->field . "=0"; Is this statement properly described? Once again, my focus is on the use of quotations marks to define the statement. update_record() Is this the most efficient way to achieve the desire goal -- namely, to toggle the value of action between 0 and 1 depending on an initially assumed value of $this->field. Roddy
  16. BACKGROUND: In the past I have retrieved an HTTPRequest via the $_GET superglobal, used the data from the superglobal to access a MySQL database, and from the thus retrieved data, generated an array of parameter values that I then assigned to a local array. This local array was then assigned to a $_SESSION variable where it was used for other purposes. This time, I would like to make the routing of data less circuitous. QUESTION: Does the following expression make sense? $_SESSION = $_GET; Roddy
  17. BACKGROUND: I have learned to keep a log that increases incrementally with the generation of each new newsletter and podcast. 1) Read the Current Log Value $file = './episode_index.txt'; if (file_exists($file)) { $json_str = file_get_contents($file); $episode_no = json_decode($json_str, true); $number = $episode_no['episode_no']; $new_episode = $number + 1; } else { echo 'The desired file either does not exist, or does not exist in the indicated location.'; } 2) Take Some Action and Update the Log Value Incrementally if (!is_blank($_POST['letter_no'])) { $episode_no['episode_no'] = $number + 1; $json_str = json_encode($episode_no); file_put_contents($file, $json_str); } in effect, I perform a simple file_get_contents and file_put_contents on a single document whose only value is that of a single JSON object whose value increases incrementally with the creation of each new newsletter. In order to keep track of my podcasts I need something vastly more complex, for not only must I be able to automatically generate a new counter with each new podcast that I generate, but each counter thus created must keep track of each and every hit of any and all podcasts by each and every known and anonymous podcast user. Further, once this data is recorded it must be easily accessible for the purpose of analysis. In effect, I am loathe to generate a separate document for each new podcast. Although a workable tool for each individual podcast, i cannot imagine it as a very effective way to manage data for all of my podcasts in aggregate or any desired subset thereof. Perhaps I could create a single MySQL table with a set number of fields for all podcasts. Then, 1) With each new podcast insert a new row of data, and 2) with each new user hit of a particular podcast update the field values for the affected row. Might I receive some input in these regards? Roddy
  18. BACKGROUND: I have an HTML template that contains a variety of template variables designated by the following pair of delimiters %varname%. In most cases there is a one-to-one correspondence between the values of a set of PHP variables gathered on a PHP processing page and the template variables found on the HTML template. The routine for populating the template variables with values is captured in the following code snippet of a very simple PHP class designed for generating templates. function replace_tags($tags) { if (sizeof($tags) > 0) { foreach ($tags as $tag => $data) { $replace = '%\%' . $tag . '\%%'; $data = (file_exists($data)) ? join("", file($data)) : $data; $this->page = preg_replace($replace, $data, $this->page); } } else { die("No tags designated for replacement."); } } The PROBLEM: My difficulty arises when I seek to populate one of the sets of template variables whose number of sets is not clearly known until the template is generated. Within the template HTML code for a single set of three variables is set aside. Ostensibly, this same set of variables could be repeated five different times, with each time carrying a different set of values. PROBLEM RESOLUTION: As each set of PHP data is numerically encoded there is no confusion about which data goes with each set. And, since the HTML code for each set of data is identical across sets it appears to be a relatively easy task to populate the template variables of the relevant set repeatedly with different data from different PHP variable sets. I imagine myself breaking the HTML code into three parts: the part that comes before the dynamically generated HTML; the part that generates the dynamic HTML code; and the part that that comes after the dynamically generated HTML. Can anyone suggest an alternative strategy? One, for example, that would simply allow me to insert the dynamically generated HTML on the fly? Roddy
  19. hello all! i was trying to run another query inside a while loop of a prepared statement. $qs = $_POST['queryString']."%"; $ledq = $mysqli->prepare("SELECT name, fullid aid, ob FROM account WHERE cid='$cid' AND name LIKE ? AND ac_id IN ('$q') ORDER BY name LIMIT 20"); if (!$ledq) { echo "Error: " . $mysqli->error; } else { $ledq->bind_param('s', $qs); $ledq->execute(); $ledq->bind_result($name, $aid, $ob); $ledq->store_result(); while ($ledq->fetch()) { $balq = $mysqli->query("SELECT SUM(debit) debit, SUM(credit) credit FROM .................."); ............... ............... ............... } $ledq->free_result(); $mysqli->close(); } when i use free result outside the while loop it gives out of sync error. if i use free result inside the while loop and before the next query, it returns only one row. i also tried more_result before executing the next query. but it only worked while testing locally. when i upload it to my server and try, it gives nothing. please someone guide me what is the best solution! thank you in advance..
  20. hello all! i was trying to get max value from a mysql query derived values but i could not succeed. please guide what i made mistake. below is the code i tried. in this after fetching data from mysql table, i made some calculations and derived data like this ////////////////// 7474.776.89578.3 ////////////////////////// which actually contains 5 values ( 74,74.7,76.8,95,78.3 ) what i want is to select the number 95. what is the proper method? thank u in advance. $cid = 2; $subid = 10; $clas = 'PG'; $highmq = $mysqli->query("SELECT marktheory, markpractical FROM marksheet WHERE studentid IN (SELECT fullid FROM students WHERE class='$clas' AND cid='$cid') AND (marktheory LIKE '%#$subid#%' OR markpractical LIKE '%#$subid#%') AND cid='$cid'"); $highmarkth = array(); for ($i = 0; $i < $highmq->num_rows; $i++) { $rows = $highmq->fetch_assoc(); if ($rows['marktheory'] != "") { $highmarkth = explode("#", $rows['marktheory'])[2]; $highmarkpr = 0; } if ($rows['markpractical'] != "") { $highmarkpr = explode("#", $rows['markpractical'])[2]; $highmarkth = 0; } $highmark = ($highmarkth + $highmarkpr); echo max($highmark); }
  21. I was trying to open this ( https://github.com/filipac/Free-Torrent-Source/blob/master/mytorrents.php ) but got error. Can anyone guide me how to open this resource ? Edit: It says "Error, Permission Denied". Can u please guide me to open this file. I have Xampp as local server and know how to run it. Downlad and run this resource and please say me steps
  22. I am new to web development, so be patient please I am working with a tab navigation system. It happens to be bootstrap, but this question is not specific to bootstrap. There are four tabs; for the sake of simplicity we will call them tabs "A", "B", "C", and "D." I have a single SQL table and one of the columns --we will call it "Letter"-- identifies each row with one of the four letters. When a user clicks on "A" tab, they should see all the rows where "Letter" = "A". The same for tabs "B", "C", and "D." Right now I am running four separate queries, one for each tab. This seems ridiculous. There must be a way to grab all the data from the table with one query, sort the rows based on their "Letter" into four separate multi dimensional arrays, and then loop through the appropriate array to display the data for a particular "Letter" when a user selects that tab. I cannot figure out how to do this. Any suggestions would be most helpful. Thanks.
  23. BACKGROUND: I have a PHP generator that creates a newsletter from an HTML template with data obtained from a MySQL database. My current plan is to include with the generator an automated mailing function using PHPMailer. I intend to use this generator to consummate to kinds of mailing functions -- mass and individual. The individual mailing: when a user opens an account he automatically receives an automatically generated newsletter with information designed for first users. In this newsletter he has the option of subscribing on a more permanent basis or declining further receipt of future newsletters. TWO TRIGGERS: The code that triggers the mailing of the first newsletter will come from the user and must be automated. The code that triggers a mass mailing to all subscribers must come from me and must be manual. This latter trigger can be resolved easily with a simple link and attached query statement. It is the automated trigger coming directly from the user that is problematic. THE DILEMMA: When the user applies for an account, he receives a verification email with a link to a PHP processor that matches the hash that he received in the email with the one created and inserted into a database when he signed up for the account. It is this PHP processor that must provide the information to the newsletter generator and trigger the new account holder's first mailing of the newsletter. The trigger must be automated. QUESTION: Although it is relatively easy to write Javascript that automatically triggers an HTTPRequest object to the newsletter generator, I am having trouble finding a simple PHP routine that will do the same. Have you any suggestions? Roddy
  24. Ok bare with me because I have no idea what this is actually called. If someone knows I will update the title. I am working on a site that will act as an out-of-game marketplace for in-game items. I want to ensure that the player is within the zone of the market in-game so I need an easy way to generate an array of valid coordinates the player could be within to access the market. Ideally i would like to run a function with a parameter specifying the radius of a square and another of the player's current geoID. Basic geometry would help if the geoID's were, in my mind, easier to predict. here is problem: Going North: geoID's increase by 512 points Going East: geoID's increase by 1 Going South: geoID's decrease by 512 Going West geoID's decrease by 1 I realize this is more of a math question then PHP but I have no idea where to start to account for the odd increase. //Generate the exchangeArea array of a 5x5 square around the centeral id specified in param2. $exchangeArea = getExchangeArea(3,117053149); //if player geoID equals one of the values in the exchangeArea array return true else false function getExchangeArea(int radius, int geoID) { . . . } I have attached a graphic showing all the geoIDs for the above example. Ignore the geoAlt that is just they players Y axis. So there is no confusion, North on this diagram is the right side of the image. Making the top West. Any help on where to begin, even if its helping me identify keywords to search on for this kind of formula, algorithm, equation... what ever it's called, would be greatly appreciated.
  25. BACKGROUND: It appears that there are few problems in web development that do not have multiple solutions. My problem is to decide which solution best suits my needs. I have a confirmation email that sends a name, hash, and email address via an HTTP REQUEST using the $_GET superglobal to a PHP file that matches the hash with an entry in a newsletter roster table. If the match succeeds the value of the status variable is changed from 0 to 1. Before the hash is sent to the roster table it is sanitized using the MySQLi real_escape_string( ) function. Elsewhere on my website I use the PHP filter_var( ) function with parameter values that vary with the nature of the data being sent. QUESTION ONE: In the above instance which PHP function would be more secure. And, why? QUESTION TWO: In general which function is preferred? And, why? Roddy
×
×
  • Create New...