Show data after receiving from database PHP - php

This is my PHP code, which will display data when I click the button. I want to display the data for the specified card when I click the button for the number 1. I want to display all information in card 1, but my code will display all information. Can anyone help me?
http://www.m9c.net/uploads/15678158911.png
<? $title= 'Show CV';
$quariy = ("select * from information where selector ='2'");
$result = mysqli_query($mysqli, $quariy) or die("database
error:". mysqli_error($mysqli));
while ($data = mysqli_fetch_assoc($result)) {?>
<form action="" method = "post" class= "pl-4 pr-4">
<div class="card">
<div class="card-body">
<div class="form-group">
<label for="name">Your Name</label>
<input type="text" class="form-control" name="name"
value="<?php echo $data['name'] ?>">
</div>
<div class="form-group">
<label for="education">Your Education</label>
<input type="text" class="form-control"
name="education" value="<?php echo $data['education']?>" >
</div>
<div class="form-group">
<label for="contact_information"> Contact
Information </label>
<textarea class="form-control"
name="contact_information" rows="3"><?php echo
$data['contact_information'] ?></textarea></div>
<div class="form-group">
<label for="skills">Skills</label>
<textarea class="form-control" name="skills"
rows="3"><?php echo $data['skills'] ?></textarea>
</div>
<div class="form-group">
<label for="work">Work Experiences </label>
<textarea class="form-control" name="work"
rows="3">
<?php echo $data['work'] ?></textarea></div>
<div class="form-group">
<label for="projects">Projects </label>
<textarea class="form-control" name="projects"
rows="3"><?php echo $data['projects'] ?>
</textarea>
</div></div><?php }?></form>

Related

Issue populating textarea with db data

So, like the title said, i'm having an issue while i'm populating a text area that is being used on HTML form, because it is not getting any content in it.
this is the form with the php while.
<?php
while ($row = mysqli_fetch_array($query))
{ echo '
<form action="insert/insertReport.php" id="newReport" method="post">
<div class="form-group">
<label for="clientRep">Cliente</label>
<br>
<input type="text" name="client" class="form-control" id="client" value="'.$row['client'].'">
</div>
<div class="form-group">
<label for="titleRep">Título do Relatório</label>
<br>
<input type="text" name="title" class="form-control" id="title" value="'.$row['title'].'">
</div>
<div class="form-group">
<label for="namefat">Data</label>
<br>
<input type="text" name="date" class="form-control" id="date" value="'.$row['date'].'">
</div>
<div class="form-group">
<label for="localRep">Local</label>
<br>
<input type="text" name="local" class="form-control" id="local" value="'.$row['local'].'">
</div>
<div class="form-group">
<label for="reportRep">Relatório</label>
<br>
<textarea rows="12" name="report" class="form-control" id="report" form="newReport" value="'.$row['report'].'"></textarea>
</div>
<input type="hidden" name="id" class="form-control" id="id" value="'.$row['id'].'">';
}?>
And this is the php query.
$sql = 'SELECT * FROM reports'
Does anyone know what's wrong with it?
Text area does not accept a value attribute. You place the contents between the textarea tags:
<textarea rows="12" name="report" class="form-control" id="report" form="newReport">'.$row['report'].'</textarea>

While loop displays one record multiple times php and mysql issue

I am trying to fetch data from the database. But while loop is executing and displaying data multiple times. Please see the screen shot
<?php
$conn = mysqli_connect("localhost", "root", "","midata");
$sql = "SELECT * FROM campaign_profile ORDER BY id DESC";
?>
<div class="modal-body">
<form>
<?php
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result))
{
$name= $row['campaign_name'];
$issues= $row['issue_name'];
$ename= $row['unused_elements'];
$uquantity= $row['unused_number'];
$descript= $row['experience']; ?>
<div class="form-group">
<label for="recipient-name" class="control-label">Campaign Name:</label>
<input type="text" class="form-control c-square" id="recipient-name" value="<?php echo $row['campaign_name'];?>">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Issues:</label>
<input type="text" class="form-control c-square" id="recipient-name" value="<?php echo $row['issue_name'];?>">
</div>
<div class="row col-md-12">
<div class="form-group col-md-6">
<label for="recipient-name" class="control-label">Element Name:</label>
<input type="text" class="form-control c-square" id="recipient-name" class="col-md-6" value="<?php echo $row['unused_elements'];?>">
</div>
<div class="form-group col-md-6">
<label for="recipient-name" class="control-label">Unused Quantity:</label>
<input type="text" class="form-control c-square" id="recipient-name" class="col-md-6" value="<?php echo $row['unused_number'];?>">
</div>
</div>
<div class="form-group">
<label for="message-text" class="control-label">Description:</label>
<textarea class="form-control c-square" id="message-text" value="<?php echo $row['experience'];?>"></textarea>
</div>
<?php } ?>
</form>
</div>
I don't understand why this is happening. Do let me know what needs to be done
May be your table has more rows then you are expecting.
limit your query using this.
$sql = "SELECT * FROM campaign_profile ORDER BY id DESC limit 1";
or try to fetch data using id or primary key.
or change your code with given below.
<?php
$conn = mysqli_connect("localhost", "root", "","midata");
$sql = "SELECT * FROM campaign_profile ORDER BY id DESC";
?>
<div class="modal-body">
<form>
<?php
$name= "";
$issues= "";
$ename= "";
$uquantity= "";
$descript= "";
$result = mysqli_query($conn,$sql);
while($row = mysqli_fetch_array($result))
{
$name= $row['campaign_name'];
$issues= $row['issue_name'];
$ename= $row['unused_elements'];
$uquantity= $row['unused_number'];
$descript= $row['experience'];
} ?>
<div class="form-group">
<label for="recipient-name" class="control-label">Campaign Name:</label>
<input type="text" class="form-control c-square" id="recipient-name" value="<?php echo $row['campaign_name'];?>">
</div>
<div class="form-group">
<label for="recipient-name" class="control-label">Issues:</label>
<input type="text" class="form-control c-square" id="recipient-name" value="<?php echo $row['issue_name'];?>">
</div>
<div class="row col-md-12">
<div class="form-group col-md-6">
<label for="recipient-name" class="control-label">Element Name:</label>
<input type="text" class="form-control c-square" id="recipient-name" class="col-md-6" value="<?php echo $row['unused_elements'];?>">
</div>
<div class="form-group col-md-6">
<label for="recipient-name" class="control-label">Unused Quantity:</label>
<input type="text" class="form-control c-square" id="recipient-name" class="col-md-6" value="<?php echo $row['unused_number'];?>">
</div>
</div>
<div class="form-group">
<label for="message-text" class="control-label">Description:</label>
<textarea class="form-control c-square" id="message-text" value="<?php echo $row['experience'];?>"></textarea>
</div>
</form>
</div>
Try to analyze the query result by directly running the mysql select query by terminal or phpmyadmin tool. Please check the result of the query with php code, If both are same your table contains duplication data.
If want show single record means no need while loop just do it like below
Limit the record by adding limit 1
SELECT * FROM campaign_profile ORDER BY id DESC limit 1
PHP :
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result);
$name= $row['campaign_name'];
$issues= $row['issue_name'];
$ename= $row['unused_elements'];
$uquantity= $row['unused_number'];
$descript= $row['experience'];

