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'");
Related
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>
EDIT:
The problem now is there are no more code errors causing error/notice splats thanks to contributors, but the data still isn't being posted into the MYSQL db, the table is just empty even though script says it's been uploaded.
Here's the code:
<?php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$ogrod_id = trim(sql_safe($_POST['ogrod_id']));
$doborsadzenieroslin = trim(sql_safe($_POST['doborsadzenieroslin']));
$nawierzchnia = trim(sql_safe($_POST['nawierzchnia']));
$systnawadn = trim(sql_safe($_POST['systnawadn']));
$malaarchitektura = trim(sql_safe($_POST['malaarchitektura']));
$oczkawodne = trim(sql_safe($_POST['oczkawodne']));
$trawniki = trim(sql_safe($_POST['trawniki']));
$oswietlenie = trim(sql_safe($_POST['oswietlenie']));
$tarasy = trim(sql_safe($_POST['tarasy']));
$pielegnacja = trim(sql_safe($_POST['pielegnacja']));
$opis = trim(sql_safe($_POST['opis']));
if ($opis === '') {
$opis = '(brak opisu)';
}
if ($password !== 'jeeus') {
$msg = 'Błąd - błędne hasło wgrywania.';
} else {
if (isset($_FILES['image'])) {
$image = $_FILES['image'];
#list(, , $imtype, ) = getimagesize($_FILES['image']['tmp_name']);
if ($imtype === 3)
$ext="png";
elseif ($imtype === 2)
$ext="jpeg";
elseif ($imtype === 1)
$ext="gif";
else
$msg = 'Błąd - nieznany format pliku.';
if (!isset($msg)) {
$data = file_get_contents($_FILES['image']['tmp_name']);
$data = mysqli_real_escape_string($con, $data);
mysqli_query($con, "INSERT INTO realizacje (ext,opis,image,ogrod_id,doborsadzenierosli,nawierzchnia,systnawadn,malaarchitektura,oczkawodne,trawniki,oswietlenie,tarasy,pielegnacja) VALUES ('$ext','$opis','$data','$ogrod_id','$doborsadzenieroslin','$nawierzchnia','$systnawadn','$malaarchitektura','$oczkawodne','$trawniki','$oswietlenie','$tarasy','$pielegnacja')");
$msg = 'Sukces - obraz został wgrany na serwer.';
}
} else if (isset($_GET['ogrod_id'])) {
$msg = 'Błąd - plik nie został wgrany.';
}
}
}
?>
Here's the HTML markup for image along with it's name property.
Also, the whole form HTML part:
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST" enctype="multipart/form-data">
<div id="filtry">
<div class="realizacjedodaj">
<b>Czy na zdjęciu znajduje/ą się <br>wykonany/e przez firmę:</b><br><br>
<label for="doborsadzenieroslin">dobór/sadzenie roślin?</label><br />
<input type="radio" name="doborsadzenieroslin" value="0" checked> Tak
<input type="radio" name="doborsadzenieroslin" value="1"> Nie<br><br>
<label for="nawierzchnia">nawierzchnia?</label><br />
<input type="radio" name="nawierzchnia" value="0" checked> Tak
<input type="radio" name="nawierzchnia" value="1"> Nie<br><br>
<label for="systnawadn">system nawadniający?</label><br />
<input type="radio" name="systnawadn" value="0" checked> Tak
<input type="radio" name="systnawadn" value="1"> Nie<br><br>
<label for="malaarchitektura">mała architektura?</label><br />
<input type="radio" name="malaarchitektura" value="0" checked> Tak
<input type="radio" name="malaarchitektura" value="1"> Nie<br><br>
</div>
<div class="realizacjedodaj">
<label for="oczkawodne">oczko wodne?</label><br />
<input type="radio" name="oczkawodne" value="0" checked> Tak
<input type="radio" name="oczkawodne" value="1"> Nie<br><br>
<label for="trawniki">trawnik?</label><br />
<input type="radio" name="trawniki" value="0" checked> Tak
<input type="radio" name="trawniki" value="1"> Nie<br><br>
<label for="oswietlenie">oswietlenie?</label><br />
<input type="radio" name="oswietlenie" value="0" checked> Tak
<input type="radio" name="oswietlenie" value="1"> Nie<br><br>
<label for="tarasy">taras?</label><br />
<input type="radio" name="tarasy" value="0" checked> Tak
<input type="radio" name="tarasy" value="1"> Nie<br><br>
<label for="pielegnacja">pielęgnacja ogrodu?</label><br />
<input type="radio" name="pielegnacja" value="0" checked> Tak
<input type="radio" name="pielegnacja" value="1"> Nie<br><br>
</div>
</div>
<div id="listaOgrodow">
<div class="realizacjedodaj">
<label for="ogrod_id"><b>Ogród:</b></label><br />
<?php
$ogrodysql = "SELECT id_ogrodu, nazwa FROM ogrody";
$result = mysqli_query($con, $ogrodysql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo "#" . $row["id_ogrodu"]. " " . $row["nazwa"]. "<input type='radio' name='ogrod_id' value=" .$row["id_ogrodu"]." <br>";
}
} else {
echo "0 results";
}
?>
<br /><br /><br />
</div>
</div>
<div id="resztaDanych" class="realizacjedodaj">
<br><br>
<label for="image">Zdjęcie realizacji:</label><br />
<input type="file" name="image" id="image"/><br /><br /><br />
<label for="opis">Opis (opcjonalnie):</label><br />
<textarea rows="4" cols="50" name="opis" id="opis"></textarea><br /><br /><br />
<input type="submit" value="Wgraj"/>
</div>
</form>
Looks like you have multiple issues in your code:
1st, the proper simple way to insert into MySQL is:
INSERT INTO table_name (field1,field2) VALUES ('$value1','$value2')
NOT
INSERT INTO {$table} SET ext='$ext', opis='$opis',
2nd, are you trying to post a normal form's field named image?
trim(sql_safe($_POST['image']));
$_POST is different than $_FILE
also, use
if (isset($_FILE['image'])) {
$image= $_FILE['image'];
}
Do you have an element (most likely the file upload element) named image in your form? If not then add it.
I'm getting a strange error when I try to submit user-generated data to a database via PHP commands. When I hit the submit button below, instead of the PHP page running its' function I am presented with a display of the raw code on my browser. I have a command at the bottom of my HTML page that looks like this:
<form action="insert.php" method="post">
<input type="submit">
</form>
So that when the user hits the submit button, the PHP file insert.php (detailed below) is called to input the answers onto a database, separating each answer into it's own field.
Here is the code I'm working with:
<?php
$con=mysqli_connect("host","username","password","database");
// Check connection
if (mysqli_connect())
{
echo "Failed to connect to MySQL: " . mysqli_errno();
}
$sql="INSERT INTO Persons (Name, Serif, Width, Height, Spacing, Weight)
VALUES
('$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]','$_POST[answer]')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
Right now, the questions are in a and not a (is there a functional difference in this case?). They look like:
<form class="testAns" id="widthAns">
<input type="radio" name="answer" value="skinny">-25%
<input type="radio" name="answer" value="skinny">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="fat">+10%
<input type="radio" name="answer" value="fat">+25%
</form>
<form class="testAns" id="spaceAns">
<input type="radio" name="answer" value="small">-25%
<input type="radio" name="answer" value="small">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="wide">+10%
<input type="radio" name="answer" value="wide">+25%
</form>
<form class="testAns" id="weightAns">
<input type="radio" name="wanswer" value="light">-25%
<input type="radio" name="answer" value="light">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="heavy">+10%
<input type="radio" name="answer" value="heavy">+25%
</form>
<form method="post" action="insert.php" class="testAns" id="heightAns">
<input type="radio" name="answer" value="short">-25%
<input type="radio" name="answer" value="short">-10%
<input type="radio" name="answer" value="mid">normal
<input type="radio" name="answer" value="tall">+10%
<input type="radio" name="answer" value="tall">+25%
</form>
The important part is for the "value" associated with each button to be logged into the database. For example, if a user selects "+10%" I want be able to log the word "heavy".And then there are two text input fields:
<form id="intro">
City: <input type="text" name="answer"><br>
Why you are using this tool:<input type="text" name="answer">
</form>
So for these text fields I need the user input logged as the answer.
I see you got the PHP thing fixed.
Now you need to fill your form with data. This:
<form action="insert.php" method="post">
<input type="submit">
</form>
sends only the submit value. You need to add input fields inside that form tag, otherwise, nothing else will get sent. So, since you're sending an answer array, you should add those (adding them as text fields, as an example):
<form action="insert.php" method="post">
<input type="text" name="answer[]" />
<input type="text" name="answer[]" />
etc...
<input type="submit" />
</form>
And make sure you filter all user inputs before writing anything into the database, as otherwise my buddy Bobby Tables might come to visit you.
Make sure in your XAMPP Control Panel that Apache and MySQL are running. Then check if your input fields are inside the <form action='insert.php' method='POST'> input fields </form>
Your HTML code would look like this:
<html>
<body>
<form action='insert.php' method='POST'>
<table>
<tr><td>Width: </td><td>
<input type="radio" name="width" value="skinny">-25%
<input type="radio" name="width" value="skinny">-10%
<input type="radio" name="width" value="mid">normal
<input type="radio" name="width" value="fat">+10%
<input type="radio" name="width" value="fat">+25%
</td></tr>
<tr><td>Spacing: </td><td>
<input type="radio" name="spacing" value="small">-25%
<input type="radio" name="spacing" value="small">-10%
<input type="radio" name="spacing" value="mid">normal
<input type="radio" name="spacing" value="wide">+10%
<input type="radio" name="spacing" value="wide">+25%
</td></tr>
<tr><td>Weight: </td><td>
<input type="radio" name="weight" value="light">-25%
<input type="radio" name="weight" value="light">-10%
<input type="radio" name="weight" value="mid">normal
<input type="radio" name="weight" value="heavy">+10%
<input type="radio" name="weight" value="heavy">+25%
</td></tr>
<tr><td>Height: </td><td>
<input type="radio" name="height" value="short">-25%
<input type="radio" name="height" value="short">-10%
<input type="radio" name="height" value="mid">normal
<input type="radio" name="height" value="tall">+10%
<input type="radio" name="height" value="tall">+25%
</td></tr>
<tr><td>City: </td><td><input type="text" name="city"></td></tr>
<tr><td>Why you are using this tool: </td><td><input type="text" name="tool"></td></tr>
<tr><td></td><td><input type='submit'></td></tr>
</table>
</form>
</body>
</html>
What are you using in creating your php files? Dreamweaver? Notepad? Try this: SAVE AS your file, Save As Type: All Files and name it insert.php.
<?php
$con=mysqli_connect("localhost","YourUsername","YourPassword(if any)","NameOfYourDatabase");
// Check connection
if (mysqli_connect())
{
echo "Failed to connect to MySQL: " . mysqli_errno();
}
$width=$_POST['width'];
$spacing=$_POST['spacing'];
$weight=$_POST['weight'];
$height=$_POST['height'];
$city=mysqli_real_escape_string($con,$_POST['city']);
$tool=mysqli_real_escape_string($con,$_POST['tool']);
/* REAL ESCAPE STRING WOULD PREVENT A BIT OF SQL INJECTION */
$sql="INSERT INTO Persons (Name, Serif, Width, Height, Spacing, Weight)
VALUES
('$city','$tool','$width','$height','$spacing','$weight')";
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
echo "1 record added";
mysqli_close($con);
?>
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.
firstly sorry my english is bad
then
i have problem
i try to make lopping insert into table but i have problem i can't make array for inputs
to can insert in table with looping from another table
maybe u can't understand me but look to the code and u will understand my problem
$select = mysql_query("SELECT * FROM table_name ");
?>
<form method="post" action="">
<?
while($row =mysql_fetch_array($select))
{
if($_POST['add'])
{
$updpol = mysql_query("insert into table_name2 (yes,no,maybe,g_id)
values
('".$_POST['yes']."','".$_POST['no']."','".$_POST['maybe']."','".$row['id']."')
")
}
else{
?>
<input type="checkbox" name="yes" value="1" />
<br />
<input type="checkbox" name="no" value="1" />
<br />
<input type="checkbox" name="maybe" value="1" />
<?
}
?>
<input type="submit" name="add_poll" value="submit" />
</form>
in your php code , your checking if:
if($_POST['add'])
While there's no input named add in your form.
I believe you meant:
if($_POST['add_poll'])
In order to have multiply instances of inputs , you can do something like:
<input type="checkbox" name="yes[]" value="1" />
<br />
<input type="checkbox" name="no[]" value="1" />
<br />
<input type="checkbox" name="maybe[]" value="1" />
So , now , when posted:
$_POST['yes'] is an array of all the checkboxes.
And as an array , it starts with $_POST['yes'][0] and continues $_POST['yes'][1] and so on.
Therefore:
$select = mysql_query("SELECT * FROM table_name ");
?>
<form method="post" action="">
<?
$i = 0;
while($row =mysql_fetch_array($select))
{
if($_POST['add_poll'])
{
$updpol = mysql_query("insert into table_name2 (yes,no,maybe,g_id)
values
('".$_POST['yes'][$i]."','".$_POST['no'][$i]."','".$_POST['maybe'][$i]."','".$row['id']."')
");
$i++;
}
else{
?>
<input type="checkbox" name="yes[]" value="1" />
<br />
<input type="checkbox" name="no[]" value="1" />
<br />
<input type="checkbox" name="maybe[]" value="1" />
<?
}
?>
<input type="submit" name="add_poll" value="submit" />
</form>