Hello all!
i have here a code that will save the inputs in my database. but 'save' button doesnt work. please help. here is the code for the save button
<?php
define ('DB_NAME', 'try1');
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$value1 = $_POST["lname"];
$value2 = $_POST["fname"];
$value3 = $_POST["hour1"];
$value4 = $_POST["min1"];
$value5 = $_POST["hour2"];
$value6 = $_POST["min2"];
$value7 = $_POST["leave"];
$value8 = $_POST["comments"];
$value9 = $_POST["sf"];
$value10= $_POST["rf"];
$value11 = $_POST["total"];
$value12 = $_POST["sp"];
$value13 = $_POST["rp"];
$sql = "INSERT INTO record (lname, fname, hour1, min1, hour2, min2, leave, comments, sf, rf, total, sp, rp)
VALUES ('$value1', '$value2', '$value3', '$value4', '$value5', '$value6', '$value7', '$value8', '$value9', '$value10', '$value11', '$value12', '$value13')";
if (!mysql_query($sql)) {
die('Error: ' . mysql_error());
}
echo 'added!';
mysql_close();
?>
and here is the code for my form
<html>
<head>
<title>Record</title>
</head>
<body>
<form action="saverec.php" method="post">
<?php
define ('DB_NAME', 'try1');
define ('DB_USER', 'root');
define ('DB_PASSWORD', '');
define ('DB_HOST', 'localhost');
$link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db(DB_NAME, $link);
if (!$db_selected) {
die('Can\'t use ' . DB_NAME . ': ' . mysql_error());
}
$strSQL = "SELECT * FROM employee ORDER BY lname";
// Execute the query (the recordset $rs contains the result)
$rs = mysql_query($strSQL);
?>
<table border="1">
<tr>
<th>Name: </th>
</tr>
<tr>
<th>Practice: </th>
</tr>
<tr>
<th>Project Name: </th>
</tr>
<tr>
<th></th><th>Time Message sent</th><th>Time Replied</th><th>On leave?</th><th>Comments</th>
</tr>
<tr>
<th>Employee Name</th><th>HH:MM</th><th>HH:MM</th>
</tr>
<?php
// Loop the recordset $rs
while($row = mysql_fetch_array($rs)) {
?>
<tr>
<td><?php echo $row['lname'] . ", " . $row['fname'] ?></td>
<td>
<select name="hour1">
<option value =""></option>
<option value ="1">01</option>
<option value ="2">02</option>
<option value ="3">03</option>
<option value ="4">04</option>
<option value ="5">05</option>
<option value ="6">06</option>
<option value ="7">07</option>
<option value ="8">08</option>
<option value ="9">09</option>
<option value ="10">10</option>
<option value ="11">11</option>
<option value ="12">12</option>
</select>
<select name="min1">
<option value =""></option>
<option value ="1">00</option>
<option value ="1">01</option>
<option value ="2">02</option>
<option value ="3">03</option>
<option value ="4">04</option>
<option value ="5">05</option>
<option value ="6">06</option>
<option value ="7">07</option>
<option value ="8">08</option>
<option value ="9">09</option>
<option value ="10">10</option>
<option value ="11">11</option>
<option value ="12">12</option>
<option value ="13">13</option>
<option value ="14">14</option>
<option value ="15">15</option>
<option value ="16">16</option>
<option value ="17">17</option>
<option value ="18">18</option>
<option value ="19">19</option>
<option value ="20">20</option>
<option value ="21">21</option>
<option value ="22">22</option>
<option value ="23">23</option>
<option value ="24">24</option>
<option value ="25">25</option>
<option value ="26">26</option>
<option value ="27">27</option>
<option value ="28">28</option>
<option value ="29">29</option>
<option value ="30">30</option>
<option value ="31">31</option>
<option value ="32">32</option>
<option value ="33">33</option>
<option value ="34">34</option>
<option value ="35">35</option>
<option value ="36">36</option>
<option value ="37">37</option>
<option value ="38">38</option>
<option value ="39">39</option>
<option value ="40">40</option>
<option value ="41">41</option>
<option value ="42">42</option>
<option value ="43">43</option>
<option value ="44">44</option>
<option value ="45">45</option>
<option value ="46">46</option>
<option value ="47">47</option>
<option value ="48">48</option>
<option value ="49">49</option>
<option value ="50">50</option>
<option value ="51">51</option>
<option value ="52">52</option>
<option value ="53">53</option>
<option value ="54">54</option>
<option value ="55">55</option>
<option value ="56">56</option>
<option value ="57">57</option>
<option value ="58">58</option>
<option value ="59">59</option>
</select>
<select name="ampm">
<option value =""></option>
<option value ="am">AM</option>
<option value ="pm">PM</option>
</select>
</td>
<td>
<select name="hour2">
<option value =""></option>
<option value ="1">01</option>
<option value ="2">02</option>
<option value ="3">03</option>
<option value ="4">04</option>
<option value ="5">05</option>
<option value ="6">06</option>
<option value ="7">07</option>
<option value ="8">08</option>
<option value ="9">09</option>
<option value ="10">10</option>
<option value ="11">11</option>
<option value ="12">12</option>
</select>
<select name="min2">
<option value =""></option>
<option value ="0">00</option>
<option value ="1">01</option>
<option value ="2">02</option>
<option value ="3">03</option>
<option value ="4">04</option>
<option value ="5">05</option>
<option value ="6">06</option>
<option value ="7">07</option>
<option value ="8">08</option>
<option value ="9">09</option>
<option value ="10">10</option>
<option value ="11">11</option>
<option value ="12">12</option>
<option value ="13">13</option>
<option value ="14">14</option>
<option value ="15">15</option>
<option value ="16">16</option>
<option value ="17">17</option>
<option value ="18">18</option>
<option value ="19">19</option>
<option value ="20">20</option>
<option value ="21">21</option>
<option value ="22">22</option>
<option value ="23">23</option>
<option value ="24">24</option>
<option value ="25">25</option>
<option value ="26">26</option>
<option value ="27">27</option>
<option value ="28">28</option>
<option value ="29">29</option>
<option value ="30">30</option>
<option value ="31">31</option>
<option value ="32">32</option>
<option value ="33">33</option>
<option value ="34">34</option>
<option value ="35">35</option>
<option value ="36">36</option>
<option value ="37">37</option>
<option value ="38">38</option>
<option value ="39">39</option>
<option value ="40">40</option>
<option value ="41">41</option>
<option value ="42">42</option>
<option value ="43">43</option>
<option value ="44">44</option>
<option value ="45">45</option>
<option value ="46">46</option>
<option value ="47">47</option>
<option value ="48">48</option>
<option value ="49">49</option>
<option value ="50">50</option>
<option value ="51">51</option>
<option value ="52">52</option>
<option value ="53">53</option>
<option value ="54">54</option>
<option value ="55">55</option>
<option value ="56">56</option>
<option value ="57">57</option>
<option value ="58">58</option>
<option value ="59">59</option>
</select>
<select name="ampm1">
<option value =""></option>
<option value ="am">AM</option>
<option value ="pm">PM</option>
</select>
</td>
<td>
<select name="leave">
<option value =""></option>
<option value ="Yes">Yes</option>
<option value ="No">No</option>
</td>
</select>
<td>
<input type="text" name="comments" />
</td>
</tr>
<?php
}
?>
</table>
<table>
<tr>
<th>Call tree successful? </th>
</tr>
<tr>
<th>Sending failed</th>
<td>
<input type="text" size="3" name="sf" />
</td>
<th>Receiving failed</th>
<td>
<input type="text" size="3" name="rf" />
</td>
<th>Total</th>
<td>
<input type="text" size="3" name="total" />
</td>
<th>Sending percentage</th>
<td>
<input type="text" size="3" name="sp" />
</td>
<th>Receiving percentage</th>
<td>
<input type="text" size="3" name="rp" />
</td>
</tr>
</table>
<?php mysql_close(); ?>
<input type="submit" name="Submit" value="Save" >
</form>
</body>
</html>
when i hit save button, the page just refreshes.