Want to display as table view

Here I want to change the UI design of this code.I need to display the belows are in table view.Here in code some fields have same names that is name ml,name en and info ml,info en and details ml,details en.that two similer fields should be in same line
<div class="form quick-post">
<!-- Edit deity Details-->
<form class="form-horizontal" action="deity_manage.php" method="post">
<!-- Deity id -->
<div class="form-group">
<label class="control-label col-lg-2" for="title"></label>
<div class="col-lg-10">
<input type="hidden" class="form-control" name="deity_id" id="title" value="<?php echo $deity_id;?>">
</div>
</div>
<!-- Name ml -->
<label class="control-label col-lg-2" for="title">Name Ml</label>
<input type="text" class="form-control" name="deity_name_ml" id="deity_name_ml" value="<?php echo $deity_name_ml;?>">
<!--Name en-->
<label class="control-label col-lg-2" for="content">Name En</label>
<input type="text" class="form-control" name="deity_name_en" id="deity_name_en" value="<?php echo $deity_name_en; ?>">
<div style="padding-top:25px"></div>
<!--Info ml-->
<label class="control-label col-lg-2" for="content">Info Ml</label>
<textarea rows="4" cols="50" name="info_ml" ><?php echo $info_ml;?></textarea>
<!--Info en-->
<label class="control-label col-lg-2" for="content">Info En</label>
<textarea rows="4" cols="50" name="info_en" ><?php echo $info_en;?></textarea>
<div style="padding-top:25px"></div>
<!--details_ml -->
<label class="control-label col-lg-2" for="content">Details Ml</label>
<textarea rows="4" cols="50" name="details_ml" ><?php echo $details_ml;?></textarea>
<!--Details en-->
<label class="control-label col-lg-2" for="content">Details En</label>
<textarea rows="4" cols="50" name="details_en" ><?php echo $details_en;?></textarea>
<div style="padding-top:25px"></div>
<!--Mantra ml-->
<label class="control-label col-lg-2" for="content">Mantra Ml</label>
<input type="text" class="form-control" name="mantra_ml" id="mantra_ml" value="<?php echo $mantra_ml;?>">
<!--Mantra en-->
<label class="control-label col-lg-2" for="content">Mantra En</label>
<input type="text" class="form-control" name="mantra_en" id="mantra_en" value="<?php echo $mantra_en;?>">
<div style="padding-top:25px"></div>
<!--God-->
<label class="control-label col-lg-2" for="content">God</label>
<select multiple="true" name="god_id">
<?php while ($row = $sth->fetch(PDO::FETCH_ASSOC)) { ?>
<option <?php if($row['god_id'] == $god_id) { echo "selected='selected'"; } ?> value="<?php echo $row['god_id'];?>">
<?php echo $row['god_name_en']; ?>
</option>
<?php } ?>
</option>
</select>
<div style="padding-top:25px"></div>
<!--Display order-->
<label class="control-label col-lg-2" for="content">Display Order</label>
<input type="text" class="form-control" name="display_order" id="display_order" value="<?php echo $display_order;?>">
<div style="padding-top:25px"></div>
<!-- Buttons -->
<div class="form-group">
<!-- Buttons -->
<div class="col-lg-offset-2 col-lg-9">
<button type="submit" class="btn btn-danger" name="submit" value="submit"> Save </button>
</div>
</div>
</form>
</div>
</div>
Give all the labels and input types inside the tag
<table>
<tr>
<td><label class="control-label col-lg-2" for="content">Details En</label>
</td>
<td>
<textarea rows="4" cols="50" name="details_en" ><?php echo $details_en;?></textarea>
</td>
<Label

