Jump to content

LearningScholar

New Members
  • Posts

    8
  • Joined

  • Last visited

LearningScholar's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. oh thanks guys! using 'mysqli_real_escape_string' worked but are the '$errors' and '$error' necessary?
  2. Hey guys, Earlier I mentioned making search criteria in my database. I also had to put in something to make it add to the database. I made some code like this: <form id="form" name="form" method="post" action="Website2.php"> <p> <label for="Genre">Genre</label> <input type="text" name="Genre" id="Genre" /> </p> <p> <label for="Naam">Naam</label> <input type="text" name="Naam" id="Naam" /> </p> <p> <label for="Jaar">Jaar</label> <input type="text" name="Jaar" id="Jaar" /> </p> <p> <label for="Regisseur">Regisseur</label> <input type="text" name="Regisseur" id="Regisseur" /> </p> <p> <input type="submit" name="Verzenden" id="Verzenden" value="Verzenden" /> </p> </form> <?php $Genre = $_POST["Genre"]; $Naam = $_POST["Naam"]; $Jaar = $_POST["Jaar"]; $Regisseur = $_POST["Regisseur"]; /*Hier hoeft geen verbinden meer gemaakt te worden met de database*/ if (isset($_POST['Verzenden']) && trim($_POST['Verzenden'])!=''){ $sql = "INSERT INTO Movies (Genre, Naam, Jaar, Regisseur) VALUES ('$Genre', '$Naam', '$Jaar', '$Regisseur')"; $resultaat = mysqli_query($db, $sql); $verbreken = mysqli_close($db); echo "De gegevens van $Naam zijn opgeslagen in de database.";} else echo 'Hier kunt u iets toevoegen'; ?> However it didn't work. I got the problem "Warning: mysqli_query() expects parameter 1 to be mysqli, null given in... on line 119" Can you guys help please?
  3. Thank you so much! I've staring for hours at my code trying to find a way to make it work. And also thanks for the checkboxesproblem you solved. I didn't even noticed it myself XD
  4. Do you know a code which only gives results if a value has been posted?
  5. When you're logged in and redirected to this form it automatically executes the criteria as nothing and it shows everything fromm the database. I would like to have it search only after you clicked on the search button
  6. The site contains a login system. you'll get to this file after you succesfully logged in. Might that be an issue?
  7. Hey guys, As my name refers, I am a beginner at school. I had a project in which I had to make a database. The database contains movies which you can search for. However in the beginning, the results only appeared when the name of the movie was fully written. I solved it by using 'LIKE' in the query. But now I got the problem of results being shown before you searched for the results. The form is on the same file as the result. I could seperate them but in this case, it's no option (for some reasons which doesn't matter). Can this problem get solved in an other way? This is the part of the code of my php file: <form id="form1" name="form1" method="post" action="Website2.php"> <div id="Zoekend"> <p> <label for="textfield"></label> <label for="Zoek"></label> <input type="text" name="Zoek" id="Zoek" /> </p> <p> <label> <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_0" /> Genre</label> <br /> <label> <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_1" /> Naam</label> <br /> <label> <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_2" /> Jaar</label> <br /> <label> <input type="radio" name="RadioGroup1" value="radio" id="RadioGroup1_3" /> Regisseur</label> <br /> <input type="submit" name="Zoeken" id="Zoeken" value="Zoeken" /> <br /> </p> </form> </div> <div id="Resultaat"> <h1> Zoekresultaten: </h1> <?php $zoekterm = $_POST['Zoek']; $username = '1509506_dyon'; $wachtwoord = 'u2pv6stvk'; $host = 'fdb6.awardspace.net'; $database = '1509506_dyon'; mysql_connect($host, $username, $wachtwoord); mysql_select_db ($database); $sql = "SELECT * FROM Movies WHERE Genre LIKE '%$zoekterm%'"; $resultaat = mysql_query ($sql); while ( $row = mysql_fetch_assoc($resultaat) ) { echo $row['Genre'] . " - " . $row['Naam'] . " - " . $row ['Jaar'] . " - " . $row ['Regisseur'] .'<br>' ; } $sql = "SELECT * FROM Movies WHERE Naam LIKE '%$zoekterm%'"; $resultaat = mysql_query ($sql); while ( $row = mysql_fetch_assoc($resultaat) ) { echo $row['Genre'] . " - " . $row['Naam'] . " - " . $row ['Jaar'] . " - " . $row ['Regisseur'].'<br>' ; } $sql = "SELECT * FROM Movies WHERE Jaar LIKE '%$zoekterm%'"; $resultaat = mysql_query ($sql); while ( $row = mysql_fetch_assoc($resultaat) ) { echo $row['Genre'] . " - " . $row['Naam'] . " - " . $row ['Jaar'] . " - " . $row ['Regisseur'].'<br>' ; } $sql = "SELECT * FROM Movies WHERE Regisseur LIKE '%$zoekterm%'"; $resultaat = mysql_query ($sql); while ( $row = mysql_fetch_assoc($resultaat) ) { echo $row['Genre'] . " - " . $row['Naam'] . " - " . $row ['Jaar'] . " - " . $row ['Regisseur'] .'<br>'; } ?> </div>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.