Results 1 to 6 of 6

Thread: PHP reloads page

  1. #1
    Join Date
    Jul 2014

    PHP reloads page

    Hello Everyone ,

    I am struggling with PHP. It's working, just not how I want it to work. I must add, I am a complete noob in php, html and so on coding. Here are some of my codes :

    index.php html form :
        <form action="index.php" method="POST">
            <input type="text" name="query" class="abcdef"/><br/>
    	    <input type="submit" value="Search"/>
    index.php php code :
    $host = "data";
    $user = "data";
    $pass = "data";
    $dbase = "data";
    $dtabl = "data";
        $con = mysqli_connect($host, $user, $pass, $dbase) or die("Error connecting to database: ".mysqli_error());
    echo "<div id='ovisible'>";
    echo "<div><a href='#' onclick='ovisible()'><b>close</b></a><br/><h1><u> Search Results</u></h1>";	
    	if (isset($_POST['query']))
    	$query = $_POST['query'];
            $query = htmlspecialchars($query);
            $query = mysqli_real_escape_string($con,$query);
            $raw_results = mysqli_query($con,"SELECT * FROM data WHERE (`cname` LIKE '%".$query."%') ") or die(mysqli_error());
            if(mysqli_num_rows($raw_results) > 0)
                while($results = mysqli_fetch_array($raw_results)){
                    echo "<p><h3>".$results['name']."</h3>".$results['surname']."</p>";
                echo "No results";
    	else{echo "No search defined ! ";}
    echo "</div>";
    echo "</div>";
    #ovisible{display:none;position: absolute;left: 0px;top: 0px;width:100%;z-index: 1000;background-color:#000;filter:alpha(opacity=80);text-align:center;-moz-opacity:0.9;opacity:0.9
    html head function
    function osearch()
    	xyz = document.getElementById("ovisible");
    	xyz.style.display = (xyz.style.display == "block") ? "none" : "block";
    Lange Rede kurzer sinn : I am trying to show the results INSIDE my overlay (ovisible) WITHOUT the page reloading on form (action="index.php"). If I add onclick="ovisible()" to the input type=submit in the form, then it will open and close the overlay because action="index.php" will reload the page. If I set action="index.php" to action="", action="#" then it doesn't work. Removing the entire input button and placing it beneath the form works, but doesn't return the text to the php and thus it doesn't compute the text box string at all :

        <form action="index.php" method="POST">
            <input type="text" name="query" class="abcdef"/><br/>
    	    <input type="submit" value="Search" onclick="ovisible()"/>
    I would like to know, if there is a easy way to get the results to display on my index.php page, without reloading my page ? Someone on another forum, mentioned I should
    You can create your search.php to return only JSON string, and making an AJAX call using javascript fetch the JSON response from the search.php and render the data using JavaScript.

    You can use JQuery or AngularJS. Both will do the needful for you.
    and I was like ... huh ? I have no idea where to start or what that even means. Is that even English ? See, I would like the above to work, as it does actually work in the sense that it just isn't displayed where and how I want it : The functionality works nicely. Here are a few examples of how I would like to see it done : None that some code and commands are mere imaginations :

    1.) the input submit must show the overlay page with results

    2.) Maybe I can remove the php code completely and add it to the "search.php" file and use action="search.php" BUT somehow forge the results INTO a page WITHIN a page almost like inception

    3.) I rewrite the entire php into java or similar with my more than non existent java or similar coding skills :S

  2. #2
    Join Date
    Jul 2013
    Voorheesville NY USA
    If you want that 'button' to only trigger your js function, change it from a submit to a button type. Or if that won't work, you could use a 'return' parameter on the onclick so that your js function can determine whether to perform the submit something like this:
    PHP Code:
    <input type='submit' value='Submit' onclick='return doSomething()'
    Your doSomething function can reset the display of your element and also return either 'true' or 'false' in order to make the submit happen or not.
    PS - If you're posting here you should be using:

    ini_set('display_errors', '1');

    at the top of ALL php code while you develop it!

  3. #3
    Join Date
    Jul 2014
    Just a quick update,

    I was able to use a XMLHttpRequest, send data to the php/server and then retrieve data back from the php and thereby the page did not reload. In my javascript I mentioned my php file , so that it could be send there.

    But thanks for the help

  4. #4
    Join Date
    Jul 2014
    I have a search page, that returns mysql query like so :

    echo "<a onclick='function1();function2();function3()'>",$row['compn'],"</a>";
    echo "<form><input type='text' id='tester' value='",$row['compuid'],"' hidden='hidden'></input></form>";
    Nothing on my page opens a new page or loads a new one. Everything basically resides on the same page. The results are displayed in another overlay :

    <a onclick="function1();function2();function3()"></a>
    <form><input id="tester" type="text" hidden="hidden" value="abcdefg"></input></form>
    <a onclick="function1();function2();function3()"></a>
    <form><input id="tester" type="text" hidden="hidden" value="mnopqrs"></input></form>
    As you can see above, it kind of works BUT not like I want it to be :
    If clicked on the top "link", it will load id="tester" into
    ; and then display abcdefg. If I click on the bottom link, it will again load tester and display abcdefg. HOW do I get the code or the php to load a dynamic attribute or something, so that if I click the below link, it will actually display mnopqrs ?

    Note: When a result link is clicked, it should display more details on an overlay by reading off from the php. For example :

    link 1 = Peter, LAW
    link 2 = Kate, JOURNALISM

    (click on link 1
    Peter, BIO : Peter has been studying LAW for more than 2 years,
    Peter was born on 24/05/1992. Picture of Peter

    (click on link 2
    Kate, BIO : Kate has been studying ...

  5. #5
    Join Date
    Jul 2013
    Voorheesville NY USA
    Sorry - your code is too broken down to make sense of. Top link? Bottom link? Two different chunks of code and I don't know what you are trying to show. I do know that if you have two elements with the same id you're going to have a js problem.

    And - why do you use input tags with 'type=text' and then add a hidden attribute? Why not just 'type=hidden'?
    PS - If you're posting here you should be using:

    ini_set('display_errors', '1');

    at the top of ALL php code while you develop it!

  6. #6
    Join Date
    Jul 2014
    The code works fine on my side, maybe I only gave SOME of the code to only give an idea what I would like to achieve ? I chose hidden because that's... I only have 2 weeks experience, so FTLOG bear with me

    Here is a scaled down, hopefully understandable, simple, algorithm/idea/FICTION code of what I am aiming for :

    First output generated from search results :

    microsoft | citynorth (hidden from view : [id="1"]) *These id's are the actual IDs from the mysql primary key
    microsoft | cityeast (hidden from view : [id="2"])
    apple | citycentre (hidden from view : [id="3"])
    nvidia | citynorth (hidden from view : [id="4"])
    Pete's cool IT shop | citysouth (hidden from view : [id="5"])

    var k = some mystical javascript function to "get id clicked" above
    $m = select * from abc where id == k
    $l = mysqli_query(m, x)
    			echo $row[item1]," | ",$row[item2]," | "$row[item3]... 
    Example : Let's kindly assume that user clicks "microsoft | citynorth"
    the only output would then be :

    microsoft | citynorth | MS north has sold over 100000 copies of MSKPLQR | 25 | 100000 | PICTURE OF VENUE | reseller

    #NOTE: here the view explained :
    1.) Items in bold, are comments
    2.) Items in italic, are on screen display, that the user sees
    3.) code = code/algorithm/php/javascript w/e

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center



X vBulletin 4.2.2 Debug Information

  • Page Generation 0.12167 seconds
  • Memory Usage 2,910KB
  • Queries Executed 15 (?)
More Information
Template Usage (35):
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (11)bbcode_code
  • (1)bbcode_php
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates