Jump to content

help w/mysqli


ckir5951

Recommended Posts

The below code produces a dropdown and when a selection is made and submitted produces
a table row with a link to the record but the link doesn't work.  suggestions?

---------------------------------------------------------------------------


<!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($_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))                              
          {
$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>

 

Link to comment
Share on other sites

Why don't you var_dump or print_var the contents of $data to debug this.

An obvious concern is that you do not urlencode() $data[0].  

 

$url= "http://localhost/home/crud-link.php?target=". urlencode($data[0]);

 

We need more information than "but the link doesn't work."  What exactly does that mean? 

Probably not related, but the form is user input, and your mysqli queries should be using mysqli_prepare with a bound parameter.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.