My project is to: select record from database menu(working),
click(?) that selection to update field1, field2
and link to the associated location. I'd appreciate any guidance.[/text]
==================================================
this is update code:
Code: Select all
<?php
$servername = "localhost";$username = "root";$password = "xxxx";
$dbname = "xxxxDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn)
{die("Connection failed: " . mysqli_connect_error());}
$id = $_POST['id'];
$lastused = $_POST['lastused'];
$visits = $_POST['visits'];
$name = $_POST['target'];
$sql = "UPDATE emailtbl SET visits = visits + 1, lastused = NOW() WHERE target = '".$name."'";
if (mysqli_query($conn, $sql))
{echo "you done good";}
else
{echo "back up charlie: " . mysqli_error($conn);}
?> this code connects, selects & displays the desired record:
<html><title>email menu</title>
<head></head>
<BODY><center>
<FORM name=form method="post" action="">
Code: Select all
<?php
include ('gethomedb.php');
// ==========This creates the drop down box using records in the table
echo "<select name = 'target'>";
echo '<option value="">'.'---select email 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 class=highlight value='". $row['target']."'>".$row['target']
.'</option>';}
echo '</select>';
?>
<input type="submit" name="submit" value="Submit"/>
</form>
<?php
if(isset($_POST['target']))
{
$id = $_POST['id'];
$visits = $_POST['visits'];
$lastused = $_POST['lastused'];
$name = $_POST['target'];
$fetch="SELECT target, username, password, emailused, visits, lastused,
purpose, saved FROM emailtbl WHERE target = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}
// =============================== this displays the table
echo '<table border="1">'.'<tr>'.'
<td bgcolor="#FFD47F" align="center">'. 'email menu'. '</td>'.'</tr>';
echo '<tr>'.'<td>'.'<table border="1">'.'<tr>'.'
<td bgcolor="#ccffff">'.'target'.'</td>'.'
<td bgcolor="#ccffff">'.'username'.'</td>'.'
<td bgcolor="#ccffff">'. 'password' .'</td>'.'
<td bgcolor="#ccffff">'. 'emailused'. '</td>'.'
<td bgcolor="#FFD47F">'.'visits' .'</td>'.'
<td bgcolor="#FFD47F">'.'lastused' .'</td>'.'
<td bgcolor="#ccffff">'. 'purpose'. '</td>'.'
<td bgcolor="#ccffff">'. '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></tr>");}
echo '</table>'.'</td>'.'</tr>'.'</table>';
}
?>