PHP: Difference between revisions

2,299 bytes added ,  6 years ago
Line 53:
$email = mysqli_real_escape_string($link, $_POST['email']);
$ProductionDown = $_POST['ProductionDown'];
</pre>
 
* Accessing DB:
<pre>
//Set database access credentials
$name = 'codered';
$user = 'test';
$password = 'test@123';
$host = 'localhost';
 
//Set table name
$tname = 'MasterDB';
 
/*Open the connection to our database use the info from the config file.*/
$link = mysqli_connect($host, $user, $password);
 
if (!$link) {
die('Could not connect: ' . mysqli_error($link));
}
mysqli_select_db($link, "codered") or die(mysqli_error($link));
</pre>
 
*Send input data to DB:
<pre>
$sql = "INSERT INTO MasterDB (sr, CustomerName, Geo, BusinessImpact, ProductVersion, ProblemDescription, CustomerTemp, BugID, LastUpdate, email, ProductionDown ) VALUES ('$sr', '$CustomerName', '$Geo', '$BusinessImpact', '$ProductVersion', '$ProblemDescription', '$CustomerTemp', '$BugID', '$LastUpdate','$email', '$ProductionDown')";
 
if (!mysqli_query($link, $sql)) {
die('Error ' . mysqli_error($link));
}
/*Redirect the user after a successful form submission*/
if ( !empty ( $redirect ) ) {
header("Location: $redirect?msg=1");
} else {
header("Location: $referred?msg=1");
}
 
mysqli_close($link);
</pre>
 
* Fetching Data from DB to Page:
<pre>
$sql = "SELECT * FROM MasterDB ORDER BY id DESC LIMIT 1";
 
$results = mysqli_query($link, $sql);
 
if (!$results) {
die('Invalid query: ' . mysqli_error($link));
}
 
echo '<h2>CodeRed Alert Generated with below Info:</h2>';
 
while($result = mysqli_fetch_array($results )){
echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">';
echo '<p>SR Number: ' . $result['sr'] . '</p>';
echo '<p>Customer Name: ' . $result['CustomerName'] . '</p>';
echo '<p>Country: ' . $result['Geo'] . '</p>';
echo '<p>Business Impact: ' . $result['BusinessImpact'] . '</p>';
echo '<p>Product Version: ' . $result['ProductVersion'] . '</p>';
echo '<p>Problem Description: ' . $result['ProblemDescription'] . '</p>';
echo '<p>Customer Temp: ' . $result['CustomerTemp'] . '</p>';
echo '<p>BugID: ' . $result['BugID'] . '</p>';
echo '<p>ProductionDown: ' . $result['ProductionDown'] . '</p>';
echo '<p>Last Update: ' . $result['LastUpdate'] . '</p>';
echo '<p>Engineers Email ID: ' . $result['email'] . '</p>';
echo '</div>';
}
</pre>