CodeLobster IDE
http://codelobster.com/forum/

new topic establish target
http://codelobster.com/forum/viewtopic.php?f=3&t=24761
Page 1 of 1

Author:  12Strings [ Sun Mar 22, 2020 8:55 pm ]
Post subject:  new topic establish target

Hi, hope ur all well. The code below creates a dropdown. I select a record from my database and that
record is displayed showing my username, password, etc. or that record and a link to that target(url).
Thee times visited(visits) and date and time last visited(lastused) but all records are updated?
--------------------------------------------------------------------------------------
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "homedb";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
?>
<!DOCTYPE><html><head>
<title>lookup menu</title>
</head>
<body><center><b>
<form name="form" method="post" action="">

<?php
//This creates the drop down box
echo "<select name= 'target'>";
echo '<option value="">' . '--- Select account ---' . '</option>';
$query = mysqli_query($conn, "SELECT target FROM infotbl");
if ($query === false)
{ echo "Something went wrong<br />"; echo mysqli_error($conn); }
else { 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

// ==============================================
if (isset($_REQUEST['target']))
{
$target = $_REQUEST['target'];
// ===============================================
$fetch = "SELECT id, target, purpose, user, password, email, visits, lastused
FROM infotbl WHERE target = '" . mysqli_real_escape_string($conn, $target) . "'";
// ===============================================================================

$result = mysqli_query($conn, $fetch);
if (!$result) { echo "Error:" . (mysqli_error($conn)); }

//display the table
echo '<table border="1"><tr><td bgcolor="cyan" align="center">lookup menu</td></tr>
<tr><td>
<table border="1">
<tr>
<td>id</td>
<td bgcolor="#ccffff"> Target </td>
<td bgcolor="violet"> Purpose </td>
<td bgcolor="#ccffff"> User </td>
<td bgcolor="#ccffff">Password </td>
<td bgcolor="#ccffff"> Email </td>
<td bgcolor="#cyan"> Visits </td>
<td bgcolor="#cyan"> lastused</td>
</tr>';

while ($data = mysqli_fetch_row($result))
{

// ==========================================================
$url = "http://$target";
$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>';

// ------------------------------------
$target='target';

$sql = "UPDATE infotbl SET visits=visits+1, lastused=NOW() WHERE target=$target";
if ($conn->query($sql) === TRUE) { echo "Record updated successfully"; }
else { echo "Error updating record: " . $conn->error; }
$conn->close();
// ------------------------------------
}

?>
</body></html>

Author:  Admin [ Tue Mar 24, 2020 2:36 pm ]
Post subject:  Re: new topic establish target

Hi.

There is the same problem here: You should enclose in quotes $target variable.

Code:
= "UPDATE receiptno SET visits=visits+1, lastused=NOW() WHERE target='".."'";


Regards,
Codelobster Team.

Page 1 of 1 All times are UTC
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/