I am trying to make a page that allows the user to enter the steps he will take to do a particular task. However, whenever I submit a step, multiple similar records get stored inside mysql database. So if i type "Do this", in my mysql database, two records will be stored with same data Here is my code...
<?php
$conn = new mysqli("localhost", "root","","KFC");
if(isset($_POST['Submit_btn']))
{
session_start();
$var_value = $_SESSION['R_ID'];
$Name= mysqli_real_escape_string($conn, $_POST['Step']);
$sql= "INSERT INTO `step`(`Step`, `R_ID`) VALUES ('$Name','$var_value')";
mysqli_query($conn,$sql);
if (!mysqli_query($conn,$sql))
{
echo("Error description: " . mysqli_error($conn));
}
}
mysqli_close($conn);
?>
<html>
<body>
<div id="bodyContent">
<h1> Submit Steps </h1>
</div>
<?php
mysql_connect('localhost', 'root', '');
mysql_select_db('garden');
$result = mysql_query("SELECT * FROM step WHERE R_ID='$var_value'");
$rows = mysql_num_rows($result);
echo "So far you have submitted " . $rows . " steps for your recipe.";
?>
<form method="post">
<table>
<tr>
<td>STEP: </td>
<td>
<textarea type="text" name="Step" class="textInput"></textarea>
</td>
</tr>
<tr>
<td> </td>
<td>
<input type="submit" name="Submit_btn" value="submit">
</td>
<td>
<input type="submit" name="Continue_btn" value="Continue">
</td>
</tr>
</table>
</form>
</body>
</html>