DS28
Q. 1) Write a PHP script using AJAX concept, to check user name and password are valid or Invalid (use
database to store user name and password). [Marks 15]
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL,
password VARCHAR(255) NOT NULL
);
$.ajax({
url: 'check_login.php',
method: 'POST',
data: {username: username, password: password},
success: function(response) {
$("#result").html(response);
}
});
});
});
</script>
// Create connection
servername, password, $dbname);
// Check connection
if (conn->connect_error) {
die("Connection failed: " . conn->connect_error);
}
_POST['username'];
_POST['password'];
username' AND password = 'result = sql);
if ($result->num_rows > 0) {
echo "<p style='color: green;'>Login successful. Username and password are valid.</p>";
} else {
echo "<p style='color: red;'>Login failed. Invalid username or password.</p>";
}
$conn->close();
?>
Q. 2 ) Build a simple linear regression model for Car Dataset
import pandas as pd
from sklearn.model_selection import train_test_split
from sklearn.linear_model import LinearRegression
from sklearn.metrics import mean_squared_error, r2_score
Assuming you have a CSV file named 'car_dataset.csv'
df = pd.read_csv('car_dataset.csv')
Display the first few rows of the dataset
print(df.head())
Select features (independent variables) and target variable (dependent variable)
X = df[['Feature1', 'Feature2', ...]] # Features
y = df['Price'] # Target variable
Split the data into training and testing sets
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)
Create a linear regression model
model = LinearRegression()
Train the model using the training sets
model.fit(X_train, y_train)
Make predictions on the testing set
y_pred = model.predict(X_test)
Calculate and print metrics
print('Mean Squared Error:', mean_squared_error(y_test, y_pred))
print('Coefficient of Determination (R^2):', r2_score(y_test, y_pred))
Example prediction
new_data = [[value1, value2, ...]] # Provide values for the features
predicted_price = model.predict(new_data)
print('Predicted Price:', predicted_price)