Pulling data and printing it in an HTML table

前端 未结 3 2086
一向
一向 2020-12-22 08:17

From a MySQL table called \"submission\" containing the fields \"loginid, submissionid, title, url, datesubmitted, displayurl\", I would like to print an HTML table thats co

3条回答
  •  一整个雨季
    2020-12-22 09:04

    Your query is probably failing.

    Try echoing the return from mysql_error(); after trying the query to see what the issue might be.

    You should also protect your input against injection. If loginID is a username, you need to surround a string in a mySQL query with quotes - if loginID is a username. If it's an integer you may be okay.

    There are more robust ways to do this but simply:

      $profile = mysql_real_escape_string($_GET['profile']);
    
      $sqlStr = "SELECT loginid, submissionid, title, url, datesubmitted, displayurl
                   FROM submission
                  WHERE loginid = '$profile'
               ORDER BY datesubmitted DESC";
    
      $result = mysql_query($sqlStr);
    
      if($result) {
          // Handle output
      } 
      else {
          echo 'query failed';
          // don't leave this here in production!
          echo mysql_error();
      }
    

提交回复
热议问题