I am writing a portable web application with Php and I am using SQLite for my database. I want to display the date difference between two dates but it isn't working at the moment.
Can you help me, please?
(My English is not good, sorry).
My Code:
<h3>Tarihe göre arama</h3>
<form class="form-horizontal" action="" method="post">
<label>Tarih 1</label>
<input type="text" class="form-control" name="tarih1" id="tarih1" value="<?php echo $buguntarih;?>" required>
<label>Tarih 2</label>
<input type="text" class="form-control" name="tarih2" id="tarih2" value="<?php echo $buguntarih;?>" required>
<input type="submit" value="Filtrele" name="filtrele" class="btn btn-primary pull-right" style="background:none;">
</form>
<?php
if($_POST['filtrele']){
$tarih1=$_POST['tarih1'];
$tarih2=$_POST['tarih2'];
$query = $db->query("SELECT * FROM islem where eklenme_tarihi between '{$tarih1}' and '{$tarih2}' and sirket_id={$sirketid} order by id ", PDO::FETCH_ASSOC);
} else{
$query = $db->query("SELECT * FROM islem where sirket_id={$sirketid} order by id ", PDO::FETCH_ASSOC);
}
?>
<?php echo $sirket['sirket_adi']; ?></b> şirketine ait işlemler (
<?php
if($_POST['filtrele']){
echo "<b>".$tarih1."</b> ve <b>".$tarih2."</b> arası";
} else{
echo"tümü";
}
?>
Related
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 last month.
Improve this question
enter code hereI want to get the id of the selected item from the database when the user selects an item from the select option in an html form using the php language.
`
$query = "select * from Courses";
$results = mysqli_query($con, $query);
`This id is in the courses table
I want to get the id of the selected item from the database when the user selects an item from the select option in an html form using the php language. this is image about select option that exsit html form
<div class="user_profile">
<div class="div">
<form action="UserPanel.php" class="userinfo" method="post">
<input type="text" value="<?php echo $user_data['username'] ?>" name="name" placeholder="نام کاربری">
<input type="email" value="<?php echo $user_data['email'] ?>" name="email" placeholder="پست الکترونیکی">
<input type="text" value="<?php echo $user_data['national_code'] ?>" name="ncode" placeholder="کد ملی ">
<input type="text" value="<?php echo $user_data['date_of_birth'] ?>" name="date_of_birth" placeholder="تاریخ تولد">
<input type="text" value="<?php echo $user_data['education'] ?>" name="education" placeholder=" تحصیلات">
<span>عنوان دوره آموزشی </span>
<select name="courses" id="course" style="width:220px;color:white;font-size:14px">
<option value="">دوره خود را انتخاب کنید</option>
<?php foreach ($result as $key => $value) { ?>
<option value="<?= $value['Course_Name']; ?>"><?= $value['Course_Name']; ?></option>
<?php } ?>
</select>
<div class="btns">
<button class="btn" name="update">ویرایش اطلاعات </button>
<button class="btn">حذف </button>
<button class="btn" name="register"> ثبت نهایی </button>
</div>
</form>
</div>
but this is an error
undefined array key id_Crs.....
this is code for insert into
if (isset($_POST['register'])) {
$id = $user_data['id'];
// insert into database and table register
$insert = "INSERT INTO registration(user_id,id_Crs) VALUES ('$id','$id_crs')";
if (mysqli_query($con, $insert)) {
$message = "Registration";
} else {
$message = "Error: registering failed $insert." . mysqli_error($con);
}
}
<?php
$query = "select * from Courses";
$results = mysqli_query($mysqli, $query);
while($res = mysqli_fetch_array($result))
{
# you can get id
?><option value="<?=$res["id"];?>"><?=$res["name"];?></option>
<?php } '>
I'm trying to echo a piece of text with PHP nested in it, anyone know how? I've tried it like this:
function update_category(){
global $connection;
if (isset($_GET['edit'])) {
$edit_cat_key = $_GET['edit'];
$query = "SELECT * FROM categories WHERE cat_id = {$edit_cat_key }";
$edit_cat_query = mysqli_query($connection, $query);
echo '<form action="categories.php" method="post">
<div class="form-group">
<label for="new-cat-title">New name of category</label>
<input value="<?php if(isset($cat_title)){echo $cat_title;} ?>" type="text" class="form-control" name="new-cat-title">
</div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Rename Category">
</div>
</form>';
while($row = mysqli_fetch_assoc($edit_cat_query)) {
$cat_title = $row['cat_title'];
$cat_id = $row['cat_id'];
}
}
}
It prints: <?php if(isset($cat_title)){echo $cat_title;} ?>
I've tried it like this:
<input value="' . <?php if(isset($cat_title)){echo $cat_title;} ?> . '" type="text" class="form-control" name="new-cat-title">
I'd do it like this (showing only the echo part inside the php code):
echo '<form action="categories.php" method="post">
<div class="form-group">
<label for="new-cat-title">New name of category</label><input value="';
if(isset($cat_title)){echo $cat_title;};
echo '" type="text" class="form-control" name="new-cat-title"></div>
<div class="form-group">
<input class="btn btn-primary" type="submit" name="submit" value="Rename Category">
</div>
</form>';
This echoes the two strings (in single quotes) and in between them the variable depending on the condition, keeping the double-quote pairs of the attribute values intact.
Echo is a php statement. You use it to display an output, as a string. What you need is, replacing echo ' with ?> and </form>'; with </form><?php. These closing(?>) and opening(<?php) tags let you decide which part of your document should be processed as PHP. So PHP will ignore the rest of the document.
Based on Johannes' answer I managed to figure out an answer. I need to close the PHP tags and instead of echoing the wished result, put it in the while loop.
Like this:
function update_category(){
global $connection;
if (isset($_GET['edit'])) {
$edit_cat_key = $_GET['edit'];
$query = "SELECT * FROM categories WHERE cat_id = {$edit_cat_key }";
$edit_cat_query = mysqli_query($connection, $query);
while($row = mysqli_fetch_assoc($edit_cat_query)) {
$cat_title = $row['cat_title'];
$cat_id = $row['cat_id'];
?>
<input value="<?php echo $cat_title; ?>" type="text" class="form-control" name="cat_title">
<?php
}
}
}
I Am trying to edit user details from a database. I have queried the database and stored the info in $row, but each time I try to echo the details I get the following error: Trying to access array offset on the value of type null in
C:\xampp\htdocs\merchant\admin\edituserhis.php
I seem not to know what I am doing wrong in the SQL statement, I have checked the Variable $id and its working well.
<div class="quotes">
<?php
$con = mysqli_connect("localhost","root","","merchant_db");
$id = $_REQUEST['username'];
$query = "SELECT * from user_trans where userid='".$id."'";
$result = mysqli_query($con, $query) or die ( mysqli_error());
$row = mysqli_fetch_assoc($result);
?>
<?php echo $row['userid']; ?>;
<form name="form" method="post" action="userprofile.php">
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['userid'];?>" />
<p><input type="text" name="balance" placeholder="Enter Amount" required value="<?php echo $row['description'];?>" /></p>
<p><input name="submit" type="submit" value="Credit" /></p>
</form>
</div>
Been trying to get this PHP to send to my database but for some reason it won't work but it isn't giving me any errors either. The code probably isn't the prettiest only been working on PHP for 6 months so any help is much appreciated.
<form method="POST">
<div class="form-group">
<label for="exampleFormControlSelect1">Send Message to: </label>
<select class="form-control" id="slectrecipient" name="recipient">
<?php
include("conn.php");
$info = "SELECT FirstName, SecondName, id FROM PT_accounts WHERE NOT id='$accountid'";
$result4 = $conn->query($info);
if(!$result4){
echo $conn->error;
}
while($row4 = $result4->fetch_assoc()){
$recipientfirst = $row4['FirstName'];
$recipientsecond = $row4['SecondName'];
$recipientid = $row4['id'];
echo "<option value='$recipientid'> $recipientfirst $recipientsecond</option>";
}
if(isset($_POST['messagetext'])){
$currentdate = date("Y-m-d H:i:s");
$messagetext = $_POST['messagetext'];
$recipid = $_POST['recipient'];
echo $currentdate;
echo $messagetext;
echo $recipid;
$messageinsert = "INSERT INTO PT_Messages (SenderID, RecipientID, Date, Message)
VALUES ('$accountid', '$recipid', '$currentdate', '$messagetext') ";
$result5 = $conn->query($messageinsert);
if(!$result5){
echo $conn->error;
}else{
echo "<p> $messageinsert</p>";
echo "<p>Message Sent!</p>";
}
}
?>
</select>
</div>
<div class="form-group">
<label for="exampleFormControlTextarea1">Message :</label>
<text class="form-control" id="messagetext" rows="3"></textarea>
</div>
<input type="submit" class="btn btn-primary btn-sm" value="Send">
</form>
I know there's two $row and $results but I've altered these in my actual to be different so I know that's not the issue. I'm unsure if it's the select tag with the option value that isn't written correctly. Or if I have to somehow set the dropdown menu selection as a PHP variable to then be sent to the database?
Thanks to user3783243
I didn't name the textarea but had set it as an id.
<input type="text" class="form-control" name="messagetext" id="messageid" rows="3">
I had it as id="messagetext"
Essentially, i'm trying to select all the users from my table where their type ='users' and if that condition is met, select their first and last name. Store them into variables and then display the variables into a dropdown list one by one(array).
Current code:
<div id="ContainerC">
<form action="AppointmentAddQuery.php" method="post">
<input type="text" name="date" class="datepicker" placeholder="Please select a date" required><br>
<input type="text" name="patient" class="textbox" placeholder="Patient" required> <br>
<?php
include 'dbconnection.php';
?>
<input type="text" name="phlebotomist" class="textbox" placeholder="phlebotomist" required> <br>
<input type="text" name="bloods" class="textbox" placeholder="blood required" required><br>
<p>Has the appointment been allocated?</p>
<select name="allocated" class="textbox" required>
<option value="yes">yes</option>
<option value="no">no</option>
</select>
<br><br><br>
<button type="submit" name="submit" class="SUB">Add patient</button>
</form>
</div>
SQL setup:
For the SQL part of your question, you are probably looking for something like:
select firstname
, lastname
from <table>
where type = 'user'
Assuming the structure of your database (you will likely need to replace table and column names) this is how you could do it:
<?php
include 'dbconnection.php';
$sql = "SELECT firstname, lastname FROM users WHERE type = 'users'";
$result = $conn->query($sql) or die($conn->error);
if ($result->num_rows > 0) {
echo '<select>';
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<option value="'.$row["firstname"].$row["lastname"].'">'.$row["firstname"].$row["lastname"].'</option>';
}
echo '</select>';
} else {
echo '<select><option value="">No Users</option></select>';
}
$conn->close();
?>
This also assumes that inside of dbconnection.php you created a mysqli object like so:
$conn = new mysqli($servername, $username, $password, $dbname);