Submit button will not send form data to MySQL database [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a problem that might be a syntax problem but I can't seem to figure out what I am doing wrong.
I have created a form and when I click on submit, the data in the form is not sent to my mysql database.
Here is my html code
<div class="content-wrapper">
<div class="container">
<div class="row">
<div class="col-md-10">
<h1 class="page-head-line">Forms </h1>
</div>
</div>
<div class="row">
<div class="col-md-10">
<div class="panel panel-default">
<div class="panel-heading">
BASIC FORM ELEMENTS
</div>
<div class="panel-body">
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name' type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num' type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="name' type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista' type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency' type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description' type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date' type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
</div>
</div>
and here is my php
<?php
echo $POST;
error_reporting(E_ALL);
ini_set('display_errors', 1);
include("../includes/config.php");
if (isset($_POST['submit'])) {
echo $_POST['submit'];
$name = $_POST['name'];
$projectnum = $_POST['project_num'];
$projectname = $_POST['project_name'];
$easyvista = $_POST['easyvista'];
$agency = $_POST['agency'];
$description = $_POST['description'];
$startDate = $_POST['input-date'];
$sql="INSERT INTO statusreport(name, project_num, project_name, easyvista, agency, description)
VALUES
('$name','$projectnum', '$projectname', '$easyvista', '$agency', '$description')";
if (!mysqli_query($conn, $sql))
{
die('Error: ' . mysqli_connect_error($conn));
}
echo "Entry is recored <br/>";
echo "Name:", $name, "<br/>";
echo "test..................<br/>", $name;
/*header("location: http://10.1.7.129//gisadmin/admin/forms.php");*/
//echo "<script>setTimeout(\"location.href = 'http://10.1.7.129//gisadmin/admin/forms.php';\",700);</script>";
mysqli_query($conn, $sql);
}
else {
echo "No data";
}
?>
Any help would be greatly appreciated.
Thanks
You have a mixing of single and double quotes here, the name attributes are opening the value with double quotes and closing with single quotes, should be as follows:
<form method="post" action="insert.php" >
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
<div class="form-group">
<label for="project_num">OIT-GIS Project Number</label>
<input name="project_num" type="text" class="form-control" id="project_num" placeholder="OIT-GIS Project Number" />
</div>
<div class="form-group">
<label for="project_name">Project Name</label>
<input name="project_name" type="text" class="form-control" id="project_name" placeholder="Project Name" required/>
</div>
<div class="form-group">
<label for="easyvista">EasyVista Ticket Number</label>
<input name="easyvista" type="text" class="form-control" id="easyvista" placeholder="EasyVista Ticket Number" />
</div>
<div class="form-group">
<label for="agency">Requestor/Agency</label>
<input name="agency" type="text" class="form-control" id="agency" placeholder="Requestor or Agency" />
</div>
<div class="form-group">
<label for="description">Description of Work:</label>
<input name="description" type="text" class="form-control" id="agency" placeholder="Description" />
</div>
<div class="form-group">
<label for="input-date">Enter Today Date</label>
<input name="input-date" type="date" value="">
<span class="result"></span>
</div>
<div class="form-group">
<div class="col-md-10">
<input id="submit" name="submit" type="submit" class="btn btn-primary">
</div>
</div>
</form>
And then, as #Fred -ii stated in his comment, the php script is wrong:
echo $POST;
That line is wrong, there is no variable with name $POST before that code.
Are you getting success message but database is not getting updated OR Getting Total Error...???
1) Check for double quotes and single quotes..
<div class="form-group">
<label for="name">Name</label>
<input name="name" type="text" class="form-control" id="name" placeholder="Enter your name" required/>
</div>
2) Also check for path... for
include("../includes/config.php");
Is it correct or not...?
3)
<label for="project_name">Project Name</label>
<input name="name' type="text"
SHOULD BE
<label for="project_name">Project Name</label>
<input name="project_name" type="text"

