Forum Moderators: coopster

Message Too Old, No Replies

linkin

         

12Strings

10:49 pm on Mar 5, 2020 (gmt 0)

10+ Year Member



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>

lammert

12:34 pm on Mar 6, 2020 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What do you mean by "the link doesn't work"? Is there no table with rows and links produced, is the URL of the link in an invalid format, or is the link in a valid format but when followed it doesn't result in the page you expected?

w3dk

11:57 pm on Mar 6, 2020 (gmt 0)

10+ Year Member Top Contributors Of The Month



...a link to the record but the link doesn't work.


What exactly is the "link to the record" supposed to do?

The only link in your code is ....


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


What is "crud-link.php"? Is that the name of this script? (But why link back to itself?) ...If that is kind-of what you're doing then a seeming inconsistency here is that you are sending a GET URL parameter called "target", when the script is expecting a POST parameter of the same name? So yes, the link won't "work" as expected - if that is what you are expecting to happen?