I like to code programs that make life a
little easier. This project is to display accounts in a database I use showing login info,
lastime used and number of times. I also want to be able to click and go to the account.
Everything works except that I can't relocate to the url. I include screenshots of the
progression.
screen1) ready for account selection for
select
screen2) shows account chosen
submit
screen3) shows row with information
go to url
screen4) result
and the current code:
<!DOCTYPE><html><head><title>email menu</title></head>
<body><center>
<form name="form" method="post" action="">
<?php
$con=mysqli_connect("localhost","root","","homedb");
//============== check connection
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error(); exit; }
else
{echo "Connected to mySQL</br>";}
//This creates the drop down box
echo "<select name= 'target'>";
echo '<option value="">'.'--- Select lookup account---'.'</option>';
$query = mysqli_query($con,"SELECT target FROM emailtbl");
$query_display = mysqli_query($con,"SELECT * FROM emailtbl");
while($row=mysqli_fetch_array($query))
{echo "<option value='". $row['target']."'>".$row['target']
.'</option>';}
echo '</select>';
?>
<p><p>
<CENTER>then
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT id, target, called, username, password, purpose, emailused,lastused, count FROM emailtbl 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>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#CFB53B align="center">'.'id'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'target'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'called'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'username'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'password'.'</td>'.'
<td bgcolor="#ccffff align="center">'.'purpose'. '</td>'.'
<td bgcolor="#ccffff align="center">'.'emailused'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'lastused'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'count'. '</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><td>$data[8]</td></tr>");}
echo '</table>'.'</td>'.'</tr>'.'</table>';
$id="id";
$target="target";
$count="count";
$lastused="lastused";
$sql = "UPDATE emailtbl SET lastused=NOW(), count=$count + 1 WHERE id=$id";
if ($con->query($sql) === TRUE) { echo "Record updated successfully"; }
else { echo "Error updating record: " . $con->error; }
}
?>
<p>
<button onclick="myFunction('<?php echo $target;?>')">go to url</button>
<?php
?>
</body></html>
Attached Files
Edited by hamluis, 23 September 2022 - 05:03 PM.
Moved from Web Development to Programming - Hamluis.