on-click use

1Tsme1941

Member
Hi, a little help, please. I have been using:

<tr bgcolor="#D4AAFF">
<td><input name="radiobutton" type="radio"
value="http://target.com" onclick="gotolink()">target name</td>
<td>purpose for target</td>
<td>username " "</td>
<td>password " "</td>
<td>secure?/ans " "</td>
<td>emailused " "</td>
<td>0000-00-00</td>
<td>22</td>
<td></td>
<td>Y</td>

in an html program to keep show passwords, click on the button and go to the url.

This BELOW code selects a record from a database table and updates the date visited and times visited.
I want to use the onclick here to go to the url also.

the 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();}
else
{echo "Connected to mySQL</br>";}
//This creates the drop down box
echo "<select name= 'target'>";
echo '<option value="">'.'--- Select email 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>';
?>
<p><p>
<CENTER>then

<input type="submit" name="submit" value="Submit"/>
</form></body></html>

<!DOCTYPE><html><head></head>
<body><center>
<?php
$con=mysqli_connect("localhost","root","","homedb");
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT id, target, username, password, purpose, emailused,lastused,
visitcount, 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">'. 'Email 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="#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">'.'visitcount'. '</td>'.'
<td bgcolor="#CFB53B align="center">'.'saved' .'</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>';

$target='target';
$visitcount='visitcount';
$lastused='lastused';
$saved='saved';

$sql = "UPDATE lookuptbl SET visitcount=$visitcount + 1, lastused=NOW() ,
saved='$saved'
WHERE target='$target'";
if ($con->query($sql) === TRUE) { echo "Record updated successfully"; }
else { echo "Error updating record: " . $con->error; }
$con->close();

}
?>
</body></html>

Thanks in advance for response!
 

Cromewell

Administrator
Staff member
So you want to visit the link and update your tracking stats at the same time? Or you just want to visit the link when the radio is clicked and only want to update the tracking stats when they submit the form?

To use an onclick handler to open a link you use javascript, and the window.open method https://developer.mozilla.org/en-US/docs/Web/API/Window/open . You can either write a function (usually recommended) or jam the call into the onlick. Something like onclick="window.open('somewhere', '_blank');"

That being said, for this specific use-case, just use LastPass. You lose tracking when you last visited (I think) but it is just a better solution.
 

Cromewell

Administrator
Staff member
 

1Tsme1941

Member
Friend, I'm trying to develop a program here, not find a substitute. This code below shows me all my accounts and info and isolates the one of my preference. I just then want to redirect to that selected target. Thanks for your attempts.
<!DOCTYPE><html><head><title>lookup 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();}
else
{echo "Connected to mySQL</br>";}
//This creates the drop down box
echo "<select name= 'target'>";
echo '<option value="">'.'--- Select email 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>';
?>
<p><p>
<CENTER>then

<input type="submit" name="submit" value="Submit"/>
</form></body></html>

<!DOCTYPE><html><head></head>
<body><center>

<script language="javascript">
var sid;
function myFunction(sid) {
window.open(sid);
}
</script>

<?php
$con=mysqli_connect("localhost","root","","homedb");
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT id, target, username, password, purpose, emailused,lastused,
count, 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>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#CFB53B align="center">'.'id'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'target'.'</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>'.'
<td bgcolor="#CFB53B align="center">'.'saved' .'</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>';

$target='target';
$count='count';
$lastused='lastused';
$saved='saved';

$sql = "UPDATE lookuptbl SET count=$count + 1, lastused=NOW() ,
saved='$saved'
WHERE target='$target'";
if ($con->query($sql) === TRUE) { echo "Record updated successfully"; }
else { echo "Error updating record: " . $con->error; }
$con->close();

}
?>
<--redirect ?-->
<--<a href="">go to site</a>-->
<button onclick="myFunction('<?php echo $row21["url"];?>')">go to site</button>
</body></html>
 

1Tsme1941

Member
Ok, thanks, that "$row21" has had me scratching my head since I first saw it. Now what are you saying
"What is $row21 this is the first occurance"? Are you asking me?
 

Cromewell

Administrator
Staff member
Are you asking me?
It is your code correct? I can guess what it is supposed to be, my assumption would be a row returned from your database, but no where else in your code is $row21 ever referenced, so it will be an undefined variable at that point.
 

1Tsme1941

Member
Hi, the code below displays the records in a database table. I select a record from a dropdown and
update a couple of fields in that record. So far so good.... Then I want to, using the "target"
field (which is a url) as an argument, onclick or whatever and go to that url. Surely there's a way?

<!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();}
else
{echo "Connected to mySQL</br>";}
//This creates the drop down box
echo "<select name= 'target'>";
echo '<option value="">'.'--- Select email 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>';
?>
<p><p>
<CENTER>then

<input type="submit" name="submit" value="Submit"/>
</form>
<?php
$con=mysqli_connect("localhost","root","","homedb");
if(mysqli_errno($con))
{echo "Can't Connect to mySQL:".mysqli_connect_error();}
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT id, target, username, password, purpose, emailused,lastused,
count 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>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#CFB53B align="center">'.'id'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'target'.'</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></tr>");}
echo '</table>'.'</td>'.'</tr>'.'</table>';
$id="id";
$target="target";
$count="count";
$lastused="lastused";
$sql = "UPDATE lookuptbl SET lastused=NOW(), count=$count + 1 WHERE target=$target";
if ($con->query($sql) === TRUE) { echo "Record updated successfully"; }
else { echo "Error updating record: " . $con->error; }
// $con->close();

}
?>
<p>
<button onclick="myFunction('<?php echo $row["url"];?>')">go to url</button>
<script language="javascript">
var sid;
function myFunction(sid) {
window.open(sid);
}
</script>
</body></html>
 

1Tsme1941

Member
<!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();}
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 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>';
?>
<p><p>
<CENTER>then

<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT id, target, username, password, purpose, emailused,lastused,
count 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>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#CFB53B align="center">'.'id'.'</td>'.'
<td bgcolor="#CFB53B align="center">'.'target'.'</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></tr>");}
echo '</table>'.'</td>'.'</tr>'.'</table>';
$id="id";
$target="target";
$count="count";
$lastused="lastused";
$sql = "UPDATE lookuptbl SET lastused=NOW(), count=$count + 1 WHERE target=$target";
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>
 

Attachments

  • scr01.png
    scr01.png
    21.8 KB · Views: 2
  • scr02.png
    scr02.png
    22.1 KB · Views: 1
  • scr03.png
    scr03.png
    35 KB · Views: 2
  • scr04.png
    scr04.png
    28.7 KB · Views: 2

1Tsme1941

Member
another time you've jumped in just to be annoying? I just need an answer to what I think a knowledgable programmer should know and the staff of this forum would offer. I won't bother you further and remove you
from my "recommended forums" pages.
 

johnb35

Administrator
Staff member
Am I to understand that no one here understands the PHP manuals enough to relate to your benefactors?
I've told you before that we aren't a very active forum and that if you wanted immediate replies, it would be better for you to find a dedicated forum that deals with programming. We only have a couple members that even know how to code.
 
Top