ckir5951 Posted September 23, 2022 Share Posted September 23, 2022 Quote 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> Quote Link to comment Share on other sites More sharing options...
maxxd Posted September 24, 2022 Share Posted September 24, 2022 What does the JavaScript function myFunction() look like? Quote Link to comment Share on other sites More sharing options...
Moorcam Posted September 24, 2022 Share Posted September 24, 2022 By using <button onclick="myFunction('<?php echo $target;?>')">go to url</button> And from looking at the code: $target="target"; You are asking the myfunction to look for 'target' That's all it will look for is 'target'. Change it to $target=$row['target']; I could be wrong though. But that's how I am seeing it. Quote Link to comment Share on other sites More sharing options...
ckir5951 Posted September 26, 2022 Author Share Posted September 26, 2022 I really thought that the code was tested Quote Link to comment Share on other sites More sharing options...
maxxd Posted September 26, 2022 Share Posted September 26, 2022 Famous last words... 😆 2 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.