Jump to content


  • Posts

  • Joined

  • Last visited

Posts posted by michaelfurey

  1. I created a login system with bootstrap but for some reason I cannot delete the "placeholder" (in which it is written "admin") in both the inputs of the form ("uname" and "psw").

    Even if I change the placeholder it's remain "admin". Have you any idea?

    This is the code:

    <!DOCTYPE html>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
    <link rel="stylesheet" type="text/css" href="css/styles.css">
        <div class="container">
            <div class="jumbotron text-center" id="jumbo_log">
                <h1>Login Page</h1>
                <p>You must login to enter</p>
                <form id="theform" method="get">
                    <div class="container2">
                        <label for="uname"><b>Username</b></label>
                        <input type="text" id= "uname" name="uname" required><br>
                        <label for="psw"><b>Password</b></label>
                        <input type="password" id="psw" name="psw" required><br><br>
                        <input type="submit" id="submit" class="btn btn-info" value="Login"><br><br>
                     <a class="btn btn-primary" href="registration.php" role="button">Click here if you are not registered</a>


  2. I have created a registration page to access my website. After the user registrate himself should appear an alert saying that the registration was OK and a redirect to main.php page... however for some reason if I create an insert statement the alert and the redirect don't appear... If I remove the insert the alert and the redirect works... why?

    This is part of the code of my 3 files:

    registration.php (ajax call)

    $('#submit').click(function() {
        var username2 = $('#uname2').val();
        var password2 = $('#psw2').val();
            url: 'ajax/response.php',
            type: 'GET',
            data: {username2 : username2, password2: password2},
                success: function(data) {
                    if(data === 'correct') {
                        alert("Username and Password have been created!"); //don' work with the insert
                        location.replace("main.php"); //don' work with the insert
                        } else {
                             alert("Username or password are not correct... please register yourself!");

    response.php (answer to ajax call)

    if(isset($_GET['username2']) && isset($_GET['password2'])) {
        $username2 = $_GET['username2'];
        $password2 = $_GET['password2'];
        if (checkUser($pdo, $username2) === true) {
            echo 'duplicate';
        } else {
            insertUserPwd($pdo, $username2, $password2); //including this line the redirect and the alert doesn't work... the insert is OK
            echo 'correct';

    data_access.php (the function works but doesn't permit alert and redirect to appear)

    function insertUserPwd(PDO $pdo, $usr, $pwd)
        $data = [
        'id' => '',
        'user' => $usr,
        'password' => $pwd
        $sql = "INSERT INTO users (id, user, password) VALUES (:id, :user, :password)";
        $stmt= $pdo->prepare($sql);

    Can someone help me to fix the code? 

  3. This is my PHP code:


                    echo "<table>";form($current_php);
                    $cit=do_order("select * from country_itemize_types");
                    echo "<tr><td>Description: </td><td><select name='descr_ger' id='descr_ger'>";
                    $descr_sql=do_order("select distinct description from country_itemize_types");
                    while ($descr_arr=mysql_fetch_array($descr_sql)){
                            echo "<option>" . $descr_arr['description'] . "</option>";
                    echo "</select></td></tr></table>";

    And this is my mysql table named country_itemize_types (the table has thousand rows but I pasted here only few lines...):


    | uid | type | description  | country |   field    | priority | datatype |      option      |
    |   1 |   12 | travelcost   | ger     | vehicle    |        1 | char     | car;bus;airplane |
    |   2 |   12 | travelcost   | ger     | distance   |        2 | decimal  |                  |
    |   3 |   12 | travelcost   | ger     | times      |        3 | integer  |                  |
    |   4 |   12 | travelcost   | ger     | cost       |        4 | decimal  |                  |
    |   5 |   12 | randomcost   | ger     | earthquake |        1 | char     | weak;strong      |
    |   6 |   12 | randomcost   | ger     | seaquake   |        2 | char     | weak;strong      |
    |   7 |   12 | randomcost   | ger     | cost       |        3 | decimal  |                  |
    |   8 |   12 | marriagecost | ger     | times      |        1 | integer  |                  |

    I would like to create a select tag containing all the descriptions of the table (see the php code above) and when the user selects an option on this select tag should appear some input tag.

    For example if the user selects from the dropdown menu "travelcost" should appear 4 new input tags (vehicle, distance, times, cost). If the user selects "marriagecost" should appear only one new input tag (times).


    How can I do that? I suppose that I have to run a sql query with javascript or something similar but I am a newbie in javascript...

  4. view-source:http://domain.tld/path/to/script.php
    Or make the script force a download instead of showing it in the browser.


    Or run PHP on your own computer and have it generate the file directly in the place you want.


    Or one of a bunch of other things.


    Is it possible to download the output of the previous code from the server to the client? In that way I should obtain the xml content in the client without copying and paste through the browser.


    In other words I would like to run a file located in the server that generates the xml file and to download it authomatically to the client.

  5. If you want to display the XML rather than have chrome try to interpret it then run it through htmlspecialchars prior to displaying it.

    echo '<p>The HTML code is:</p>';
    echo '<code>' . htmlscpecialchars($xml) . '</code>';

    Ok perfect that I wanted to know! I apreciated also the test that you created for me to check if I have some problem solving skills ( " htmlsCpecialchars($xml) " ).

  6. I have to generate the following text with a php script in the server and render it in chrome, then copy it manually with the mouse and finally paste it manually in a xml file located in my desktop pc.


    The text is the following:

    <?xml version="1.0" encoding="UTF-8"?>
    <shiporder orderid="889923"
      <orderperson>John Smith</orderperson>
        <title>Hide your heart</title>
        <title>Hide your heart</title>

    The problem is that I have to render in the browser also the tags and the text included inside the tags... is it possible to render that text in chrome in that way?

  7. Sure can.. You'll need to put it into a Javascript function, and set that function to run when the input is changed:

    document.querySelector("input[name='date']").addEventListener('change', function(e) {
      var dateInput = e.target;
      var date = dateInput.value;

    There you will have the date value that they selected.


    From there, you create a new instance of the Javascript Date class, passing the date in as a paramater, and then call getDay() on it.. getDay() will return an integer, corresponding to the day of the week, with Sunday = 0 (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date)


    Have a crack at finishing that function off, and if you need more help, let us know.

    Ok perfect solved!


    function switchDay (dateInput) {
      var date = dateInput.value;
      var dayF = new Date(date);
      var dayNumber = dayF.getDay();
        switch (dayNumber) {
        case 0:
            day = "Sunday";
        case 1:
            day = "Monday";
        case 2:
            day = "Tuesday";
        case 3:
            day = "Wednesday";
        case 4:
            day = "Thursday";
        case 5:
            day = "Friday";
        case 6:
            day = "Saturday";
        return day;
    document.querySelector("input[name='date']").addEventListener('change', function(e) {
      var dateInput = e.target; 
      day = switchDay(dateInput);
  8. I have a php file and in javascript I am a newbie.


    This is my php code:


    echo 'Date:<input type="date" name="date">';
    echo 'Day:<input type="text" name="day">';
    I would like that when the user select a date from the input "date" in the input "day" appears the right day.
    For example if the user writes "18/07/2017" in the input "date", in the second input tag should appear "Tuesday".
    Is it possible to do that?
  9. Starting from a PHP script I would like to select some options of a multiple select... but I don't know how.


    This is my html code:

    <select id="pairlang[]" name="pairlang[]" multiple size=3>
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="mercedes">Mercedes</option>
      <option value="audi">Audi</option>
    <input type="submit" value="save allllll" name="update" class="great" onclick="pairSave()">

    This is my js code:

    function pairSave() {
        var newJs = <?php echo json_encode($pair); ?>;

    The output of the alert is an array:


    Someone knows how to select the options volvo and saab with the function pairSave?

  10. This is my code:

    <script type="text/javascript">
    $(document).ready(function() {
    <select class="js-example-basic-single">
      <option value="volvo">Volvo</option>
      <option value="saab">Saab</option>
      <option value="opel">Opel</option>
      <option value="audi">Audi</option>
      <option value="fiat">Fiat</option>
      <option value="mercedes">Mercedes</option>
      <option value="bmw">BMW</option>
      <option value="tata">Tata</option>

    Unfortunately I am using Select2 that is a plugin of jquery... I have the impression that the attribute size doesn't work with it.


    Then what's the whole point of reading the response from the server? You already have the selected option.



    Because I am using a particular web framework written in PHP and to apply a change I have to reload the entire page.... so I was thinking to use Ajax in order to reload only an element to apply a change, as a <p> in this case.

  12. The obvious question: What exactly is data?


    Note that you cannot put arbitrary content into p elements.



    data is a way that I tried to put inside the <p> element the selected option values  with ajax... I would like to echo 'selectedOptionValue' inside the <p> element. So if I select the option One and Two I would like to read inside the <p> One and Two.

  13. I would like to change the <p> text in the following way but it doesn't work:


    PHP code:

    echo "<p id=\"change_me\">" . $_POST['data'] . "</p>";
    echo "<select onchange=\"getval(this);\" id=\"status\" multiple>";
    echo "<option value=\"1\">One</option>";
    echo "<option value=\"2\">Two</option>";
    echo "<option value=\"3\">One</option>";
    echo "<option value=\"4\">Two</option>";
    echo "</select>";

    JS code:


        $(function() { // on page load
      $('#status').on("change",function(e) {
        $("#change_me").empty(); // clear the container
        var selectedOptionValue = $(this).val();
        if (selectedOptionValue) { // in case they select "Please select"
            url: '/other/shipments.php', 
            type: 'POST', 
            data: {data : selectedOptionValue },
            dataType: 'text',
            success: function(data){

    I would like to echo the selected option values of the multiple select but it doesn't work. For example if I substitute 




    PHP echo correctly the string 'viva'... but I would like to echo the selected values 'data' and the code doesn't work.


    Can someone help me?

  14. I am trying to echo a javascript variable with php but it doesn't work. That's my code.

                            url: 'dendax_trans.php',
                            type: 'POST',
                            dataType: 'text',
                            data: {latitude: '7.15588546', longitude: '81.5659984458'},
    $lat = $_REQUEST['latitude'];
    $lon = $_REQUEST['longitude'];
    echo 'latitude- '.$lat . ', longitude- ' . $lon;

    dendax_trans.php is the name of the php file and the javascript code is located into that php file. 


    The result is unfortunately that:

    latitude- , longitude-

    Someone have any idea?

  15. I would like to print a string variable ($var_xml) with php... the output that i wish is that:

    <?xml version="1.0"?>
      <subproduct sid="001">
        <module name="vat_invoices">

    But if I print that string variable the output that I see is that:

    https://google.com SPAIN 800 1

    How can I print the first output?

  16. I would like to connect two html datalists each other.


    For example starting from a table like that obtained with a SQL query::


    | ID |  Name   | Country| Gender |
    |  1 | Michael | USA    | M      |
    |  2 | John    | USA    | M      |
    |  3 | Michele | Italy  | M      |
    |  4 | Carlo   | Italy  | M      |
    |  5 | Pablo   | Mexico | M      |
    |  6 | Lucy    | USA    | F      |
    SELECT *
    FROM genders

    I would like to select in the first datalist one country in order to see in the second datalist only the names of the persons living in that country. So if I select USA in the first datalist in the second one I should see only the names Michael, John and Lucy.

    I suppose that an easy way to do that is saving the selected option of the first datalist (for example USA) in a variable ($country_selected) and to modify the SQL query to get the data of the second datalist adding a where clause (where=$country_selected)).

    But my problem is that I don't know how to create $country_selected... is it possible with PHP?
  17. I am trying to create a bot to auto login to one external blog. Unfortunately when the html 'body' of that site is loading appears an alert:

    <body onload="alert('Welcome to my personal Blog! Click on continue to Login')"

    Is there a way to avoid that this alert appears in order to auto fill the username and password more easily?

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.