This question already has answers here:
php mysql storing line breaks in text area in database
(4 answers)
Closed 3 months ago.
i'm writing simple program that allow user to write their contents and post them
i'm using php ,html,css and mysql database
assume user has written a content in this format
i know codes written in php will allow user to post and store contents in database
i will use <?php echo $row['content']; ?> to display content posted by the user
but contents are not displayed in similary format as it was written by the use in paragraph formats(in format of more than one paragraph),insetad it display like this
Python datatypes.....To get Python handwritten notes, visit the link in the bio.....Visit our site for free project source codes-- copyassignment.com.....Turn on post notifications for more such posts like this.....Follow #python.hub for more content on computer science,
what's the good idea on this problem ? how can i solve it so that contents should be displayed as it is written by the user,,,
any help will be appreciated
<?php
require_once 'dbconfig.php';
if(isset($_POST['btnsave']))
{
$content = $_POST['content'];// user email
$stmt = $DB_con->prepare('INSERT INTO template(content) VALUES(:content)');
$stmt->bindParam(':content',$content);
$stmt->execute();
}
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bootstrap demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-Zenh87qX5JnK2Jl0vWa8Ck2rdkQ2Bzep5IDxbcnCeuOxjzrPF/et3URy9Bv1WTRi" crossorigin="anonymous">
</head>
<body>
<div class="container">
<div class="row">
<div class="col-lg-4">
<form method="post">
<div class="mb-3">
<label for="exampleFormControlTextarea1" class="form-label">Description</label>
<textarea class="form-control" id="exampleFormControlTextarea1" rows="3" name="content"></textarea>
</div>
<button type="submit" name="btnsave">ok</button>
</form>
<div>
<div>
<div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.2.2/dist/js/bootstrap.bundle.min.js" integrity="sha384-OERcA2EqjJCMA+/3y+gxIOqMEjwtxJY7qPCqsdltbNJuaOe923+mo//f6V8Qbsw3" crossorigin="anonymous"></script>
</body>
</html>
<?php echo nl2br($row['content']); ?>
Use nl2br to convert Input/textarea linebreaks to real html linebreaks (br).
Related
The question I'm trying to answer is below
Create a new PHP file named lab2.php.
Inside, add the HTML skeleton code and give its title “Lab Week 2"
Within the body tag, create a h1 tag that says "Enter the name of your favourite musical artist"
Add a section tag inside the body tag.
Create a form tag and use the $_GET method to get users to input their favorite artist. Store the user input into variables.
Create a submit button for the user to input their favorite artist.
Check whether the variable is empty or not.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title> Fav Artist</title>
<meta name="author" content="Sean Kingston">
<meta name="viewport" content="with=device-width, initial-scale=1.0">
</head>
<body>
<!-- H1 tag I want to change once the user clicks on submit button-->
<h1> Enter the name of your favourite musical artist </h1>
<!--Form-->
<form method="get">
<input type="text" name="name" />
<input type="submit" value="Submit" name="sub">
</form>
</body>
</html>
<?php
//isset not working//
if(isset($_GET['name'])){
echo $_GET['name'];
}
?>
<?php
show_source(FILE);
</html>
?>
i'm gonna hazard a guess and asume that this is some sort of educational task.
but nevertheless here is how i understand the tasks.
<?php
//1.Create a new PHP file named lab2.php.
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Lab Week 2</title><!-- 2.Inside, add the HTML skeleton code and give its title “Lab Week 2" -->
</head>
<body>
<h1><?php
// 5. use the $_GET method to get users to input their favorite artist. Store the user input into variables.
$favouriteMusicalArtist = $_GET['favourite_musical_artist'];
// 7.Check whether the variable is empty or not.
if (empty($favouriteMusicalArtist)) {
//3.Within the body tag, create a h1 tag that says "Enter the name of your favourite musical artist"
echo 'Enter the name of your favourite musical artist';
} else {
echo 'Your favourite musical artist is: ' . $favouriteMusicalArtist;
}
?></h1>
<!-- 4.Add a section tag inside the body tag. -->
<section>
<!-- 5.Create a form tag -->
<form method="GET">
<input type="text" name="favourite_musical_artist"/>
<!-- 6.Create a submit button for the user to input their favorite artist. -->
<button type="submit">Submit</button>
</form>
</section>
</body>
</html>
Now if this is some sort of test don't just copy of the internet. Do some fiddling around with the code and try to learn something :-)
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have created two pages , one is index.php and admin.php . In the first page or index.php , i have created a loggin form so that i can access the admin.php page trough the loggin or like this enter image description here
Now by logging in i go to admin.php page. Here is the question what i want to ask about that now when ever i click the back button or next button in the chrome. I am returning to the admin.php page . I have tryed the session_start() and the if(!isset($password) || !isset($user)){}. But this code for obvious reasons doesnt work . So can someone help me out with this ?
The code for the example is here index.php
<?php
session_start();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Admin</title>
</head>
<body>
Reset
<div class="image">
<img src="img/adi.png" alt="image"> <!-- image -->
</div>
<form action="inc/login.php" method="POST"><br>
<p class="title">Log In</p>
<label for="Username">User :</label>
<input type="text" name="username" id="user"> <br> <!--username -->
<label for="Password">Password :</label>
<input type="password" name="password" id="password" ><br><br> <!-- password -->
<label for="showpassword" class="showpassword">Show Password</label>
<input type="checkbox" name="checkbox" id="chk" ><br><br> <!-- checkbox -->
<input type="submit" name="submit" value="Log in" > <!-- enter -->
</form>
<?php
if(!isset($_GET['Login'])){
exit();
}else{
$check=$_GET['Login'];
if($check=="userEmpty"){
echo "<p class='class_login'>user is empty</p> ";
}elseif($check=="passwordEmpty"){
echo "<p class='class_login'>password is empty</p> ";
}elseif($check=="wrongUser"){
echo "<p class='class_login'>user is wrong</p> ";
}elseif($check=="Password"){
echo "<p class='class_login'>password is wrong</p> ";
};
} ;
?>
<script src="js/main.js"></script>
</body>
</html>
and the code for the admin.php is this one :
<?php
session_start();
if(!isset($username) || !isset($password)){
header("location:index.php?data=closed");
exit();
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<script>
window.history.forward();
</script>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<title>Document</title>
</head>
<body>
<div class="top">
Log Out
</div>
</body>
</html>
Besides using of session_start you need to store something in the session, using something like this:
$_SESSION['userId'] = <value>;
which must be set in your login.php and checked by your admin.php if user has access rigths to visit secured page. I.e. you need to check:
if (isset($_SESSION['userId']) && $_SESSION['userId'] == <value>) {
// access granted
}
I have been searching all over the net looking for an answer and I've been able to piece things together, however I am trying to create an HTML/PHP page for the user to submit an entry into a contest via a website link or attached pic/vid. I also have a drop down menu to choose which category it's for.
What I'd like to do is have the drop down menu selection included in the body of the email as well as their website link. Unfortunately I'm at a loss for how to accomplish this. I'm good when it comes to HTML, however I only have a basic understanding of PHP. I found an email form template of HTML and PHP that allows for an attachment, but I cannot figure out for the life of me how to add the selection from the drop down into the body of the email that I added to the HTML code.
Can anyone assist?
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>HTML5 Contact Form With File Upload - reusable form</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<link href="https://fonts.googleapis.com/css?family=Montserrat" rel="stylesheet">
<link rel="stylesheet" href="form.css" >
<script src="form.js"></script>
</head>
<body >
<div class="container">
<div id="form-main">
<div id="form-div">
<form class="montform" enctype=""multipart/form-data"" id="reused_form">
<p class="name"><input class="feedback-input" id="name" name="name" placeholder="Name" required="" type="text" /></p>
<p class="email"><input class="feedback-input" id="email" name="email" placeholder="Email" required="" type="text" /></p>
<p><select name="category">
<option selected="selected" value="Best Static">Best Static</option>
<option value="Best Animatronic">Best Animatronic</option>
<option value="Best Display">Best Display</option>
<option value="Best Walk Through">Best Walkthrough</option>
<option value="Best Hauntcycled">Best Hauntcycled</option></select></p>
<p class="text"><textarea class="feedback-input" id="comment" name="message" placeholder="Message"></textarea></p>
<p class="file"><input class="feedback-input" id="file" name="image" type="file" /></p>
<div class="submit"><button class="button-blue" type="submit">SUBMIT</button>
<div class="ease"> </div>
</div>
</form>
<div id="error_message" style="height: 100%; width: 100%; display: none">
<h4>Error</h4>
Sorry there was an error sending your form.</div>
<div id="success_message" style="height: 100%; width: 100%; display: none">
<h2>Success! Your Message was Sent Successfully.</h2>
</div>
</div>
</div>
</div>
</body>
</html>
And now for the PHP that was included with the code I found online:
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
/*
Tested working with PHP5.4 and above (including PHP 7 )
*/
require_once './vendor/autoload.php';
use FormGuide\Handlx\FormHandler;
$pp = new FormHandler();
$validator = $pp->getValidator();
$validator->fields(['name','email'])->areRequired()->maxLength(50);
$validator->field('email')->isEmail();
$validator->fields(['message','category'])->maxLength(6000);
$pp->attachFiles(['image']);
$pp->sendEmailTo('someone#gmail.com'); // ← Your email here
echo $pp->process($_POST);
The piece of code you have found is for laravel. You need to understand how PHP works first to learn any PHP framework like laravel works.
Visit: https://www.w3schools.com/php/php_forms.asp
Learn how to pass values from one page to another, catch form data and run SQL queries using passed data.
You can check for any php registration example to understand that. I would recommend you to learn the PHP SQL Object oriented approach then PHP PDO.
Issues with code:
1. Your form does not have any action and method
2. You PHP does not catch data (becuase laravel use request classes to auto validate and store data)
I'm trying to convert HTML To PDF, by copying the whole HTML in the textarea. I've tried all the examples shown in this question without solving the problem. Why is this happening? Here's my main php file:
<?php
use Dompdf\Dompdf;
require 'vendor/autoload.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
<title>PDF Converter</title>
</head>
<body>
<div style="text-align: center;">
<form method="POST">
<div class="form-group">
<label for="convert">Paste Your HTML Code here ; )
<hr>
<textarea name="htmlCode" class="form-control" rows="10" placeholder="<body>Example..</body>">asd</textarea>
</label>
</div>
<input class="btn btn-primary" type="submit" value="Convert To PDF" name="convert">
</form>
<?php
if (isset($_POST['convert'])) {
$dompfd = new Dompdf();
$html = htmlspecialchars($_POST['htmlCode']);
$dompfd->loadHtml($html);
$dompfd->setPaper('A4', 'landscape');
$dompfd->render();
$dompfd->stream();
}
?>
</div>
</body>
</html>
You output HTML, therefore headers have sent saying it's text/html.
Move your PHP to the top of the script above all HTML and it should work!
exit(); after calling the stream() method too.
form.php
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="lib/jmobile/jquery.mobile-1.4.5.min.css">
<script src="lib/jmobile/jquery.js"></script>
<script src="lib/jmobile/jquery.mobile-1.4.5.min.js"></script>
<head>
<body class="ui-page-theme-a">
<div data-role="page">
<div role="main" class="ui-content">
<form action = "aksi.php" method = "post">
<input type="text" name="cari" placeholder="cari informasi...">
<input type="submit" value="PROSES">
</form>
</div>
</div>
</body>
</html>
aksi.php
<?php
$lihat = $_POST['cari'];
echo $lihat;
?>
Why aksi.php cannot get value from form.php ?
if i cannot include jquery mobile that script it's working well.
JQuery Mobile will post the form via AJAX unless you add the data-ajax="false" to your form. So your PHP should be getting the Posted data under $_POST['cari'].
Tested in JSFiddle with both.
data-ajax="true" - http://jsfiddle.net/Twisty/mco3uben/
data-ajax="false" - http://jsfiddle.net/Twisty/mco3uben/1/
If you review your Console for the first, you will see a new HTTP request is posted to the action and the response echo'd back by jsfiddle. The second brings you to a new page and echos the entry.
Both should work as you have it configured. You may want to add some HTML to your PHP to allow JQM to hook into it:
<?php
$lihat = $_POST['cari'];
echo "<html><body><div data-role='page'><div role='main' class='ui-content'>\r\n";
echo $lihat;
echo "</div></div></body></html>";
?>