2017-09-14 1 views
1

데이터베이스의 레코드를 업데이트하는이 양식이 있습니다. 10 진수를 입력해야하는데, 작업을 수행하고 데이터베이스를 업데이트합니다. 문제는 단지 정수만 읽는다는 것입니다.데이터베이스에 십진수를 설정했지만 정수만 읽습니다.

예 :

2.35 (업데이트 된 값이됩니다 2)

나는 또한 내 데이터베이스에 진수로 sickleave 및 vacationleave의 종류를 설정 않았다

. 무엇이 문제일까요? 내가 잘못하고 있니? 당신은 i를 사용하여 integers으로 숫자를 바인딩이 너무 바닥 그들된다

<?php 
 
/* 
 
Allows the user to both create new records and edit existing records 
 
*/ 
 

 
// connect to the database 
 
include("connect-db.php"); 
 

 
// creates the new/edit record form 
 
// since this form is used multiple times in this file, I have made it a function that is easily reusable 
 
function renderForm($fullname = '', $username ='', $error = '', $id = '', $email = '', $address = '', $contact = '', $gender = '', $password = '', $user_levels = '', $date = '', $picture = '', $sickleave = '', $vacationleave = '') 
 
{ ?> 
 
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
 
<html> 
 
<head> 
 

 
\t <link href="https://fonts.googleapis.com/css?family=Questrial" rel="stylesheet"> 
 

 
<style> 
 

 
\t body { 
 
\t \t background-image: url("img/wood2.jpg"); 
 
\t } 
 
\t 
 
\t html { 
 
\t \t font-family: Questrial; 
 
\t } 
 
\t 
 
\t .main > div { 
 
\t \t position: center; 
 
\t } 
 

 
\t .register { 
 
\t width: 500px; 
 
\t margin: 10px auto; 
 
\t padding: 10px; 
 
\t border: 7px solid #285f9f; 
 
\t border-radius: 10px; 
 
\t font-family: Questrial; 
 
\t color: #444; 
 
\t background-color: #F0F0F0; 
 
\t box-shadow: 0 0 20px 0 #000000; 
 
\t } 
 
\t .register h3 { 
 
\t margin: 0 15px 20px; 
 
\t border-bottom: 2px solid #285f9f; 
 
\t padding: 5px 10px 5px 0; 
 
\t font-size: 1.1em; 
 
\t } 
 
\t .register div { 
 
\t margin: 0 0 15px 0; 
 
\t border: none; 
 
\t } 
 
\t .register label { 
 
\t display: inline-block; 
 
\t width: 25%; 
 
\t text-align: right; 
 
\t margin: 10px; 
 
\t } 
 
\t .register input[type=text], .register input[type=password] { 
 
\t width: 65%; 
 
\t font-family: "Lucida Grande", "Lucida Sans Unicode", Tahoma, Sans-Serif; 
 
\t padding: 5px; 
 
\t font-size: 0.9em; 
 
\t border-radius: 5px; 
 
\t background: rgba(0, 0, 0, 0.07); 
 
\t } 
 
\t .register input[type=text]:focus, .register input[type=password]:focus { 
 
\t background: #FFFFFF; 
 
\t } 
 
\t .register .button { 
 
\t font-size: 1em; 
 
\t font-family: Questrial; 
 
\t border-radius: 8px; 
 
\t padding: 10px; 
 
\t border: 1px solid #285f9f; 
 
\t background: #285f9f; 
 
\t 
 
\t } 
 
\t .register .button:hover { 
 
\t background: #51DB1C; 
 
\t background: -webkit-linear-gradient(#51DB1C, #6BA061); 
 
\t background: -moz-linear-gradient(#51DB1C, #6BA061); 
 
\t background: -o-linear-gradient(#51DB1C, #6BA061); 
 
\t background: linear-gradient(#51db1c, #6ba061); 
 
\t } 
 
\t .register .sep { 
 
\t border: 1px solid #72B372; 
 
\t position: relative; 
 
\t margin: 35px 20px; 
 
\t } 
 
\t .register .or { 
 
\t position: absolute; 
 
\t width: 50px; 
 
\t left: 50%; 
 
\t background: #F0F0F0; 
 
\t text-align: center; 
 
\t margin: -10px 0 0 -25px; 
 
\t line-height: 20px; 
 
\t } 
 
\t .register .connect { 
 
\t width: 400px; 
 
\t margin: 0 auto; 
 
\t text-align: center; 
 
\t } 
 
\t 
 
</style> 
 

 
<title> <?php if ($id != '') { echo "Edit Record"; } else { echo "New Record"; } ?> </title> 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> 
 

 
</head> 
 
<body> 
 

 
\t <?php if ($error != '') { 
 
\t echo "<div style='padding:4px; border:1px solid red; color:red'>" . $error 
 
\t . "</div>"; 
 
\t } ?> 
 

 
<div class="main"> 
 
\t <div class="one"> 
 
    <div class="register"> 
 
     <center><h3>Edit Account #</h3></center> 
 
     <form action="" method="post"> 
 
\t \t <div> 
 
      <label>ID</label> 
 
\t \t <?php if ($id != '') { ?> 
 
\t \t <?php echo $id;?> 
 
      <input type="hidden" name="id" value="<?php echo $id;?>"> 
 
\t \t <?php } ?> 
 
     </div> 
 
     <div> 
 
      <label>Fullname</label> 
 
      <input type="text" name="fullname" value="<?php echo $fullname;?>"> 
 
     </div> 
 
     <div> 
 
      <label>Email</label> 
 
      <input type="text" name="email" value="<?php echo $email; ?>"> 
 
     </div> 
 
     <div> 
 
      <label>Username</label> 
 
      <input type="text" name="username" value="<?php echo $username; ?>"> 
 
     </div> 
 
     <div> 
 
      <label>Password</label> 
 
      <input type="password" name="password" value="<?php echo $password; ?>"> 
 
     </div> 
 
     <div> 
 
      <label>Address</label> 
 
      <input type="text" name="address" value="<?php echo $address; ?>"> 
 
     </div> 
 
\t \t <div> 
 
      <label>Contact</label> 
 
      <input type="text" name="contact" value="<?php echo $contact; ?>"> 
 
     </div> 
 
\t \t <div> 
 
      <label>Gender</label> 
 
      <input type="text" name="gender" value="<?php echo $gender; ?>"> 
 
     </div> 
 
\t \t <div> 
 
      <label>User Levels</label> 
 
      <input type="text" name="user_levels" value="<?php echo $user_levels; ?>"> 
 
     </div> 
 
\t \t <div> 
 
      <label>Date</label> 
 
      <input type="text" name="date" value="<?php echo $date; ?>"> 
 
     </div> 
 
\t \t <div> 
 
      <label>Picture</label> 
 
      <?php echo $picture; ?> 
 
     </div> 
 
\t \t <div> 
 
      <label>Sick Leave</label> 
 
      <input type="text" name="sickleave" value="<?php echo $sickleave; ?>"> 
 
     </div> 
 
\t \t <div> 
 
      <label>Vacation Leave</label> 
 
      <input type="text" name="vacationleave" value="<?php echo $vacationleave; ?>"> 
 
     </div> 
 
     <div> 
 
      <label></label> 
 
\t \t <input type="submit" name="submit" value="Save Changes" class="button" /> 
 
\t \t <a href="view.php"><input type="button" value="View Records" class="button" /> 
 
     </div> 
 
     </form> 
 
    </div> 
 
    </div> 
 
\t 
 
</body> 
 
</html> 
 

 
<?php } 
 

 
/* EDIT RECORD */ 
 
// if the 'id' variable is set in the URL, we know that we need to edit a record 
 
if (isset($_GET['id'])) 
 
{ 
 
// if the form's submit button is clicked, we need to process the form 
 
if (isset($_POST['submit'])) 
 
{ 
 
// make sure the 'id' in the URL is valid 
 
if (is_numeric($_POST['id'])) 
 
{ 
 
// get variables from the URL/form 
 
\t $id = $_POST['id']; 
 
\t $fullname = htmlentities($_POST['fullname'], ENT_QUOTES); 
 
\t $username = htmlentities($_POST['username'], ENT_QUOTES); 
 
\t $email = htmlentities($_POST['email'], ENT_QUOTES); 
 
\t $address = htmlentities($_POST['address'], ENT_QUOTES); 
 
\t $contact = htmlentities($_POST['contact'], ENT_QUOTES); 
 
\t $gender = htmlentities($_POST['gender'], ENT_QUOTES); 
 
\t $password = htmlentities($_POST['password'], ENT_QUOTES); 
 
\t $user_levels = htmlentities($_POST['user_levels'], ENT_QUOTES); 
 
\t $date = htmlentities($_POST['date'], ENT_QUOTES); 
 
\t $picture = htmlentities($_POST['picture'], ENT_QUOTES); 
 
\t $sickleave = htmlentities($_POST['sickleave'], ENT_QUOTES); 
 
\t $vacationleave = htmlentities($_POST['vacationleave'], ENT_QUOTES); 
 

 
// check that firstname and lastname are both not empty 
 
if ($fullname == '' || $username == '' || $email == '' || $address == '') 
 
{ 
 
// if they are empty, show an error message and display the form 
 
\t $error = 'ERROR: Please fill in all required fields!'; 
 
\t renderForm($fullname, $username, $error, $id, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave); 
 
} 
 
else 
 
{ 
 
// if everything is fine, update the record in the database 
 
if ($stmt = $mysqli->prepare("UPDATE signup_and_login_users_table SET fullname = ?, username = ?, email = ?, 
 
address = ?, 
 
contact = ?, 
 
gender = ?, 
 
password = ?, 
 
user_levels = ?, 
 
date = ?, 
 
picture = ?, 
 
sickleave = ?, 
 
vacationleave = ? 
 
WHERE id = ?")) 
 
{ 
 
    $stmt->bind_param("ssssssssssiii", $fullname, $username, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave, $id); 
 
    $stmt->execute(); 
 
    $stmt->close(); 
 
} 
 
// show an error message if the query has an error 
 
else 
 
{ 
 
echo "ERROR: could not prepare SQL statement."; 
 
} 
 

 
// redirect the user once the form is updated 
 
header("Location: view.php"); 
 
} 
 
} 
 
// if the 'id' variable is not valid, show an error message 
 
else 
 
{ 
 
echo "Error!"; 
 
} 
 
} 
 
// if the form hasn't been submitted yet, get the info from the database and show the form 
 
else 
 
{ 
 
// make sure the 'id' value is valid 
 
if (is_numeric($_GET['id']) && $_GET['id'] > 0) 
 
{ 
 
// get 'id' from URL 
 
\t $id = $_GET['id']; 
 

 
// get the recod from the database 
 
if($stmt = $mysqli->prepare("SELECT * FROM signup_and_login_users_table WHERE id=?")) 
 
{ 
 
\t $stmt->bind_param("i", $id); 
 
\t $stmt->execute(); 
 

 
\t $stmt->bind_result($id, $fullname, $username, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave); 
 
\t $stmt->fetch(); 
 

 
// show the form 
 
renderForm($fullname, $username, NULL, $id, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave); 
 

 
$stmt->close(); 
 
} 
 
// show an error if the query has an error 
 
else 
 
{ 
 
\t echo "Error: could not prepare SQL statement"; 
 
} 
 
} 
 
// if the 'id' value is not valid, redirect the user back to the view.php page 
 
else 
 
{ 
 
\t header("Location: view.php"); 
 
} 
 
} 
 
} 
 

 

 

 
/* 
 

 
NEW RECORD 
 

 
*/ 
 
// if the 'id' variable is not set in the URL, we must be creating a new record 
 
else 
 
{ 
 
// if the form's submit button is clicked, we need to process the form 
 
if (isset($_POST['submit'])) 
 
{ 
 
// get the form data 
 
\t $fullname = htmlentities($_POST['fullname'], ENT_QUOTES); 
 
\t $username = htmlentities($_POST['username'], ENT_QUOTES); 
 
\t $email = htmlentities($_POST['email'], ENT_QUOTES); 
 
\t $address = htmlentities($_POST['address'], ENT_QUOTES); 
 
\t $contact = htmlentities($_POST['contact'], ENT_QUOTES); 
 
\t $gender = htmlentities($_POST['gender'], ENT_QUOTES); 
 
\t $password = htmlentities($_POST['password'], ENT_QUOTES); 
 
\t $user_levels = htmlentities($_POST['user_levels'], ENT_QUOTES); 
 
\t $date = htmlentities($_POST['date'], ENT_QUOTES); 
 
\t $picture = htmlentities($_POST['picture'], ENT_QUOTES); 
 
\t $sickleave = htmlentities($_POST['sickleave'], ENT_QUOTES); 
 
\t $vacationleave = htmlentities($_POST['vacationleave'], ENT_QUOTES); 
 

 
// check that firstname and lastname are both not empty 
 
if ($fullname == '' || $username == '' || $email == '' || $address == '') 
 
{ 
 
// if they are empty, show an error message and display the form 
 
$error = 'ERROR: Please fill in all required fields!'; 
 
renderForm($fullname, $username, $error, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave); 
 
} 
 
else 
 
{ 
 
// insert the new record into the database 
 
if ($stmt = $mysqli->prepare("INSERT signup_and_login_users_table (fullname, username, email, address, contact, gender, password, user_levels, date, picture, sickleave, vacationleave) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) 
 
{ 
 
$stmt->bind_param("ssssssssssiii", $fullname, $username, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave, $id); 
 
$stmt->execute(); 
 
$stmt->close(); 
 
} 
 
// show an error if the query has an error 
 
else 
 
{ 
 
echo "ERROR: Could not prepare SQL statement."; 
 
} 
 

 
// redirec the user 
 
header("Location: view.php"); 
 
} 
 

 
} 
 
// if the form hasn't been submitted yet, show the form 
 
else 
 
{ 
 
renderForm(); 
 
} 
 
} 
 

 
// close the mysqli connection 
 
$mysqli->close(); 
 
?>

Table Schema

+0

에만 관련 코드하시기 바랍니다 보여 사용해 볼 수 있습니까? – CarlosCarucce

+0

테이블 스키마는 여기에서 매우 유용 할 것입니다 ... – ThoriumBR

+0

@ThoriumBR이 테이블 스키마를 추가했습니다 –

답변

1

:

여기 내 코드입니다. 그것은 소수를 유지 있도록 d과 복식을 결합하십시오 :

$stmt->bind_param("ssssssssssddi", $fullname, $username, $email, $address, $contact, $gender, $password, $user_levels, $date, $picture, $sickleave, $vacationleave, $id); 

는 또한,이 데이터 유형으로 DECIMAL(11, 0) 있습니다. 두 번째 숫자가 0이면 소수점이 0 개임을 의미합니다. sickleavevacationleave ~ DECIMAL(11, 2)을 2 소수점을 저장하도록 설정하십시오.

+0

작동하지 않습니다 :(내 데이터베이스 유형도 두 배로 증가합니까? –

+1

테이블 스키마를 원본 게시물에 추가하여 볼 수 있습니다. – ishegg

+0

테이블 스키마가 추가되었습니다. –