Jump to content

updating database


ataboy

Recommended Posts

Hi friends, the below code, which I've worked on quite a while,  creates  a dropdown, selects a record with a link to visit the url of that  record.   one ? can I update the table b4 closing?

--------------------------------------------------

below is code:

 <?php

include ('homedb-connect.php');

?>   

<!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>';

  }

?>

</body></html>

------------------------------------------------------

this is my update code:

<?php

$target = $_POST["target"];   

  $visits = 'visits';

  $Lastused = 'Lastused';   

  $sql = "UPDATE receiptno 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();

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.