Hello, I’ve searched the forum and I couldn’t find and answer that i could understand. I’m trying to do a form with lots of text, checkboxes, and a comment box at the end of each text.
And i want individuals to save their progress while they complete this huge form, so I’ve added a save/submit button also at the end of each text so they dont loose progress. Also and echo with the value they inputed in each text.
I’m really new into coding in general but i just liked php as soon as I started trying to understand it.
Here is my code its a one page php:
<?php
include_once 'connect4.php';
$sql_read = 'SELECT * FROM document1';
$gsent = $pdo->prepare($sql_read);
$gsent->execute();
$result = $gsent->fetchall();
//var_dump($result);
if (isset($_POST['post1'])){
$email = $_POST['email'];
$select01 = $_POST['select01'];
$comment01 = $_POST['comment01'];
$sql_read = 'INSERT INTO document1 (email,select01,comment01) VALUES (?,?,?)';
$sentence_add = $pdo->prepare($sql_read);
$sentence_add->execute(array($email,$select01,$comment01));
header('location:document-1.php');
}
if (isset($_POST['post2'])){
$select02 = $_POST['select02'];
$comment02 = $_POST['comment02'];
$sql_read = 'INSERT INTO document1 (select02,comment02) VALUES (?,?)';
$sentence_add = $pdo->prepare($sql_read);
$sentence_add->execute(array($select02,$comment02));
header('location:document-1.php');
}
?>
<html>
<head>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">
</head>
<body>
lots of text, text, more text, more text, more text, more text.....
<form method="post">
<input type="email" placeholder="Email" name="email" required/>
<div class="col md-6">
<input type="radio" name="select01" value="Accepted" checked>
<label for="huey">Accept</label><br>
<input type="radio" name="select01" value="">
<label for="huey">Reject</label>
<br><br>
<textarea name="comment01" rows="5" cols="75" placeholder="Comment . . . "></textarea><br>
<input type="submit" name="post1" value="Save Answers"/>
<br>
</form>
</div>
<div class="col-md-6">
<?php foreach($result as $data); ?>
<div class="alert alert-success" role="alert">
Answer: <?php echo '<b>  Checkbox : </b>', $data['select01'];
echo '<b>  Comment : </b>', $data['comment01']; ?>
</div>
</div>
lots of text, text, more text, more text, more text, more text.....
<form method="post" name="form2">
<input type="radio" name="select02" value="Accepted" checked>
<label for="huey">Accept</label><br>
<input type="radio" name="select02" value="">
<label for="huey">Reject</label>
<br><br>
<textarea name="comment02" rows="5" cols="75" placeholder="Comment . . . "></textarea><br>
<input type="submit" name="post2" value="Save Answers"/>
<br>
</form>
</div>
<div class="col-md-6">
<?php foreach($result as $data); ?>
<div class="alert alert-success" role="alert">
Answer: <?php echo '<b>  Checkbox : </b>', $data['select02'];
echo '<b>  Comment : </b>', $data['comment02']; ?>
</div>
</div>
</body>
</html>
Form 2 dosen’t work, and when the table is empty i get errors insted of values. Any suggestion, material to read, ideas to add stuff that could make my form nicer? Thanks a lot.