Jump to content

probably mixing up sql with php?


STUBBORN_ME

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...