Quantcast
Viewing all articles
Browse latest Browse all 85594

Re: Server Behavior & Database extension keeps re-downloading

AdobeLover wrote:

 

osgood,

I would love to see an image of your simplified code if possible!!   I've basically created a login form, that logs into a MySQL database on GoDaddy.  I have the "RecordSet" (which contains the login info for the MySQL server) and the "Log In" behavior coming from the Server Behaviors & Database extension.  You are correct by saying when Dreamweaver applies that code to the PHP page, it is nearly impossible to read and decipher.

 

The below mysqli code selects the 'username' and 'password' columns from a database table named 'users' and checks they are correct. If they are the user is logged in and gets redirected to a specific page.

 

The connection string to the database (where the XXXXX's are) will need amending to your own connection details - server-name, username, password and database name.

 

If you want to test it just copy all the code and paste it into a new DW file and save it as login.php (assuming your database 'users' table is set up correctly with the 'username and password' columns and the connection details to the database is correct it should work IF your server can use mysqli)

 

 

<?php  session_start() ?>

<?php

// connect to database

$conn = new mysqli('XXXXXXXX' , 'XXXXXXX' , 'XXXXXXXX' , 'XXXXXXXXX'); ?>

<?php

// Query database for username and password

if(isset($_POST['submit'])) {

$username = trim($_POST['username']);

$sql = 'SELECT * FROM users';

$result = $conn->query($sql) or die($conn->error);

while ($row = $result->fetch_assoc()) {

if ($row['username'] == $username && $row['password'] == trim($_POST['password'])) {

$_SESSION['username'] = $username;

// Redirect to specific page if login successful

header('Location: http://www.bbc.co.uk');

}

else {

$response = "Sorry you do not have permission to access this website";

}

}

}

?>

<!DOCTYPE html>

<head>

<meta charset="UTF-8" />

<title>Security Login</title>

</head>

<body>

<?php

if(isset($response)) {

echo $response;

}

?>

 

<form id="form1" name="form1" method="post" action="login.php">

<label>Username</label><br />

<input type="text" name="username" id="username" value=""/><br />

<label>Password</label><br />

<input type="text" name="password" id="password" value=""/><br />

<input type="submit" name="submit" id="submit" value="Submit" />

</form>

</body>

</html>


Viewing all articles
Browse latest Browse all 85594

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>