Jump to content

Arcadia

New Members
  • Posts

    5
  • Joined

  • Last visited

Arcadia's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I made a database in MySQL and made a database connection true php to show the data on the browser and it all works fine but the problem start when I only want show the top 10 highest score. I tried $result = mysql_query("SELECT top 10 ID, Naam, sum(Score) FROM Scores"); But it does not work it does really noting:( Below is my code. <?php $username = "root"; $password = ""; $hostname = "localhost"; //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); echo "Connected to MySQL<br>"; //select a database to work with $selected = mysql_select_db("Oefentoets1",$dbhandle) or die("Could not select examples"); //execute the SQL query and return records $result = mysql_query("SELECT ID, Naam, Score FROM Scores"); //fetch tha data from the database while ($row = mysql_fetch_array($result)) { echo "ID: ".$row{'ID'}. " Naam: ".$row{'Naam'}." Score: ". //display the results $row{'Score'}."<br>"; } //close the connection mysql_close($dbhandle); ?>
  2. Hello, I have a little problem with my php code an really hope someone can help me out here. I made a php code that show data when I fill in a form but my problem is it doesn't go further that the first two statements it also does not give a error message when a form field is not filled in:( So my main problem is that the last two ifelse statements do not work and it also does not give a error message when a form field is not filled in. I just started with php so really hope someone can help me out here with this stupid question <?php $Name = $_POST ['Name']; $Place = $_POST ['Place']; $Age = $_POST ['Age']; if (isset($_POST['Submit'])) { //Als men op de Submit knop heeft gedrukt van het formulier... if ($_POST['Name'] == "") { $error = "Name is not filled in.<BR />"; } if ($_POST['Age'] == "") { $error .= "Age is not filled in!<BR />"; } if ($_POST['place '] == "") { $error .= "Place is not filled in!"; } } if ($Age > 18) { echo "Hello $Name"; } elseif ($Age < 18) { echo "Hello little $Name"; } elseif ($Age< 18 && $Place == "New York") { echo "Living in: $Place"; } elseif ($Age > 18 && $Place == "New York") { echo "I love New York!!"; } ?>
  3. Hello everyone, I have a problem and really hope someone can help me out here I'm trying to insert data from a form in my MYSQL database and it connect to the database but when i try to submit the form i keep getting these two error messages: Notice: Undefined index: Naam in /Applications/XAMPP/xamppfiles/htdocs/Oefentoets1/Vraag4_Invoer.php on line 18 Notice: Undefined index: Score in /Applications/XAMPP/xamppfiles/htdocs/Oefentoets1/Vraag4_Invoer.php on line 19 I have the form and php code in one page I hope this is not a problem. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Vraag4_Invoer</title> <?php // Connect to the database $con = mysqli_connect("localhost","root","","Oefentoets1"); $naam = $_POST['Naam']; $score = $_POST['Score']; // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } $sql = "INSERT INTO Scores (Naam, Score) VALUES ('$naam', '$score')"; if ($con->query($sql) === TRUE) { echo "Thanks for signing up!"; } else { echo "Error: " . $sql . "<br>" . $con->error; } mysqli_close($con); ?> </head> <body> <form action="Vraag4_Invoer.php" method="post"> <label>Naam: </label><input name="Naam" type="text" /> <p> <label>Score: </label><input name="Score" type="text" /> <p> <input name="Submit" type="submit" /> </form> </body> </html>
  4. Hi everyone i'm having a problem with my login system and really hope someone can help me out here.. I made a login page and it's all working and it perfectly connect to my database but I also want the option when someone logins that they see a welcome message on each page on the website like "Welcome, $username" I searched on google but each time i pumb into errors I would like to show the "welcome message" in the header. Below you can see my code: Home.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <link rel="stylesheet" type="text/css" href="Design.css"> <title>Fotoalbum</title> <script src="http://maps.googleapis.com/maps/api/js"></script> <script> function initialize() { var mapProp = { center:new google.maps.LatLng(51.508742,-0.120850), zoom:5, mapTypeId:google.maps.MapTypeId.ROADMAP }; var map=new google.maps.Map(document.getElementById("googleMap"),mapProp); } google.maps.event.addDomListener(window, 'load', initialize); </script> </head> <body> <div id ="Wrapper"> <div id ="Logo"> <img src="Afbeeldingen/10881558_759342210782402_1567173209848574625_n.jpg" width="160" height="150" /> </div> <div id ="Header"> <center> <p> </p> <H1><p>CB </p></H1> </center> <a href="Main_login.php">Login</a> <a href="Logout.php">Logout</a> <ul> <li><a href="#">Home</a></li> <li><a href="#">Biografie</a></li> <li><a href="#">Fotoalbum</a></li> <li><a href="#">Contact</a></li> </ul> </center> </div> </body> </html> Main_LoginForm.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Main Login</title> </head> <body> <form action="Inlog.php" method="post"> <label>UserName :</label> <input type="text" name="Naam"/><br /> <label>Password :</label> <input type="password" name="Wachtwoord"/><br/> <p> <input type="submit" value=" Submit "/><br /> </form> </body> </html> Inlog.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php ob_start(); $host="localhost"; // Host name $username="root"; // Mysql username $password=""; // Mysql password $db_name="InlogFA"; // Database name $tbl_name="InlogFotoalbum"; // Table name // Connect to server and select databse. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // Define $myusername and $mypassword $myusername=$_POST['Naam']; $mypassword=$_POST['Wachtwoord']; // To protect MySQL injection (more detail about MySQL injection) $myusername = stripslashes($myusername); $mypassword = stripslashes($mypassword); $myusername = mysql_real_escape_string($myusername); $mypassword = mysql_real_escape_string($mypassword); $sql="SELECT * FROM $tbl_name WHERE Naam='$myusername' and Wachtwoord='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched $myusername and $mypassword, table row must be 1 row if($count==1){ // Register $myusername, $mypassword and redirect to file "login_success.php" $_SESSION['myusername']= "myusername"; $_SESSION['mypassword']= "mypassword"; header("Location: Login_success.php"); } else { echo "Wrong Username or Password"; } ob_end_flush(); ?> </body> </html> Login_succesful.php <?php session_start(); if(!$_SESSION['myusername']){ header("Location: Fotoalbum.php"); } ?> <body> Login Succesful! </body> </html>
×
×
  • 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.