0

Firstly i'm not a developer so bear with me :)

I'm trying to delete a row from a small inventory system we are setting up but its still not allowing me to do anything, this is my current code:

Assigned page:

<?php
$password = 'notTheRealPassword';
$conn = mysql_connect('localhost', 'root', $password);
        if(!$conn)
        {
                die('Error connecting database');
        }
        mysql_select_db('inventory_system', $conn);


$query= "SELECT * from assigned";

$result=mysql_query($query);



 echo "<table border='0' cellpadding='100' class='table-striped'>";
         echo "<th>Asset ID</th><th>Asset</th><th>Type</th><th>Manufacturer</th><th>Model</th><th>PC
 Name</th><th>Serial Number</th><th>Purchased</th><th>Warranty
 End</th><th>OS</th><th>OS
 Bit</th><th>CPU</th><th>Memory</th><th>HDD</th><$

    while($row = mysql_fetch_array($result))
     {
      echo '<td>' . $row['asset_id'] . '</td>';
      echo '<td>' . $row['asset'] . '</td>';
      echo '<td>' . $row['type'] . '</td>';
      echo '<td>' . $row['manufacturer'] . '</td>';
      echo '<td>' . $row['model'] . '</td>';
      echo '<td>' . $row['pc_name'] . '</td>';
      echo '<td>' . $row['serial_no'] . '</td>';
      echo '<td>' . $row['purchased'] . '</td>';
      echo '<td>' . $row['warranty_end'] . '</td>';
      echo '<td>' . $row['os'] . '</td>';
      echo '<td>' . $row['os_bit'] . '</td>';
      echo '<td>' . $row['cpu'] . '</td>';
      echo '<td>' . $row['memory'] . '</td>';
      echo '<td>' . $row['hdd'] . '</td>';
      echo '<td>' . $row['plant'] . '</td>';
      echo '<td>' . $row['location'] . '</td>';
      echo '<td>' . $row['username'] . '</td>';
      echo "<td><a href=\"delete.php?id=".$row['asset_id']."\">Delete</a></td>";
          echo "</tr>";
          }
         echo "</table>";

mysql_close();

?>

Delete page:

<?php

$password = 'notTheRealPassword';    
$conn = mysql_connect('localhost', 'root', $password);
        if(!$conn)
        {
                die('Error connecting database');
       }
       mysql_select_db('inventory_system', $conn);


 $id = (int)$_GET['asset_id'];

mysqli_query($conn,"DELETE FROM assigned WHERE asset_id='".$id."'");
mysqli_close($conn);
header("Location: assigned1.php");


?>

I'm guessing it will be something simple.

Cheers,

4
  • 3
    mysql_connect is your issue. You cant mix drivers. You also should use parameterized queries. Commented Jan 6, 2017 at 13:29
  • @chris85 I almost closed it but there are more errors in this than I care to shake a stick at. Jeroen posted something below. Commented Jan 6, 2017 at 13:30
  • @Fred-ii- yea, noticed after there are a few more issues. Retracted vote. Error reporting also could help the OP. OP please see php.net/manual/en/function.error-reporting.php and monitor your error logs. Commented Jan 6, 2017 at 13:35
  • Tell us; what did php.net/manual/en/function.error-reporting.php throw back and mysql_error()? You have quite a few syntax errors here. Edit: GMTA ;-) Commented Jan 6, 2017 at 13:36

1 Answer 1

4

There are a few things wrong here:

  • Your GET variable, the one you put in the link, is id, not asset_id
  • You should not use GET to modify things in your database; if your browser or a plugin decides to pre-fetch links, your database will be wiped out.
  • You can't mix mysql apis, use either mysqli or mysql (although not the latter...).
  • The mysql_* functions are deprecated, you should use PDO or mysqli in combination with prepared statements.
  • When you echo out lots of html, it is easier to just close the php section and then open it again when you need it; now you have php tags inside the echoed texts. The php / strings / html are not separated correctly.
Sign up to request clarification or add additional context in comments.

5 Comments

I'd also look at their code again; Stack's highlighter shows there are errors in and around <$ while($row = mysql_fetch_array($result))...
@Fred-ii- Ugh, there's more?!?!
It looks like it; something wanky's going on up there, did you see syntax highlighting?
@Fred-ii- Yeah, half the time I just assume the OP is playing around with ` characters in order to format the code :-) Added another point though.
@Fred-ii- Or not, the results'll just look funny ;-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.