STUBBORN_ME Posted April 14, 2020 Share Posted April 14, 2020 Hey Guys, I'm an a complete noob if it comes to programming. For my own store I am programming my own productcatalog because i don't like to work with Wordpress... To get data from my database I used this code (just a snipped, i opened a connection in the previous code from the document) : <?php $resultSet = $conn->query("SELECT ID, naam, groepID FROM subgroep INNER JOIN groep ON subgroep.groepID=groep.ID"); if($resultSet->num_rows != 0){ while($rows = $resultSet->fetch_assoc()){ $subgroep = $rows['naam']; echo "<option value='$subgroep'>$subgroep</option>"; } }else{ echo "No results"; } ?> The databases I use are named: 'groep' (ID, naam, afbeelding) and 'subgroep' (ID, naam, groepID, afbeelding). So I geuss it's quite a stupid mistake I made. But can someone please explane to me how it's done properly? Grtz, Saskia Link to comment Share on other sites More sharing options...
ckrudelux Posted April 16, 2020 Share Posted April 16, 2020 Nothing wrong with the code above (Just not so reusable). To think of is: that user input don't go raw in the SQL query (mysqli or PDO makes that easy) and not outputting raw user input/data to the browser by using for example htmlentities function. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now