1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

help w/mysqli

Discussion in 'PHP' started by ataloss, Mar 2, 2020.

  1. #1
    Hi guys, the below code creates my dropdown.
    I select the record and submit and the selected record is displayed.
    ------------------------------------------------------------------
    <!DOCTYPE><html><head><title>email menu</title></head>
    <body><center>
    <form name="form" method="post" action="">
    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';
    
    //This creates the drop down box
    echo "<select name= 'target'>";
    echo '<option value="">'.'--- Select email account ---'.'</option>';
    $query = mysqli_query($con,"SELECT target FROM lookuptbl");
    $query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
    while($row=mysqli_fetch_array($query))
    {echo "<option value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/><!-- update "lastused" using selected "target"-->
    </form></body></html>
    
    <!DOCTYPE><html><head><title>email menu</title></head>
    <body><center>
    
    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';
    if(isset($_POST['target']))
    {
    $name = $_POST['target'];
    $fetch="SELECT target, purpose, user, password, email, visits, date,
    saved FROM lookuptbl WHERE target = '".$name."'";
    $result = mysqli_query($con,$fetch);
    if(!$result)
    {echo "Error:".(mysqli_error($con));}
    
    //display the table
    echo '<table border="1">'.'<tr>'.'<td bgcolor="#ccffff align="center">'. 'Email menu'. '</td>'.'</tr>';
    echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
    <td bgcolor="#CFB53B>'.'target'.'</td>'.'
    <td bgcolor="#ccffff>'.'purpose'. '</td>'.'
    <td bgcolor="#ccffff>'.'user'.'</td>'.'
    <td bgcolor="#ccffff>'.'password'.'</td>'.'
    <td bgcolor="#ccffff>'.'email'.'</td>'.'
    <td bgcolor="#CFB53B>'.'visits'. '</td>'.'
    <td bgcolor="#CFB53B>'.'date'.'</td>'.'
    <td bgcolor="#CFB53B>'. 'saved' .'</td>'.'</tr>';
    while($data=mysqli_fetch_row($result))
    {echo ("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td>
    <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>");}
    echo '</table>'.'</td>'.'</tr>'.'</table>';
    }
    ?>
    </body></html>
    Code (markup):
    =========================================
    SEMrush
    but the headers
    should be: target purpose user password email visits date saved
    but are: purpose password visits saved
    target,user,email,and date are skipped (every other heading is skipped)?
    -----------------------------------------------
    a screenshot is included to illustrate
    --------------------------------------------
    What's left after is that I want include a button to link to the target.
    suggestions?
     
    Last edited by a moderator: Mar 2, 2020
    ataloss, Mar 2, 2020 IP
    SEMrush
  2. JEET

    JEET Notable Member

    Messages:
    3,285
    Likes Received:
    349
    Best Answers:
    15
    Trophy Points:
    235
    #2
    You are not closing the '"' sign after bgcolor attribute in your <td bgcolor="#ccffff> tags...

    Fix that, it should work then.
     
    JEET, Mar 2, 2020 IP
  3. JEET

    JEET Notable Member

    Messages:
    3,285
    Likes Received:
    349
    Best Answers:
    15
    Trophy Points:
    235
    #3
    I think you asked another question for this same code earlier also.
    Then also I told you, "not" to pass a variable directly to database.
    At least do this:

    $name= addslashes($_POST['target']);

    Also, in your HTML, why are you using table inside table? There is only 1 row and 1 column in the first table...

    And these so many '.' are pointless. Not doing anything anywhere.
     
    JEET, Mar 3, 2020 IP
  4. ataloss

    ataloss Active Member

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #4
    here is what I tried. of course no go:
    
    <!DOCTYPE><html><head><title>lookup menu</title></head>
    <body><center>
    <script language="Javascript" type="text/javascript">
    function gotolink() {
    var destination= self.location;
    
    for(var i = 0; i<document.formname.radiobutton.length; i++){
    if(document.formname.radiobutton.checked) {
    destination=document.formname.radiobutton.value }
    }
    window.location = destination;
    }
    </script>
    
    <form name="form" method="post" action="">
    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';
    
    //This creates the drop down box
    echo "<select name= 'target'>";
    echo '<option value="">'.'--- Select account ---'.'</option>';
    $query = mysqli_query($con,"SELECT target FROM lookuptbl");
    $query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
    while($row=mysqli_fetch_array($query))
    {echo "<option value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/><!-- update "lastused" using selected "target"-->
    </form><center>
    
    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';
    if(isset($_POST['target']))
    {
    $name = $_POST['target'];
    $fetch="SELECT target, purpose, user, password, email, visits, date,
    saved FROM lookuptbl WHERE target = '".$name."'";
    $result = mysqli_query($con,$fetch);
    if(!$result)
    {echo "Error:".(mysqli_error($con));}
    
    //display the table
    echo '<table border="1"><tr><td bgcolor="#ccffff" align="center">lookup menu</td></tr>
    <tr><td><table border="1">
    
    <th bgcolor="#CFB53B"><input name="radiobutton" type="radio"
    onClick="gotolink()">target</th>
    
    <th bgcolor="#ccffff">purpose</th>
    <th bgcolor="#ccffff">user</th>
    <th bgcolor="#ccffff">password</th>
    <th bgcolor="#ccffff">email</th>
    <th bgcolor="#CFB53B">visits</th>
    <th bgcolor="#CFB53B">date</th>
    <th bgcolor="#CFB53B">saved</th></tr>';
    while($data=mysqli_fetch_row($result))
    {echo ("<tr><td>$data[0]</td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td>
    <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>");}
    echo '</table>'.'</td>'.'</tr>'.'</table>';
    }
    ?>
    </body></html>
    
    Code (markup):
     
    Last edited by a moderator: Mar 4, 2020
    ataloss, Mar 3, 2020 IP
  5. JEET

    JEET Notable Member

    Messages:
    3,285
    Likes Received:
    349
    Best Answers:
    15
    Trophy Points:
    235
    #5
    How will this work my friend?

    In your javascript you are going through all radio buttons to get the value of a selected radio button, then forming a URL based on that, and changing window.location to that.
    No value is getting found there.
    Even if you find a value, URL is not formed.

    Then in your HTML,
    you are not setting a value="$target" to radio buttons.
    You are making only one radio button by the way, in the heading, and that also has no value assigned to it.

    Forget all this code, you can do this like this:
    
    echo '<table border="1"><tr><td bgcolor="#ccffff" align="center">lookup menu</td></tr>
    <tr><td>
    <table border="1">
    <tr>
    <td> Target </td>
    <td> Purpose </td>
    <td> User </td>
    <td> Password </td>
    <td> Email </td>
    <td> Visits </td>
    <td> Date </td>
    <td> Saved </td>
    </tr>';
    
    
    while($data=mysqli_fetch_row($result)){
    
    $url= "URL_of_webpage.php?target=". $data[0];
    $link= '<a href="'.$url.'">'. $data[0]. '</a>';
    
    echo ("<tr><td> $link </td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td>
    <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>");
    }//while loop ends here
    
    echo '</table>
    </td>/tr></table>';
    
    Code (markup):

    Change the "URL_of_webpage.php" to full path of your PHP script.
     
    Last edited by a moderator: Mar 4, 2020
    JEET, Mar 3, 2020 IP
  6. ataloss

    ataloss Active Member

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #6
    Here is sugested code. Not sure if I understood but the target shows as a
    link(not working). Clicking the link takes me back to the select and submit.
    -----------------------------------------------------
    <!DOCTYPE><html><head>
    <title>lookup menu</title>
    </head>
    <body><center>
    <form name="form" method="post" action="">
    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';

    //This creates the drop down box
    echo "<select name= 'target'>";
    echo '<option value="">'.'--- Select account ---'.'</option>';
    $query = mysqli_query($con,"SELECT target FROM lookuptbl");
    $query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
    while($row=mysqli_fetch_array($query))
    {echo "<option value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/>
    </form><center>

    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';
    if(isset($_POST['target']))
    {
    $name = $_POST['target'];
    $fetch="SELECT target, purpose, user, password, email, visits, date,
    saved FROM lookuptbl WHERE target = '".$name."'";
    $result = mysqli_query($con,$fetch);
    if(!$result)
    {echo "Error:".(mysqli_error($con));}

    //display the table
    echo '<table border="1"><tr><td bgcolor="#ccffff" align="center">lookup menu</td></tr>
    <tr><td>
    <table border="1">
    <tr>
    <td> Target </td>
    <td> Purpose </td>
    <td> User </td>
    <td> Password </td>
    <td> Email </td>
    <td> Visits </td>
    <td> Date </td>
    <td> Saved </td>
    </tr>';

    while($data=mysqli_fetch_row($result)){

    // Change the "URL_of_webpage.php" to full path of your PHP script.

    $url= "http://localhost/home/crude-link.php?target=". $data[0];
    $link= '<a href="'.$url.'">'. $data[0]. '</a>';

    echo ("<tr><td> $link </td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td>
    <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>");
    } //while loop ends here

    echo '</table>
    </td></tr></table>';


    }
    ?>
    </body></html>
     
    Last edited: Mar 4, 2020
    ataloss, Mar 4, 2020 IP
  7. JEET

    JEET Notable Member

    Messages:
    3,285
    Likes Received:
    349
    Best Answers:
    15
    Trophy Points:
    235
    #7
    Again same thing is happening like your very first error.
    You are using $_POST to get $name.
    Use this:

    $name= addslashes($_REQUEST['target']);
    instead of:
    $name= $_POST['target'];

    Although I am not sure what will happen with this, only the page will reload...
    because you are resending $target back to same page, same as you did with select...

    When people click $target in the table, what do you want to do there?
    That code is missing.
     
    JEET, Mar 4, 2020 IP
  8. ataloss

    ataloss Active Member

    Messages:
    77
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    63
    #8
    All the code below is intended to and does create a dropdown which selects a record(url)
    and submit produces and does not display a table row with a link to the record.
    "select & submit" goes back to "select & submit". I've been working on this along time.
    Jeet u got me so close
    -----------------------------------------------------------------
    <!DOCTYPE><html><head>
    <title>lookup menu</title>
    </head>
    <body><center><b>
    <form name="form" method="post" action="">

    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';

    //This creates the drop down box
    echo "<select name= 'target'>";
    echo '<option value="">'.'--- Select account ---'.'</option>';
    $query = mysqli_query($con,"SELECT target FROM lookuptbl");
    $query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
    while($row=mysqli_fetch_array($query))
    {echo "<option value='". $row['target']."'>".$row['target']
    .'</option>';}
    echo '</select>';
    ?>
    <input type="submit" name="submit" value="Submit"/>
    </form><center>

    <?php
    // error_reporting(0);
    error_reporting(E_ALL ^ E_NOTICE);
    include 'homedb-connect.php';

    // ==============================================
    if(isset($_GET['target']))
    {
    $target = $_GET['target'];
    // ===============================================
    $fetch="SELECT target, purpose, user, password, email, visits, date, saved
    FROM lookuptbl WHERE target = '". mysqli_real_escape_string ( $con , $target ) . "'";
    // ===============================================================================

    $result = mysqli_query($con,$fetch);
    if(!$result)
    {echo "Error:".(mysqli_error($con));}

    //display the table
    echo '<table border="1"><tr><td bgcolor="#ccffff" align="center">lookup menu</td></tr>
    <tr><td>
    <table border="1">
    <tr bgcolor="#ccffff">
    <td> Target </td>
    <td> Purpose </td>
    <td> User </td>
    <td> Password </td>
    <td> Email </td>
    <td> Visits </td>
    <td> Date </td>
    <td> Saved </td>
    </tr>';

    while($data=mysqli_fetch_row($result))
    {

    // ==========================================================
    $url= "http://localhost/home/crud-link.php?target=". $data[0];
    $link= '<a href="'.$url.'">'. $data[0]. '</a>';
    // ===========================================================

    echo ("<tr><td> $link </td><td>$data[1]</td><td>$data[2]</td><td>$data[3]</td>
    <td>$data[4]</td><td>$data[5]</td><td>$data[6]</td><td>$data[7]</td></tr>");
    }
    echo '</table>
    </td></tr></table>';
    }
    ?>
    </body></html>
     
    ataloss, Mar 6, 2020 IP
  9. JEET

    JEET Notable Member

    Messages:
    3,285
    Likes Received:
    349
    Best Answers:
    15
    Trophy Points:
    235
    #9
    See, now you went back to square one.

    You are using method="post" in your form,
    but then in your PHP code, you are reading$_GET, which is empty...
    Use $_REQUEST instead.

    $target= $_REQUEST['target'];
    instead of
    $target= $_GET['target'];

    This will solve the issue.
     
    JEET, Mar 6, 2020 IP