I've tried to make a comment system, by using fwrite() code. It works but I want my latest comments to list on top of the list.
Here is my code which works but it doesn't work the way I want. Latest comments appears under the list :((
<?php
if ($_POST){
$name = $_POST['name'];
$content = $_POST['commentcontent'];
$date = date("Y-m-d H:i:s");
$handle = fopen("comments.html","a");
fwrite($handle,"<b>" . $name . "<b> (" .$date . ") </b>" ."</b>:</br>" . $content . "</br>");
fclose($handle);
}
?>
<html>
<body>
<form action="" method="POST">
Comments: <textarea rows="10" cols="30" name="commentcontent"/></textarea></br>
Name: <input type="text" name="name"></br>
<input type="submit" value="post!"></br>
<?php include"comments.html";?>
</form>
</body>
</html>
Related
My Goal is to insert the value from a textbox from a form to csv one by one.
I tried to look for answers in the internet but I can't seems to find similar scenario on this problem
<?php
if(isset($_POST['submit']))
{
//read data from form
$lName = filter_input(INPUT_POST, "lName");
$fName = filter_input(INPUT_POST, "fName");
$email = filter_input(INPUT_POST, "email");
$phone = filter_input(INPUT_POST, "phone");
//generate output for text file
$output = $fName . " ";
$output .= $lName . " ";
$output .= $email . " ";
$output .= $phone . " ";
//here "t" means tab
//here "n" newline
//open file for output with append mode "a"
$fp = fopen("contacts.csv", "a");
//write to the file
fwrite($fp, $output);
fclose($fp);
}
else
{
echo "empty submit";
}
?>
<html>
<head>
</head>
<body>
<form action="next_page.php" method="post" >
Lastname:<input type="text" name="lName" />
Firstname:<input type="text" name="fName" />
Email:<input type="text" name="email" />
Phone:<input type="text" name="phone" />
<input type="submit" name="submit" value="submit" />
</form>
</body>
</html>
My expected output is Lastname will be save in first cell, Firstname will be saev in 2nd cell, and so on.
A comment posting tutorial for a guestbook type situation I watched on the internet works fine for many others but for me I keep having
" . $name. ":
" . $content . "
"); fclose ($handle); } ?>
appear above the comment box. Also it does not post anything after doing all that in php. Here is the code:
<?php
if($_POST){
$name = $_POST ['name'];
$content = $_POST ['commentcontent'];
$handle = fopen("JackPackNetwork.html","a");
fwrite ($handle, "<b>" . $name. "</b>:<br/>" . $content . "<br/>");
fclose ($handle);
}
?>
<html>
<head>
</head>
<body>
<form action="" method= "POST">
Comments: <textarea rows= "10" cols= "30" name= "commentContent"></textarea> <br/>
Name: <input type= "text" name = "name"> <br/>
<input type= "submit" value = "Post!"> <br/>
</form>
<?php include "JackPackNetwork.html"; ?>
</body>
</html>
Specifically I want to link to JackPackNetwork.html and update the comments with the ability of someone being able to put their name on it as well. Thanks for your time and consideration.
Your code should look like this:
<?php
if($_POST){
$name = $_POST ['name'];
$content = $_POST ['commentContent'];
$handle = fopen("JackPackNetwork.html","a");
fwrite ($handle, "<b>" . $name. "</b>:<br/>" . $content . "<br/>");
fclose ($handle);
}
?>
<html>
<head>
</head>
<body>
<form action="" method= "POST">
Comments: <textarea rows= "10" cols= "30" name= "commentContent"></textarea> <br/>
Name: <input type= "text" name = "name"> <br/>
<input type= "submit" value = "Post!"> <br/>
</form>
<?php require_once("JackPackNetwork.html"); ?>
</body>
</html>
MISTAKE
array index are case sensitive so $content post request fetch should be done correctly.
Suggestion
Use require_once() instead of include().
Hello Im having an issue with the website I am creating for a project. Everytime I upload it to aws elastic beanstalk it works except when I use a form.
<form action="supply.php" method="POST">
Product Name: <input type="text" name="p_name"><br>
Order Qty: <input type="text" name="ord_qty"><br>
Name: <input type="text" name="user_name"><br>
Address: <input type="text" name="address"><br>
<input type="submit" name="submit" value="Submit"> <input type="reset">
</form>
this is my form and here is my supply.php where I get the 500 error
<html>
<body>
<h1>Thank you for your order. <? php echo $_POST["user_name"]; ?><br></h1>
<form action="order.php">
<input type="submit" value="Go to Orders">
</form>
<?php
$p_name = $_POST['p_name'];
$ord_qty = $_POST['ord_qty'];
$name = $_POST['user_name'];
$address = $_POST['address'];
$string = $p_name. "," . $ord_qty. "," . $name. "," . $address;
$file = "order.txt";
file_put_contents($file,$string . "/n", FILE_APPEND);
?>
</body>
</html>
Is there something wrong? I can't see any issues and its driving me crazy
<? php echo $_POST["user_name"]; ?>
You have a space in the first opening php tag
Try:
<?php echo $_POST["user_name"]; ?>
This was enough to break a simple test page I set up, let me know if you're still experiencing problems.
I want to show the changes made in current file after submitting form as message without alert and confirm.How can I do this?
I update language with:
$query="update `account_detail` set `prompt_language`= '$language' WHERE `org_id`='".$_SESSION['account_id']."'";
$result = $mysqli->query($query) or die($mysqli->error);
$Msg="updated language to $language";
function logToFile($filename, $msg)
{
$fd = fopen($filename, "a");
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
fwrite($fd, $str . "\n");
fclose($fd);
}
logToFile("change.log", "updated language to $language");
header("location:".SITE_URL."index.php?view=view_service");
I put all cheanges made in file.And also want to show as message.
Something along the lines of:
<?PHP
if(isset($_REQUEST['something']))
{
echo('you made some changes...');
}
else
{ ?>
<form method="POST">
<input name="something" type="text" />
<!-- rest of code here... -->
<button type="submit">
</form>
<?PHP
}
?>
The logic being, if the variable has been set (i.e. the form has been submitted) then echo out a message to the page, othewise display the form.
try something like this:
your view page:
<body>
<div id="message"><?PHP
if(isset($_REQUEST['msg']))
{
echo $_REQUEST['msg'];
}
?>
</div>
<form method="POST" action="submit.php">
<input name="language" type="text" />
<!-- rest of code here... -->
<button type="submit" >SUBMIT</button>
</form>
</body>
your submit.php
<?php
if(isset($_POST['language'])){
$msg=array();
$language=$_POST['language'];
$Msg="updated language to $language";
logToFile("change.log", "updated language to $language");
////yor rest pf the code
header("location:view1.php?view=view_service&msg=".$Msg);
}
function logToFile($filename, $msg)
{
$fd = fopen($filename, "a");
$str = "[" . date("Y/m/d h:i:s", mktime()) . "] " . $msg;
fwrite($fd, $str . "\n");
fclose($fd);
}
?>
I cannot seem to retrieve the data input into this text area. Also I know this code may not be secure, but I am just beginning with php.
echo '<tr><td align=right>Description:</td><td><textarea name=description form=description cols=100 rows=5></textarea></td></tr>';
$descriptionToSend = $("#description").val()
DBSubmit("INSERT INTO Conference (conferenceid,description,submission_due,review_due) VALUES ('".$_POST['conferenceName']."', '" . $descriptionToSend . "','" .$_POST['submitdeadline'] . "','" .$_POST['reviewdeadline']. "')");
Are you mixing up jquery with php ?
First, the <textarea> should reside in a <form>
After the form is submitted to php, you can access the data sent with $_REQUEST['description'] so you would have
$descriptionToSend = $_REQUEST['description'];
<html>
<head>
<title>Test</title>
</head>
<body>
<?php $name = 'nick';
?>
<form action="Test.php">
Name: <input type="text" name="name" value="<?php echo $name; ?>">
About Me: <textarea name="about" rows="5" cols="10"><?php echo $comment; ?></textarea><br/>
Click Me: <input type="submit" vaule="submit">
</body>
</html>
Use $comment to set text and then just retrieve value using $_GET['about'] in next page
<html>
<body>
<?php
$about = $_GET['about'];
echo $about;
?>
</body>
</html>