Guest User

Untitled

a guest
Oct 8th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.93 KB | None | 0 0
  1. <?php
  2.  
  3. $user = 'root';
  4. $password = 'root';
  5. $db = 'SQL-Injection';
  6. $host = 'localhost';
  7. $port = 3306;
  8.  
  9. $link = mysql_connect(
  10. "$host:$port",
  11. $user,
  12. $password
  13. );
  14. $db_selected = mysql_select_db(
  15. $db,
  16. $link
  17. );
  18.  
  19. // dynamically build the sql statement with the input
  20. $userId = 1;
  21. $query = "SELECT id, user_id, car_name, car_model, car_model_year FROM cars WHERE user_id = $userId AND car_name = '$_GET[car_name]'";
  22.  
  23. print_r($query);
  24.  
  25. // execute the query against the database
  26. $result = mysql_query($query);
  27.  
  28. if ($result) {
  29. while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
  30. echo '<pre>';
  31. print_r($row);
  32. echo '</pre>';
  33. }
  34. } else {
  35. die('<p>Error:' . mysql_error() . '</p>');
  36. }
  37.  
  38. // iterate through the record set returned
  39. $row = 1;
  40. while ($db_field = mysql_fetch_assoc($result)) {
  41.  
  42. if ($row <= $rowcount) {
  43. echo '<pre>';
  44. print_r($db_field);
  45. echo '</pre>';
  46. }
  47.  
  48. $row++;
  49. }
Add Comment
Please, Sign In to add comment