So I have a variable, its called $comments.
but every time I do it I want it to break a line and echo out the new one I submit. Right now it just replaces the current one.
So everytime I click submit I would like it to make a NEW comments and not just write over the old one.
this is what I currently have, But everytime i hit submit it just overwrites the previous comment. I want it to break a line and display the next one without erasing teh previous
<?php
session_start();
if(isset($_POST['add'])){
$text = $_POST['content'];
$author = $_POST['author'];
$comment = $text. ',' .$author;
$_SESSION['cm'] = $comment;
echo '<b>';
}
?>
<!DOCTYPE>
<html>
<head>
<style>
body{
text-align: center;
margin: 10px 0 0 0;
}
.listing{
text-align: left;
border-top: 2px solid #000;
padding: 15px;
}
input{
font-size: 16px;
padding: 5px;
text-align: center;
}
input[type=submit]{
display: block;
margin: auto;
margin-top: 10px;
}
#gotolink{
position: absolute;
top: 15px;
right: 15px;
}
.listing > div{
max-width: 100%;
word-break: break-all;
}
</style>
</head>
<body>
<div id="gotolink"><button onClick='document.getElementById("bottom").scrollIntoView({block: "end", behavior: "smooth"});'>Scroll to bottom</button></div>
<p>Try and stay</p>
<p>Creating new test</p>
<form action="" method="POST">
<input type="text" name="content" placeholder="Text">
<input type="text" name="author" placeholder="Name">
<input type="submit" value="Submit" name="add">
</form>
<div class="listing">
<?php echo '<div>' .$_SESSION['cm']. '</div>'; ?>
</div>
<div id="bottom"></div>
</body>
</html>
$_SESSION['cm'] = $comment;
Replace with:
$_SESSION['cm'] .= $comment."<br>";
Related
I have a web page which displays data on the left side of the page and it goes down in a list.
I need help displaying a form in the middle/right side of the page using CSS. With the current CSS I have for the form, it is displayed at the bottom of the page which is wrong, I want it to be in the middle/right. The form is basically a search field where users can search for members on the website.
I'm bad with CSS, maybe someone can also suggest a cool style for the form? :D
The div class called searchList is where the form is that I want to align to the middle/right
My code:
<?php
include('init.inc.php');
$output = '';
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq); //filter, can remove
$query = mysql_query("SELECT * FROM users WHERE user_first LIKE '%$searchq%' OR user_last LIKE '%$searchq%' OR user_uid LIKE '%$searchq%'");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'There was no search found!';
}else{
while($row = mysql_fetch_array($query)){
$uname = $row['user_uid'];
$fname = $row['user_first'];
$lname = $row['user_last'];
$email = $row['user_email'];
$id = $row['user_id'];
$output .= '<div> '.$uname.' '.$fname.' '.$lname.' '.$email.'</div>';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C/DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns=""http://www.w3.org/1999/xhtml>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" href="./css/style.css">
</head>
<body>
<section id="showcase1">
<section id="newsletter">
<div class="container">
<h1>ProjectNet Members:</h1>
</div>
</section>
<div class="container">
<div class="userList">
<?php
foreach (fetch_users() as $user){
?>
<p>
<button><a class="userList" href="profile.php?uid=<?php echo $user['id']; ?>"><?php echo $user['username']; ?></a></button>
</p>
<?php
}
?>
</div>
</div>
<div class="searchList">
<form id="search" action="user_list.php" method="post">
<input type="text" name="search" placeholder="Search for members..." />
<input type="submit" value="Search" />
</form>
<?php print("$output");?>
</div>
</section>
</body>
</html>
CSS:
.searchList {
color: #ffffff;
text-decoration: none;
font-weight: bold;
font: 20px Arial, Helvetica,sans-serif;
text-align: center;
}
UPDATE:
I managed to get the form in the middle of the screen, I need help moving it slightly towards the right.
CSS:
.searchList {
color: #ffffff;
text-decoration: none;
font-weight: bold;
font: 19px Arial, Helvetica,sans-serif;
text-align: center;
left: 0;
line-height: 35px;
margin: auto;
margin-top: -100px;
position: absolute;
top: 50%;
width: 100%;
float: right;
}
#search input[type="submit"] {
cursor: pointer;
border: none;
background: #fafafa;
color: #333;
font-weight: bold;
margin: 0 0 5px;
padding: 3px;
font-size: 15px;
font: Arial, Helvetica,sans-serif;
}
#search input[type="text"] {
width: 18%;
border: 1px solid #CCC;
background: #FFF;
margin: 0 0 5px;
padding: 4px;
}
}
#search input[type="submit"]:hover {
background: #e8491d;
color: #fafafa;
-webkit-transition: background 0.3s ease-in-out;
-moz-transition: background 0.3s ease-in-out;
transition: background-color 0.3s ease-in-out;
}
Use CSS position property or float property.
To display form on the right of the page use float : right;
form {
float : right;
}
Moving to the right, where the 4th value is the left padding.
padding: 0px 0px 0px 30px;
..alternatively you can use.
padding-left: 30px;
If you want to have better control of the layout structure I suggest you use "grid" which is embedded in css. Search for "css grid".
This works good with out a loop but with a loop the first one works but the second one can't set a PHP session value like the first one so how can I get the loop copy to work like the first one meaning being able to set a PHP session value.
*NOTE: THIS IS NOT A HTML FORM THIS IS COSTUME CODE THAT me and my friend MADE FROM a tutorial THAT ACTS LIKE A FORM TO SET A SESSION VALUE.*
tutorial source: https://www.formget.com/submit-form-using-ajax-php-and-jquery/#
I don't want to use a form don't ask me why it's personal so how can I fix this where the loop copy can also set a session value of a session variable i'm saying this because only the first one is able to do that and the second one can't set a session value like the first one.
.gif Screenshot
code
submit_session.php
<?php
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>Simulated Form</title>
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
//This section converts the HTML id's in the form div into form values
$(document).ready(function(){
$("#execute").click(function(){
var execute= $("#execute").val();
var name= $("#name").val();
var age= $("#age").val();
var dataString = 'execute='+ execute + '&name='+ name + '&age='+ age;
//AJAX code to submit the simulated form.
$.ajax({
type: "POST",
url: "submit_session.php",
data: dataString
});
});
});
</script>
<style>
.form {
background-color: gold;
width: 200px;
margin: auto;
border-radius: 5px;
padding-top: 5px;
}
.set-value{
background: blue;
padding: 1px 4px;
text-decoration: none;
border: 1px solid gray;
color: white;
margin: auto;
display: block;
width: 100px;
text-align: center;
border-radius: 5px;
}
.name-input {
margin: auto;
display: block;
}
.age-input {
margin: auto;
display: block;
}
</style>
</head>
<body>
<?php
//Generate more than one copy of the simulated form
for ($loop = 0; $loop <= 1; $loop++) {
?>
<br>
<!--The simulated form-->
<div class="form">
<p style='text-align: center;'>Simulated form</p>
<input type="text" id="name" class='name-input' required="required" placeholder='Name' autocomplete="off">
<br>
<input type="text" id="age" class='age-input' required="required" placeholder='Age' autocomplete="off">
<br>
<!-- Simulated form submit button -->
<a class="set-value" id="execute" href="view-session-values.php">Set value</a>
<br>
</div>
<?php
echo $loop;
}
//Set session values from a simulated form
if(isset($_POST['execute'])){
$name = $_POST['name'];
$age = $_POST['age'];
if($check=1){
$_SESSION['name']=$name;
$_SESSION['age']=$age;
echo "<script>window.open('_self')</script>";
}
}
?>
</body>
</html>
view-session-values.php
<?php
session_start();
$name = $_SESSION['name'];
$age = $_SESSION['age'];
?>
<!DOCTYPE html>
<html>
<head>
<style>
#set-new-session-value {
background-color: black;
color: white;
padding: 5px 5px;
text-decoration: none;
border-radius: 5px;
}
#destroy-session-value{
background-color: black;
color: white;
padding: 5px 5px;
text-decoration: none;
border-radius: 5px;
}
</style>
</head>
<body>
<!--This section is based on choosing session options -->
<br>
<a id='set-new-session-value' href="submit_session">Set new session value</a>
<a id='destroy-session-value' href="destroy_session.php">Destroy session value</a>
<br>
<!--This section is where the set session values are shown-->
<p><?php echo $name; ?></p
<p><?php echo $age; ?></p>
</body>
</html>
This question has been asked alot so I found this article Allowing users to Refresh browser without the "Confirm Form Resubmission" pop-up
And I follow what it said but now i'm getting this message 500: Internal Error.
So what i'm I doing wrong here? I basically want be able to refresh a page with out getting greeted with this message
Confirm For Resubmission
The page that you're looking for used information that you entered. Returning to that page might cause any action you took to be repeated. Do you want to continue?
because of a form and I all so checked this out to Preventing form resubmission
I try to understand these guys answers but i'm still not getting something right if any one can show me the two so called poplar methods mentioned in the links by using the PHP method or the AJAX with jQuery method to prevent that confirm for resubmission message I will really appreciate that. Please I prefer code solutions based on my code as answers because I personally learn best that way thank you.
GIF Screenshot
code
index.php
<!DOCTYPE html>
<html>
<head>
<style>
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'Nunito', sans-serif;
color: #384047;
}
form {
max-width: 300px;
margin: 10px auto;
padding: 10px 20px;
background: gold;
border-radius: 8px;
}
h1 {
margin: 0 0 30px 0;
text-align: center;
}
input[type="text"] {
background: rgba(255,255,255,0.1);
border: none;
font-size: 16px;
height: auto;
margin: 0;
outline: 0;
padding: 15px;
width: 100%;
background-color: white;
color: black;
box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
margin-bottom: 30px;
}
button {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: blue;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid blue;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
cursor: pointer;
}
label {
display: block;
margin-bottom: 8px;
}
label.light {
font-weight: 300;
display: inline;
}
</style>
</head>
<body>
<form action='x.php' method='POST'>
<h1>Form</h1>
<label for='name'>Name</label>
<input type='text' id='name' name='name' value='Tom'>
<label for='age'>Age</label>
<input type='text' id='age' name='age' value='20'>
<button type='submit'>Send</button>
</form>
</body>
</html>
x.php
<?php
if($_SERVER['REQUEST_METHOD'] == "POST"){ header('x.php'); }
$name = $_POST['name'];
$age = $_POST['age'];
?>
<p><?php echo $name; ?></p>
<p><?php echo $age; ?></p>
I changed your code a bit, but should produce the result that you want
<?php
if(isset($_POST['submit'])){
header('Location: x.php?successfulRedirect');
exit;
}
?>
<form action='' method='POST'>
<h1>Form</h1>
<label for='name'>Name</label>
<input type='text' id='name' name='name' value='Tom'>
<label for='age'>Age</label>
<input type='text' id='age' name='age' value='20'>
<input type='submit' name='submit' value='Send' />
</form>
This will make sure that you will be redirected to x.php after clicking Send, with a GET parameter it in, just to see that the redirection works
I'm trying to create sms floader and i have created the two following php files but when ever the user entered his mobile number its redirecting to another external website and please help me on how to get input from user to loop the same code for several times. like if the user they enter his mobilenumber and loop value to 10 times it should send 10 sms to destination number
sms.php
<html>
<head>
<meta charset="utf-8">
<title>TrickzTracking | SMS Floader</title>
<meta name="author" content="Nandan T Rsn" />
<meta name="keyword" content="sms bomber,sms bomber 2016,working sms bomber,trickztracking sms bomber,unlimited sms bomber,anonymous sms bomber" />
<meta name="description" content="Free SMS Bomber | TrickzTracking" />
<meta name="contact" content="TrickzTracking#Gmail.com" />
<meta name="copyright" content="Copyright (c)2015-2016
TrickzTracking. All Rights Reserved." />
<style>
body {
background: #3b5998;
font-family: 'Lato', sans-serif;
color: #FDFCFB;
text-align: center;
}
#id1{
color: #000000;
}
input{
margin: 5px;
}
.input{
margin: 5px;
}
form {
width: 500px;
margin: 17% auto;
margin-top:90px;
}
.header {
font-size: 35px;
text-transform: uppercase;
letter-spacing: 5px;
}
.description {
font-size: 20px;
letter-spacing: 1px;
line-height: 1.3em;
margin: -2px 0 45px;
}
.button {
padding: 10px;
height: 44px;
border: none;
}
#email,#number,#message,#times {
width: 70%;
background: #FDFCFB;
font-family: inherit;
color: #737373;
letter-spacing: 1px;
text-indent: 5%;
border-radius: 5px 0 0 5px;
}
#submit {
width: 31%;
padding: 10px;
height: 46px;
background: #E86C8D;
font-family: inherit;
font-weight: bold;
color: inherit;
letter-spacing: 1px;
border-radius: 0 5px 5px 0;
cursor: pointer;
transition: background .3s ease-in-out;
}
#submit:hover {
background: #d45d7d;
}
input:focus {
outline: none;
outline: 2px solid #E86C8D;
box-shadow: 0 0 2px #E86C8D;
}
</style>
<link href="http://fonts.googleapis.com/css?family=Lato:400,700"rel="stylesheet" type="text/css">
</head>
<body>
<form action="sms_api.php" method="post" name="SMS Floader">
<div class="header">
<p>Bomb your friends</p>
</div>
<div class="description">
<p>Now, you can bomb your Friends number by simply using their numbers in the below form </p>
</div>
<div class="input">
<input type="text" class="button" id="number" name="num" placeholder="XXXXXXXXXX" maxlength="10" value="">
<button type="submit" class="button" onclick="submit">Start</button>
</div>
<div class="">
<h4> Terms And Conditions : </h4>
</div>
<div class="description">
<p id="id1">1. Don't Try To Fload On Unknow Person's. </p>
<p id="id1">2. Send Only Maximum Of 50 SMS On The Go.</p>
<p id="id1">2. Your IP Will Be Logged For Security Purpose.</p>
<p>Powered By: www.TrickzTracking.com</p>
</div>
</form>
</body>
</html>
sms_api.php
<html>
<script type="text/javascript">
function submit(myForm){
document.myForm.submit();
}
</script>
<body onLoad="javascript:submit(myForm)">
<form action="http://www.some-other-website.com/sms/api.php" method="post" name="myForm">
<input type="hidden" name="type" value="0">
<input type="hidden" name="message" value="102310">
<input type="hidden" name="num" value="<?php echo $_POST['num'] ?>">
<input name="hidden" type="submit">
</form>
</body>
</html>
Ps: when ever sms.php send post data to sms_api.php its redirecting it to http://www.some-other-website.com/sms/api.php instead i want that to redirect to sms.php after posting data to http://www.some-other-website.com/sms/api.php
I'm new to php please help me :D
You are using a on load submit function, which will submit the form as soon as the
sms_api is called. The coding format is wrong and so is the concept. You should try making a single form rather than trying to complex the code. Keep it simple.
whenever i try to create a new txtfile using create button although the file get create but the data is not written into the file. i just het a blank file. what is the error ?
<?php
error_reporting(0);
if(isset($_POST['sub']))
{
$fname=$_POST["txtfile"];
$cont=$_POST['txtarea'];
if($_POST['sub']=="create")
{
fopen($fname,"w");
fwrite($fname, $cont);
}
else if($_POST['sub']=="read")
{
echo file_get_contents($fname);
}
else if($_POST['sub']=="delete")
{
unlink($fname);
}
else if($_POST['sub']=="append")
{
$cont=$_POST['txtarea'];
$fp=fopen($fname,"a");
fwrite($fp,$cont);
}
}
?>
here is the html code of above program. should i insert the php code for reading the file into the textarea code in html.?
<!DOCTYPE html>
<html>
<h3>file handling concept</h3>
<style type="text/css">
#form{
height: 200px;
width: 400px;
margin: 10px;
}
label {
float: left;
margin-right: 10px;
width: 70px;
padding-top: 5px;
font-size: 15px;
}
#form input, #form textarea{
padding: 5px;
width: 306px;
font-family: Helvetica, sans-serif;
font-size: 15px;
margin: 0px 0px 0px 0px;
border: 2px solid #ccc;
}
#button input{
float: right;
margin: 5px;
width: 60px;
padding: 5px;
border: 1px solid #ccc;
}
</style>
<div id="form">
<form method="POST" action="filehandling.php">
<label for="name">Filename:</label>
<input type="text" name="txtfile" placeholder="file-name.txt" />
<label for="name">content:</label>
<textarea name="txtarea" placeholder="write some content">
</textarea>
<div id="button">
<input type='submit' name='sub' value='create'>
<input type='submit' name='sub' value='delete'>
<input type='submit' name='sub' value='append'>
<input type='submit' name='sub' value='read'>
</div>
</form>
</div>
</html>
Your file creation and writing method should be as follows:
if($_POST['sub']=="create")
{
$fp = fopen($fname,"wb");
fwrite($fp,$cont);
fclose($fp);
}
I think you should use handle while creating the file too like below.
if($_POST['sub']=="create")
{
$fh = fopen($fname,"w");
fwrite($fh, $cont);
fclose($fh);
}
Also in else if($_POST['sub']=="append") there is no need to define $cont again as its already define with the same value.
so
else if($_POST['sub']=="append")
{
$cont=$_POST['txtarea'];
$fp=fopen($fname,"a");
fwrite($fp,$cont);
}
becomes
else if($_POST['sub']=="append")
{
$fp=fopen($fname,"a");
fwrite($fp,$cont);
fclose($fp);
}