CodeLobster IDE

Free cross-platform PHP IDE (HTML, PHP, CSS, JavaScript code editor) with support Drupal, Joomla, Twig, JQuery, BackboneJS, LaravelJS, Node.js, Fhalcon, CodeIgniter, CakePHP, Laravel, Magento, MeteorJS, Phalcon, Symfony, VueJS, WordPress, Yii
It is currently Wed Aug 10, 2022 7:29 pm

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: new topic establish target
PostPosted: Sun Mar 22, 2020 8:55 pm 

Joined: Tue Jun 16, 2015 1:03 am
Posts: 15
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?
$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);
<title>lookup menu</title>
<form name="form" method="post" action="">

//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"/>


// ==============================================
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>
<table border="1">
<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>

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>
echo '</table>

// ------------------------------------

$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; }
// ------------------------------------


 Post subject: Re: new topic establish target
PostPosted: Tue Mar 24, 2020 2:36 pm 
Site Admin

Joined: Wed Sep 12, 2007 2:18 pm
Posts: 3841

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

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

Codelobster Team.

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Google [Bot] and 21 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2016 phpBB Group