Can not get data from database in ECHO

My edit.php code is stated below, and this is what the outcome is: http://i.imgur.com/lt89Wi8.png
But what it is supposed to do is, get the information from the username - loggin_session, and show their server details , so they dont have to re-write everything.
see: http://i.imgur.com/fGEsXPq.png
<?php
$query = "SELECT id, username, name, url, banner, description, sponsor, votes FROM websites WHERE username = '$login_session'";
$result = mysql_query($query) OR die($mysql_error());
$num = mysql_num_rows($result);
if ($num < 1) {
$n = FALSE;
echo '<font color="red">You have no servers to edit, You can add one here</font><br />';
die();
} ?>
<form action="" method="post" name="join_form" class="form-horizontal" role="form" enctype="multipart/form-data" onSubmit="return checkform(this);">
<div class="form-group ">
<label for="join_email" class="col-md-1 control-label"><span class="required">*</span>Server Title</label>
<div class="col-md-5">
<input name="name" value="<?php echo $_POST['name']; ?>" class="form-control" placeholder="<?php echo ''.$row['name'].''?>" required>
</div>
</div>
<div class="form-group ">
<label for="join_password" class="col-md-1 control-label"><span class="required">*</span>Website URL</label>
<div class="col-md-5">
<input name="url" value="<?php if (isset($_POST['url'])) echo $_POST['url']; ?>" class="form-control" placeholder="<?php echo ''.$row['url'].''?>" required>
</div>
</div>
<div class="form-group ">
<label for="join_url" class="col-md-1 control-label"><span class="required">*</span>Banner URL</label>
<div class="col-md-5">
<input name="banner" value="<?php if (isset($_POST['banner'])) echo $_POST['banner']; ?>" class="form-control" type="text" placeholder="<?php echo ''.$row['banner'].''?>" required>
</div>
</div>
<div class="form-group ">
<label for="join_title" class="col-md-1 control-label"></label>
<div class="col-md-5"></div>
</div>
<div class="form-group ">
<label for="join_description" class="col-md-1 control-label"><span class="required">*</span>Descr..</label>
<div class="col-md-5">
<textarea cols="50" rows="5" value="<?php if(isset($_POST['description'])) echo $_POST['description']; ?>" name="description" id="description_size" class="form-control" placeholder="<?php echo ''.$row['description'].''?>" required></textarea>
</div>
</div>
<input type="submit" name="submit" value="Add" />
<input type="hidden" name="submitted" value="TRUE" />
</form>
$row is undefined in your code. It has to be
$row=mysql_fetch_assoc($result); // fetch it from the result set
How can I prevent SQL injection in PHP?
And what's up with that useless '' in every echo?
echo ''.$row['name'].''
^^ ^^
This is enough
echo $row['name'];

Categories