Jump to content
Sign in to follow this  
STUBBORN_ME

probably mixing up sql with php?

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...