Get radio button data from mysql in input form - php

I've already searched and I don't understand why this isn't working.
<input type="radio" name="soort" value="in" echo ('.$_GET['soort'].'=="in")?"checked":"">In-Company<br />
<input type="radio" name="soort" value="open" echo ('.$_GET['soort'] . '"=="open")?"checked":">Open inschrijving<br />
This isn't working either:
<input type="radio" name="soort" value="in" echo ($soort=="in")?"checked":"">In-Company<br />
<input type="radio" name="soort" value="open" echo ($soort=="open")?"checked":">Open inschrijving<br />
Clearly I'm doing something wrong or I'm missing something.
If anyone could help me out here or put me in the right direction. Thank you!!!!
This is the entire form.
print '<form action="edit_dienst.php" method="post">
<p><strong>Titel</strong> <textarea name="navigatie" columns="20" rows="5">' . $row['navigatie'] . '</textarea></p>
<p><strong>Tekst</strong> <textarea name="tekst" columns="20" rows="5">' . $row['tekst'] . '</textarea></p>
<input type="radio" name="soort" value="in" echo ($soort=="in")?"checked":"">In-Company<br />
<input type="radio" name="soort" value="open" echo ($soort=="open")?"checked":">Open inschrijving<br />
<input type="hidden" name="id" value="' . $_GET['id'] . '" />
<input type="submit" name="submit" value="Pas aan!" />
</form><p></p>';

<?php $soort=$_GET['soort']; ?>
<input type="radio" name="soort" value="in" <?php echo ($soort=="in")?"checked":"" ?>>In-Company<br />
<input type="radio" name="soort" value="open" <?php echo ($soort=="open")?"checked":"" ?>>Open inschrijving<br />

since i see 'print', i infer that you are already in the php tag. you can the below script.
$soortInChecked = ($soort=="in")?"checked":"";
$soortOpenChecked = ($soort=="open")?"checked":"";
print '<form action="edit_dienst.php" method="post">
<p><strong>Titel</strong> <textarea name="navigatie" columns="20" rows="5">' . $row['navigatie'] . '</textarea></p>
<p><strong>Tekst</strong> <textarea name="tekst" columns="20" rows="5">' . $row['tekst'] . '</textarea></p>
<input type="radio" name="soort" value="in" '.$soortInChecked.' >In-Company<br />
<input type="radio" name="soort" value="open" '.$soortOpenChecked.' >Open inschrijving<br />
<input type="hidden" name="id" value="' . $_GET['id'] . '" />
<input type="submit" name="submit" value="Pas aan!" />
</form><p></p>';
the issue is that you have given the echo inside the quotes. check the tutorials for print/echo also the difference in single and double quotes in php to start with.

Related

get form values from one php "echo" to the other

i want get the values of form in other php file but i am getting only one input value as the name are same in loop....How to get all the input values with the same name or if i have to change the name tell me how? and how to get it in other php file
<?php
if(isset($_POST['submit'])){
//getting values of number of MCQ questions and true/false questions
$mcq = $_POST['mcq'];
$truefalse = $_POST['truefalse'];
$number = 1;
echo '<form action="finalquestions.php" method="post">';
//loop to get inputs of mcq as many as the user posted
for($i=1;$i<=$mcq;$i++){
echo 'Question:'.$number.'<input type="text" name="question1" /> </br></br>';
echo '<input type="radio" name="radio1"> <input type="text" name="radiooptions" /> </br>
<input type="radio" name="radio1"> <input type="text" name="radiooptions" /> </br>
<input type="radio" name="radio1"> <input type="text" name="radiooptions" /> </br>
<input type="radio" name="radio1"> <input type="text" name="radiooptions" /> </br>';
echo '</br></br>';
$number++;
}
//loop to get inputs of truefalse as many as the user posted
for($i=1;$i<=$truefalse;$i++){
echo 'Question:'.$number.' <input type="text" name="question2" /> </br></br>';
echo '<input type="radio" name="question2">True</br>
<input type="radio" name="question1">False</br>';
echo '</br></br>';
$number++;
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>WebQuiz Generator</title>
</head>
<body>
<input type="submit" name="submit" value="Generate Quiz" />
</form>
</body>
</html>

Keep the check mark after form is submitted

I have 2 forms that they need to be used to make a report. The first form gets data from the database (MariaDB) onchange of one of the cells (the on change events happens when the user checks the cell with the report) once that the cell is selected with the details of the report, those details are used on submit by the second form. Until that point everything is perfect. The problem is that I can't keep the check mark on the cell of the first form once that it is selected because the page is reloaded onchange. That makes the user believe that they didn't select any report.
So, what I want to do is to keep checked the cell of the first form after it gets the data from the database. Then, the user will click on "Submit" to submit the second form.
Kind regards and thanks in advance for your help!
<form name="f1" id="form1" action="" method="post">
<div class="table-responsive">
<table class="table table-striped">
<thead>
<tr>
<th>Select</th>
<th>Assets </th>
<th>Description </th>
<th>Date</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
while($agency_row = $agency_stmt->fetch(PDO::FETCH_ASSOC)){
$value1 = str_replace(' ',' ',str_pad($agency_row["agency"], -10));
$value2 = str_replace(' ',' ',str_pad($agency_row["report_name"], 70));
$formatedDate = date("D M d H:i:s Y", $agency_row["scan_end"]);
$value3 = str_replace(' ',' ',str_pad($formatedDate, 20));
echo "<tr>";
echo "<td><input onchange='f1.submit()'; type='checkbox' class='i-checks' name='agency' value='" . $value1 . ":" . $agency_row["report_name"] . ":" . $agency_row["scan_start"] . ":" . $agency_row["scan_end"] . "'></td>";
echo "<td>$value1</td>";
echo "<td>$value2</td>";
echo "<td>$formatedDate</td>";
echo "<td>$value3</td>";
echo "</tr>";
}?>
</tbody>
</table>
</form>
<form name="f2" id="form2" action="report.php" method="post">
<input type="hidden" name="agency" value="<?php echo "$agency";?>">
<input type="hidden" name="report_name" value="<?php echo "$report_name";?>">
<input type="hidden" name="scan_start" value="<?php echo "$scan_start";?>">
<input type="hidden" name="scan_end" value="<?php echo "$scan_end";?>">
<input type="hidden" value="yes" name="isPlugName">
<input type="hidden" value="yes" name="isPlugFam">
<input type="hidden" value="yes" name="isPlugInfo">
<input type="hidden" value="yes" name="isSynopsis">
<input type="hidden" value="yes" name="isDescription">
<input type="hidden" value="yes" name="isSolution">
<input type="hidden" value="yes" name="isSeeAlso">
<input type="hidden" value="yes" name="isPlugOut">
<input type="hidden" value="plugin" name="byVuln">
<input type="hidden" value="yes" name="isCvss">
<input type="hidden" value="yes" name="isVulnPub">
<input type="hidden" value="yes" name="isExploit">
<input type="hidden" value="yes" name="isCve">
<input type="hidden" value="yes" name="isBid">
<input type="hidden" value="yes" name="isOsvdb">
<input type="hidden" value="yes" name="isCert">
<input type="hidden" value="yes" name="isIava">
<input type="hidden" value="yes" name="isCWE">
<input type="hidden" value="yes" name="isMS">
<input type="hidden" value="yes" name="isSec">
<input type="hidden" value="yes" name="isEdb">
<input type="hidden" value="yes" name="isAffected">
<input type="hidden" value="yes" name="isService">
<input type="hidden" value="4" name="critical">
<input type="hidden" value="3" name="high">
<input type="hidden" value="2" name="medium">
<input type="hidden" value="1" name="low">
<input type="submit" name="submithost" value="submit">
</form>
Change
echo "<td><input onchange='f1.submit()'; type='checkbox' class='i-checks' name='agency' value='" . $value1 . ":" . $agency_row["report_name"] . ":" . $agency_row["scan_start"] . ":" . $agency_row["scan_end"] . "'></td>"
to
$checked=(isset($_REQUEST['agency']) && $_REQUEST['agency'] == $value1) ? ' checked' : '';
echo "<td><input onchange='f1.submit()'; type='checkbox' class='i-checks' name='agency' value='" . $value1 . ":" . $agency_row["report_name"] . ":" . $agency_row["scan_start"] . ":" . $agency_row["scan_end"] . $checked ."'></td>"

Displaying a column that a user created in a form

Im trying to display a single column from where a user created a form, i have a table and user sessions set up. I need it so that only that column is displayed for the user that created it.
This is the form
<form action="core/process.php" method="post" id="registration" >
<input type="hidden" name="formID" value="Product_Tracker" />
<input type="hidden" name="id_user" value="<?php echo $_SESSION['name_of_user']; ?>" />
<p>Name of product:<input type="text" name="Name of Product" class="input" />
<p>Please select the tests that were done on the product.</p>
<p>In Circuit Test (ICT): Yes: <input type="radio" name="ICT" value="yes" /> No: <input type="radio" name="ICT" value="no" /></p>
<p>Visual Inspection: Yes: <input type="radio" name="Visual Inspection" value="yes" /> No: <input type="radio" name="Visual Inspection" value="no" /></p>
<p>XRAY: Yes: <input type="radio" name="XRAY" value="yes" /> No: <input type="radio" name="XRAY" value="no" /></p>
<p>Automated Optical Inspection (AOI): Yes: <input type="radio" name="AOI" value="yes" /> No: <input type="radio" name="AOI" value="no" /></p>
<!--<p>Checkbox1 <input type="checkbox" name="checkbox" value="checkbox1" /> Checkbox2: <input type="checkbox" name="checkbox" value="checkbox2" /></p>-->
<input type="submit" value="Submit" />
<p>
<a href='access-controlled.php'>Back</a>
</p>
</form>
</div>
</body>
</html>
<?php VDEnd(); ?>
Ive tried this but it doesnt work,
$con = mysql_connect("","","");
if (!$con){
die("Can not connect: " . mysql_error());
}
mysql_select_db("database",$con);
$result = mysql_query("SELECT id_user, Name_of_product FROM Product_Tracker WHERE id_user=$_SESSION['name_of_user']");
while ($row = mysql_fetch_assoc($result)) {
echo $row['Name_of_Product'];
echo "<br />";
this did it;
mysql_select_db("database",$con);
$id=$_SESSION['name_of_user'];
$result = mysql_query("SELECT id_user, Name_of_product FROM Product_Tracker WHERE id_user='$id'");
while ($row = mysql_fetch_array($result))
{
echo $row['Name_of_product'] . "<br/>";
}
mysql_query($query);
mysql_close($con);
?>
have you tried this
$id=$_SESSION['name_of_user'];
$result = mysql_query("SELECT id_user, Name_of_product FROM Product_Tracker WHERE id_user='$id'");

Display a checked checkbox in a form to form POST submission

I have this wizard that needs to display the previous posted value
index.html
<form method="post" action="posted.php">
<input type="text" name="surname" value="" placeholder="Surname" />
<input type="text" name="firstname" value="" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
in the posted.php i have a similar form only this time i know the value from $_POST
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" />
<input type="checkbox" name="jquery" />
<input type="checkbox" name="python" />
<input type="submit" value="Submit" />
</form>
I am having a hard time trying to come up with a solution that shows what checkbox was checked.I have seen several solutions like https://stackoverflow.com/a/11424091/1411148 but i wondering if there more solution probably in html5 or jquery.
How can i show what checkbox was checked?.The probem i am having is that <input type="checkbox" name="jquery" checked /> checked checks the checkbox and no post data can be added to show what the user checked.
This would be a way to go:
<form method="post" action="finish.php">
<input type="text" name="surname" value="<?php echo $_POST['surname']; ?>" placeholder="Surname" />
<input type="text" name="firstname" value="<?php echo $_POST['firstname']; ?>" placeholder="Firstname" />
<input type="checkbox" name="php" <?php if (isset($_POST['php'])) echo 'checked="checked"'; ?> />
<input type="checkbox" name="jquery" <?php if (isset($_POST['jquery'])) echo 'checked="checked"'; ?> />
<input type="checkbox" name="python" <?php if (isset($_POST['python'])) echo 'checked="checked"'; ?> />
<input type="submit" value="Submit" />
</form>

I want to update a value of radio button in database (mysql) using php

I am new to php and mysql. i've used radio buttons to save the type of my account records i can insert the data successfully but when i try to get that data (whether type S is selected or type T is selected) from sql to update it further i cant do that. i dont know how to get the data of radio buttons from my sql.. please help
<form method="post" action="users-edit-action.php">
<input type="hidden" value="<?php echo $accountid; ?>" name="id" />
<label>Email/Username:</label><input type="text" name="email" value="<?php echo $email; ?>" /><br /><br />
<label>Password:</label><input type="password" name="password" value="<?php echo $password;?>" /><br /><br />
<label>First Name:</label><input type="text" name="firstname" value="<?php echo $firstname; ?>" /><br /><br />
<label>Last Name:</label><input type="text" name="lastname" value="<?php echo $lastname; ?>" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Student<br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Teacher<br />
<input type="submit" value="Edit" />
</form>
this is how i get the value from database.. im sure iam doing wrong, please help me solve this..
You have to check which type you got from the database and according to that add this attribute to the input element: checked="checked". So the whole selected tag would look like this:
<input name="type" type="radio" checked="checked" value="the one PHP returned" />
And the other input tag would also be there, but without the checked attribute.
You just need to do the PHP check on what element to put the attribute.
The whole part:
<input type="radio" name="type" value="S" <?php if ($type == 'S') echo 'checked="checked"'; ?>" /> Student<br />
<input type="radio" name="type" value="T" <?php if ($type == 'T') echo 'checked="checked"'; ?>" /> Teacher<br />
The value of your radio-buttons is fixed and does not depend on the value in the database, only whether it is checked or not.
It should be something like:
<input type="radio" name="type" value="S" <?php echo ($type == 'S') ? 'checked' : ''; ?> /> Student<br />
<input type="radio" name="type" value="T" <?php echo ($type == 'T') ? 'checked' : ''; ?> /> Teacher<br />

Categories