Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Generic User Avatar

Hi, whoever you are who is going to solve this.


  • Please log in to reply
16 replies to this topic

#1 guitarzRus

guitarzRus

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 23 September 2022 - 04:48 PM

 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.


BC AdBot (Login to Remove)

 


#2 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 23 September 2022 - 05:14 PM

Why are you using a button to do a simple redirect? You shouldn't be using the onclick attribute to register event handlers either. I would strongly suggest simply using a <a> tag and then styling it as a button using CSS.



#3 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 23 September 2022 - 05:41 PM

please demonstrate an anchor statement using a target url such as http://apachefriends.com I select from the menu. thanks.


Edited by guitarzRus, 23 September 2022 - 05:42 PM.


#4 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 23 September 2022 - 06:28 PM

You can just pass it the same way as you're doing with the JS function. I assume that the page you're redirecting to takes a query string parameter?

 

Here's an example - https://teamtreehouse.com/community/passing-a-get-variable-through-a-link-with-php-2



#5 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 23 September 2022 - 07:29 PM

I'm sorry but I don't understand. The target changes as I make a selection




#6 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 25 September 2022 - 08:30 AM

To further explain what I'm trying to do, I needed something to keep track of passwords.
Below is HTML code which displays username and passwords and  has a button that when clicked
takes me to the target01 site.
--------------------------------------------------------------------
<tr>
<td><input name="radiobutton" type="radio" value="http://target01.com"
onClick="gotolink()">target01</td>
<td>computer forums</td>
<td>username01</td>
<td>lkcjjhfrdtrd</td>
<tr>
<td><in
=====================================================================
I put the records in a database, and now have an option to click and get a menu, click
and select a specific record, see the information and click to take me to the target site.
All's well until I click "go to url". S*&^%T!
You have my code. Any suggestions? Be nice.



#7 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 26 September 2022 - 04:18 AM

The $target variable contains the target URL does it not? The reason why your JS code isn't executing is because by default a button performs a form submission, you need to alter your button element so the type attribute is set to button i.e. <button type="button"></button>

 

Nevertheless, you shouldn't be using a <button> element in order to perform page navigation.



#8 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 26 September 2022 - 10:47 AM

what should I use instead of: <button onclick="myFunction('<?php echo $target;?>')">go to url</button> ?



#9 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 26 September 2022 - 03:25 PM

You'll need something like the following:

 

<a href="<?php echo $target;?>">Go to URL</a>



#10 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 26 September 2022 - 03:36 PM

that gives me:

Not Found

The requested URL was not found on this server.

 

I confirmed the presence of the url in the database



#11 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 26 September 2022 - 03:54 PM

What is the HTML set to? Have you checked within the browser developer tools?



#12 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 26 September 2022 - 04:00 PM

What is the HTML set to? Have you checked within the browser developer tools?

What are u asking? I'm accessing the file with: <a href="http://localhost/home/lookupsel.php">



#13 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 26 September 2022 - 04:45 PM

The HTML is okay then, it's just that your URL is incorrect. You'll need to check that the directory path exists on your system.



#14 guitarzRus

guitarzRus
  • Topic Starter

  •  Avatar image
  • Members
  • 30 posts
  • OFFLINE
  •  
  • Local time:10:56 PM

Posted 26 September 2022 - 06:02 PM

that gives me:

Not Found

The requested URL was not found on this server.

 

I confirmed the presence of the url in the database

note the quote



#15 xBlueRobot

xBlueRobot

  •  Avatar image
  • BSOD Kernel Dump Expert
  • 408 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:%systemroot%
  • Local time:06:56 AM

Posted 27 September 2022 - 03:21 AM

It's irrelevant wherever the URL exists within the database or not, that is being used to merely populate the href attribute of the <a> tag. Do you understand what a HTTP Not Found (404) response means? I would suggest taking a look at the directory where you have index.php saved and then ensure that a home directory exists within the same folder with the lookupsel.php file.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users