Jump to content
#StayAtHome ×

ataboy

New Members
  • Content Count

    2
  • Joined

  • Last visited

Community Reputation

0 Neutral

About ataboy

  • Rank
    Newbie
  1. Having issue insertinginto database. The code are below followed by result. thanks for any advice Form code: <html> <body><center> <font size=+2><b> Insert data into information database</font><br> <script type="text/javascript">document.write(mmddyy);</script> <form action="crud-insert.php" method="post"> <p><label for="id">id:</label> <input type="text" name="id" id="id"></p> <p><label for="target">target:</label> <input type="text" name="target" id="target"></p> <p><label for="purpose">purpose:</label> <input type="text" name="purpose" id="purpose"></p> <p><label for="user">user:</label> <input type="text" name="user" id="user"></p> <p><label for="password">password:</label> <input type="text" name="password" id="password"></p> <p><label for="email">email:</label> <input type="text" name="email" id="email"></p> <p><label for="visits">visits:</label> <input type="text" name="visits" id="visits"></p> <p><label for="lastused"> lastused:</label> <input type="text" name="lastused" id="lastused"></p> <input type="submit" name="submit" value="Submit"> </form></body></html> ------------------------------------------------------------------- php code: <?php $link = mysqli_connect("localhost", "root", "", "homedb"); // Check connection if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } $id=$_POST['id']; $target=$_POST['target']; $purpose=$_POST['purpose']; $user=$_POST['user']; $password=$_POST['password']; $email=$_POST['email']; $visits=$_POST['visits']; $lastused=$_POST['lastused']; $sql = "INSERT INTO infotbl (id, target, purpose, user, password, email, visits, lastused) VALUES ('$id', '$target', '$purpose', '$user', '$password', '$email', '$visits', '$lastused')"; if ($conn->query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } $conn->close(); ?> --------------------------------------------------------------- this is result: query($sql) === TRUE) { echo "New record created successfully"; } else { echo "Error: " . $sql . " " . $conn->error; } $conn->close(); ?>
  2. 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(); ?>
×
×
  • 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.