Fail la conectare PHP cu baza de date
Scris: Joi Noi 21, 2019 5:30 pm
Buna ziua, am si eu de facut un website - la partea de design e ok, dar am probleme la partea cu PHP si MySQL.
Vreau sa fac celebrul sistem login si nu reusesc. Am cumparat un host si un domain si cand accesez situ-ul la sectiunea de login nu se intampla nimic cand apas pe "SUBMIT".
las aici codul poate ma poate sfatui cineva .
Va multumesc!!!
************************************************************************************************
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Bogdan University</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
</head>
<body>
<div class="containter">
<header><!-- here start the header -->
<div class="header-logo">
<img src="img/logo-university.png" alt="logo of university of Bogdan">
</div>
<div class="header-name">
<h1>UNIVERSITY OF BOGDAN</h1>
</div>
<div class="header-social">
<a class="btn" href="https://www.facebook.com">
<i class="fab fa-facebook"></i>
</a>
<a class="btn" href="https://twitter.com">
<i class="fab fa-twitter"></i>
</a>
<a class="btn" href="https://www.linkedin.com">
<i class="fab fa-linkedin"></i>
</a>
<a class="btn" href="https://www.youtube.com">
<i class="fab fa-youtube"></i>
</a>
</div>
</header><!-- here ends the header -->
<nav><!-- here starts the navigation menu -->
<div class="nav-menu">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="courses.html">COURSES</a>
<div class="sub-menu">
<ul>
<li><a href="courses-undergraduated.html">UNDERGRADUATE</a></li>
<li><a href="courses-postgraduated.html">POSTGRADUATE</a></li>
</ul>
</div>
</li>
<li><a href="registration.html">REGISTRATION</a></li>
<li><a href="about.html">ABOUT</a>
<div class="sub-menu">
<ul>
<li><a href="about-why-BU.html">WHY BOGDAN UNI?</a></li>
<li><a href="about-accomodation.html">ACCOMMODATION</a></li>
<li><a href="about-student-fees.html">STUDENT FEES</a></li>
</ul>
</div>
</li>
<li><a href="contact.html">CONTACT</a></li>
<li class="active"><a href="access.html">LOGIN</a></li>
</ul>
</div>
</nav><!-- here ends the nav menu -->
<!-- here stats the main -->
<main>
<div class="login-box">
<div class="login-field">
<select name="username" id="Type-of-user">
<option value="-1">User type</option>
<option value="Admin">Admin</option>
<option value="Student">Student</option>
<option value="Lecturer">Lecturer</option>
</select>
<!-- <input type="text" placeholder="Type of User"> -->
</div>
<div class="login-field">
<input type="text" name="username" placeholder="Username">
</div>
<div class="login-field">
<input type="password" name="pwd" placeholder="Password">
</div>
<div class="login-field-submit">
<input type="submit" name="submit" value="Submit">
</div>
</div>
</main>
<!-- here end the main -->
<!-- here starts footer -->
<footer>
<div class="address">
<p>University of Bogdan || Radcliffe Sq, Oxford OX1 3BG || 01865 277162 || contact@universityofbogdan.ac.uk </p>
</div>
<div class="footer-botttom">
<p><a href="#">Privacy Policy</a> || <a href="#">Site Map</a> ||<a href="#">Ⓒ Copyright by Bogdan Halinga</a></p>
</div>
</footer>
<!-- here ends footer -->
</div>
</body>
</html>
<?php
$con=mysql_connect('localhost:3306','ogdfios_admin','admin','bogdfios_University_of_Bogdan');
if(!$con)
{
echo"Unable to establish connection!" .mysql_error();
}
$db=mysql_select_db("bogdfios_University_of_Bogdan",$con);
if(!$db)
{
echo"Database not found!!!" .mysql_error();
}
if(isset($_POST['submit']))
{
$type=$_POST['type'];
$username=$_POST['username'];
$password=$_POST['pwd'];
$query="select * from login where username='$username' and password='$password'and type='$type' ";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
if($row['username']==$username && $row['password']==$password &&$row['type']=='Admin'){
header("Location: admin.html");
}
elseif($row['username']==$username && $row['password']==$password &&$row['type']=='Student'){
header("Location: student.html");
}
elseif($row['username']==$username && $row['password']==$password &&$row['type']=='Lecturer'){
header("Location: lecturer.html");
}
}
}
?>
************************************************************************************************
Vreau sa fac celebrul sistem login si nu reusesc. Am cumparat un host si un domain si cand accesez situ-ul la sectiunea de login nu se intampla nimic cand apas pe "SUBMIT".
las aici codul poate ma poate sfatui cineva .
Va multumesc!!!
************************************************************************************************
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Bogdan University</title>
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.4.1/css/all.css">
</head>
<body>
<div class="containter">
<header><!-- here start the header -->
<div class="header-logo">
<img src="img/logo-university.png" alt="logo of university of Bogdan">
</div>
<div class="header-name">
<h1>UNIVERSITY OF BOGDAN</h1>
</div>
<div class="header-social">
<a class="btn" href="https://www.facebook.com">
<i class="fab fa-facebook"></i>
</a>
<a class="btn" href="https://twitter.com">
<i class="fab fa-twitter"></i>
</a>
<a class="btn" href="https://www.linkedin.com">
<i class="fab fa-linkedin"></i>
</a>
<a class="btn" href="https://www.youtube.com">
<i class="fab fa-youtube"></i>
</a>
</div>
</header><!-- here ends the header -->
<nav><!-- here starts the navigation menu -->
<div class="nav-menu">
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="courses.html">COURSES</a>
<div class="sub-menu">
<ul>
<li><a href="courses-undergraduated.html">UNDERGRADUATE</a></li>
<li><a href="courses-postgraduated.html">POSTGRADUATE</a></li>
</ul>
</div>
</li>
<li><a href="registration.html">REGISTRATION</a></li>
<li><a href="about.html">ABOUT</a>
<div class="sub-menu">
<ul>
<li><a href="about-why-BU.html">WHY BOGDAN UNI?</a></li>
<li><a href="about-accomodation.html">ACCOMMODATION</a></li>
<li><a href="about-student-fees.html">STUDENT FEES</a></li>
</ul>
</div>
</li>
<li><a href="contact.html">CONTACT</a></li>
<li class="active"><a href="access.html">LOGIN</a></li>
</ul>
</div>
</nav><!-- here ends the nav menu -->
<!-- here stats the main -->
<main>
<div class="login-box">
<div class="login-field">
<select name="username" id="Type-of-user">
<option value="-1">User type</option>
<option value="Admin">Admin</option>
<option value="Student">Student</option>
<option value="Lecturer">Lecturer</option>
</select>
<!-- <input type="text" placeholder="Type of User"> -->
</div>
<div class="login-field">
<input type="text" name="username" placeholder="Username">
</div>
<div class="login-field">
<input type="password" name="pwd" placeholder="Password">
</div>
<div class="login-field-submit">
<input type="submit" name="submit" value="Submit">
</div>
</div>
</main>
<!-- here end the main -->
<!-- here starts footer -->
<footer>
<div class="address">
<p>University of Bogdan || Radcliffe Sq, Oxford OX1 3BG || 01865 277162 || contact@universityofbogdan.ac.uk </p>
</div>
<div class="footer-botttom">
<p><a href="#">Privacy Policy</a> || <a href="#">Site Map</a> ||<a href="#">Ⓒ Copyright by Bogdan Halinga</a></p>
</div>
</footer>
<!-- here ends footer -->
</div>
</body>
</html>
<?php
$con=mysql_connect('localhost:3306','ogdfios_admin','admin','bogdfios_University_of_Bogdan');
if(!$con)
{
echo"Unable to establish connection!" .mysql_error();
}
$db=mysql_select_db("bogdfios_University_of_Bogdan",$con);
if(!$db)
{
echo"Database not found!!!" .mysql_error();
}
if(isset($_POST['submit']))
{
$type=$_POST['type'];
$username=$_POST['username'];
$password=$_POST['pwd'];
$query="select * from login where username='$username' and password='$password'and type='$type' ";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{
if($row['username']==$username && $row['password']==$password &&$row['type']=='Admin'){
header("Location: admin.html");
}
elseif($row['username']==$username && $row['password']==$password &&$row['type']=='Student'){
header("Location: student.html");
}
elseif($row['username']==$username && $row['password']==$password &&$row['type']=='Lecturer'){
header("Location: lecturer.html");
}
}
}
?>
************************************************************************************************