CodeLobster IDE

Free cross-platform PHP IDE (HTML, PHP, CSS, JavaScript, Python code editor) with support Drupal, Joomla, Twig, JQuery, BackboneJS, LaravelJS, Node.js, CodeIgniter, CakePHP, Laravel, Magento, MeteorJS, Phalcon, Symfony, VueJS, WordPress, Yii
It is currently Thu Mar 28, 2024 9:06 am

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 
Offline

Joined: Tue Jun 16, 2015 1:03 am
Posts: 21
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>


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

Joined: Wed Sep 12, 2007 2:18 pm
Posts: 3931
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.


Top
 Profile  
 
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: No registered users and 51 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:  
cron
Powered by phpBB © 2016 phpBB Group