Create a Simple CRUD Database App: Connecting to MySQL with PHP

code example



<?php

error_reporting(0);
ini_set(display_errors, 1);
$servername='localhost' ; 
$database_name='myschool'; 
$database_username='root';
$database_password=''; 
mysql_connect($servername,$database_username,$database_password);
mysql_select_db($database_name);

if (count($_POST) > 0)
{
$subject = $_POST['subject'];
$out_of = $_POST['out_of'];
$passing_marks = $_POST['passing_marks'];
$obatained_marks = $_POST['obatained_marks'];
$condon = $_POST['condon'];
$obatained_marks_words = $_POST['obatained_marks_words'];
echo $subject . '<br>';
echo $out_of . '<br>';
echo $passing_marks . '<br>';
echo $obatained_marks . '<br>';
echo $condon . '<br>';
echo $obatained_marks_words . '<br>' ;
$sql = "INSERT INTO `myschool`.`marksheet` (`st_id`, `subject`, `out-of`, `passing-marks`, `obtined-marks`, `condon`, `obtined-marks-in-words`) VALUES (NULL, '$subject', '$out_of', '$passing_marks', '$obatained_marks', '', '$obatained_marks_words')";
$run_qry = mysql_query($sql);
$my_row = mysql_fetch_array($run_qry);


}
?>
<form method="post">
subject:<input name="subject" value="<?php echo $subject; ?>"></input><br>
out-of:<input name="out_of" value="<?php echo $out_of; ?>"></input><br>
passing-marks:<input name="passing_marks" value="<?php echo $passing_marks; ?>" ></input><br>
obatained-marks:<input name="obatained_marks" value="<?php echo $obatained_marks; ?>"></input><br>
condon:<input name="condon" value="<?php echo $condon; ?>" ></input><br>
obatained-marks-words:<input name="obatained_marks_words" value="<?php echo $obatained_marks_words; ?>"></input><br>
<input type=submit></input>

</form>

No comments

Note: only a member of this blog may post a comment.