PHP form not submitting to the next page - php

The landing page has form but it is not submitting and not redirecting to the next page.After submitting the form, it stays on the same page.
It was alright and was working before but I cant figure out where is the problem.
Code in formPage.php is below:
<form action="insert.php" enctype="multipart/form-data" class="contact_form" method="post" name="htmlform" >
<input class="frm-input" name="name" type="text" size="30" maxlength="50" placeholder="Enter Name" required="required" />
<input class="frm-input" name="email" type="text" size="30" maxlength="80" placeholder="Enter Email" required="required"/>
<input class="frm-input" name="jobtype" type="text" size="30" maxlength="30" placeholder="Job Type" required="required"/>
<input class="frm-input" name="ent_type" type="text" size="30" maxlength="80" placeholder="Entity Type" required="required"/>
<input class="frm-input" name="tas_out" type="text" size="30" maxlength="80" placeholder="Task Outline" required="required"/>
<input class="frm-input" name="l_st" type="text" size="30" maxlength="80" placeholder="Logo style of interest (optional)" />
<textarea required="required" class="frm-input frm-txtarea" name="message" placeholder="Task Description!!" maxlength="1000" cols="25" rows="6" ></textarea>
<input style="float: left;" type="file" name="image" size="66"/>
<input type="submit" class="btn btn-success btn-lg" name="submitt" value="submit" style="float: right" />
</form>
In this file I am trying to get the form information and storing them in database.But this page is not loading after the form submission.
Code in insert.php is below:
<?php
/*
$name = "";
$text = "";
$post = "";
*/
//echo $name;
if (isset($_POST['submitt']))
{
$name = $_POST["name"];
$mail = $_POST["email"];
$j_type = $_POST["jobtype"];
$e_type = $_POST["ent_type"];
$task = $_POST["tas_out"];
$l_st = $_POST["l_st"];
$task_des = $_POST["message"];
$image_name=$_FILES['image']['name'];
$image_type=$_FILES['image']['type'];
$image_size=$_FILES['image']['size'];
$image_temp=$_FILES['image']['tmp_name'];
//$date = date(m-d-y);
echo $name;
echo $mail;
echo $j_type;
echo $e_type;
echo $task;
echo $l_st;
echo $task_des;
if ($image_type=='image/jpeg' || $image_type=='image/png' || $image_type=='image/gif') {
move_uploaded_file($image_temp, "img/$image_name");
}
$connection=mysqli_connect("localhost", "root", "","com");
$query="insert into details (name, mail, j_type, e_type, task_outline, l_style, task_desc, image) values('".$name."','".$mail."','".$j_type."','".$e_type."','".$task."','".$l_st."','".$task_des."','".$image_name."')";
if(mysqli_query($connection,$query)){
//include('test.php');
echo '<h2>Data submitted successfully!!</h2>';
header("refresh:1; url=login.php");
//echo 'Back';
}else{
echo "Data not Submitted!";
# code...
}
}
echo "Data not Submitted!";
?>

echo "Data not Submitted!"; // put this line inside the last bracket

Sorry it was my fault,there was a typo mistake in the form action.Everything else is fine.

Related

2 different action in one form

I have a form called addcustomer.php . it's contain firsname, lastname, mobile fields.i have also 2 button on this form. onr button for saving data and the others for sending sms to customers.
i want to when i click second button 3 data fields passed to another form called smsinfo.php.
now action for saving data works good but when direct to smsinfo . there is no data on this form .
<form method ="POST" name = "custform" action="">
<div class="cell_2_2"><label class="lblfields">Firstname:</label> <input type="text" name="firstname" autocomplete="off"/></div>
<div class="cell_3_2"><label class="lblfields">Lastname :</label> <input type="text" name="lastname" autocomplete="off"/></div>
<div class="cell_5_2"><label class="lblfields">Mobile :</label> <input type="text" name="mobile" autocomplete="off"/></div>
<input type="submit" name="submit" value="Save"/>
<input type="submit" name="sendsms" value="Sms"/>
if (isset($_POST['submit']))
{
Saving code here
} else if (isset($_POST['sendsms'])) {
header("Location: smsinfo.php");
}
here code of smsinfo.php:
<?php
$Fname = $_REQUEST['firstname'];
$Lname = $_REQUEST['lastname'];
$Mob = $_REQUEST['mobile'];
?>
<html>
<body>
<form action="sendingsms.php" method="POST">
<input style="width: 100px;" name="firstname" type="text" value="<?php echo $firstname; ?>"/>
<input style="width: 100px;" name="lastname" type="text" value="<?php echo $lastname; ?>"/>
<input style="width: 100px;" name="mobile" type="text" value="<?php echo $mobile; ?>"/>
</form>
</body>
</html>
thanks all and sorry for my poor english

My echo statement wont show in html lines

This is my code. I'm trying to print the comments on my site. The query and everything works since I tried it in an empty project but here it doesn't echo. The comments update in the database but they just don't show. What am I missing?
<h1>Leave a comment below!</h1>
<?php
$find_comments = mysql_query("SELECT * FROM comments");
if ($find_comments) {
while ($row = mysql_fetch_assoc($find_comments)) {
$comment_name = $row['name'];
$comment = $row['comment'];
echo "<p>'$comment_name' - '$comment'</p>";
}
}
if(isset($_GET['error'])) {
echo "<p>100 per limit";
}
?>
<form action="post_comments.php" method="post">
<p>Your Name: </p>
<input type="text" name="name" size="40" maxlength="30" placeholder="Enter name..." </input><br><p>
<p>Your Email: </p>
<input type="text" name="email" size="40" maxlength="30" placeholder="Enter email..." </input><br><p>
<p>Your comment: </p>
<textarea type="text" name="comment" cols="50" rows="10" placeholder="Enter comment..."></textarea><br><p>
<input type="submit" name="submit" value="Submit comment!" ></input>
</form>
Your variable name is in single quote, it must me concat or place in double quote..
For Ex
echo "<p>$comment_name-$comment</p>";
or
echo "<p>".$comment_name."-".$comment</p>";
Try this it will work :
Use
"<p>".$comment_name." - ".$comment."</p>";
instead of
"<p>'$comment_name' - '$comment'</p>";
echo "<p>".$comment_name."-".$comment."</p>";

$_POST returning empty value

EDIT: The code seems to work if I place the PHP code in the same file at the HTML. I'll implement this method for now. Thank you for the help!
Whenever I try to echo the values in a PHP file from an input box the values appear to be empty.
Here is my HTML code
<form action="sendmail.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
This is my sendmail.php file
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name;
echo $email;
echo $message;
You can get the value in Your current page itself
<?php
if(isset($_POST['person']))
{
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Name".$name;
echo "Email".$email;
echo "Message".$message;
}
?>
<form action="" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
or if you want the data in another page
<form action="send.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
send.php file
<?php
if(isset($_POST['person']))
{
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo "Name".$name;
echo "Email".$email;
echo "Message".$message;
}
?>
I tried this code and it worked fine, so whatever is wrong it is not with the code you have pasted here.
to make sure the post is successful, try this:
if(isset($_POST['person']))
echo "passed fine.";
check:
if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST'){
if(isset($_POST['person'])){
$name = $_POST['person'];
echo $name;
}
}
else{
echo"Your form submission is not correct";
}
try this code.
HTML
<form action="sendmail.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
PHP
<?php
$name = $_POST['person'];
$email = $_POST['email'];
$message = $_POST['message'];
echo $name;
echo $email;
echo $message;
?>
<form action="456.php" method="post">
<label>Name:</label><br>
<input name="person" type="text" /><br>
<label>Email:</label><br>
<input name="email" type="email" /><br>
<label>Opportunity:</label><br>
<textarea name="message" rows="8"></textarea><br>
<input type="submit" value="Submit" class="button">
</form>
<?
print_r($_POST);
?>

Get form to submit on same page? [duplicate]

This question already has an answer here:
Submission form won't stay on same page
(1 answer)
Closed 9 years ago.
Okay so, I've posted this already but still haven't found a solution. I can't seem make my form stay on the same page and I've basically tried EVERYTHING I could possibly think of.
<?php include("inc\incfiles\header.inc.php"); ?>
<?php
$reg = #$_POST['reg'];
//declaring variables to prevent errors
$fn = $ln = $un = $em = $em2 = $pswd = $pswd2 = $d = $u_check = "";
/*$fn = ""; //First Name
$ln = ""; //Last Name
$un = ""; //Username
$em = ""; //Email
$em2 = ""; //Email 2
$pawd = ""; //:Password
$pawd2 = ""; //Password 2
$d = ""; //Sign up Date
$u_check = ""; //Check if username exists*/
//registration form
$fn = mysql_real_escape_string(#$_POST['fname']);
$ln = mysql_real_escape_string(#$_POST['lname']);
$un = mysql_real_escape_string(#$_POST['username']);
$em = mysql_real_escape_string(#$_POST['email']);
$em2 = mysql_real_escape_string(#$_POST['email2']);
$pswd = mysql_real_escape_string(#$_POST['password']);
$pswd2 = mysql_real_escape_string(#$_POST['password2']);
$d = date("Y-m-d"); //Year - Month - Day
if ($reg)
{
//check all of the fields have been filled in
if ($fn && $ln && $un && $em && $em2 && $pswd && $pswd2) {
}
else{
echo "please fill in all fields...";
}
}
?>
<table class="homepageTable">
<tr>
<td width="60%" valign="top">
<center><h2>Join the community today!</h2></center>
<center><img src="images/photo.png" width="500"></center>
<form>
</td>
<td width="40%" valign="top">
<h2>Get started below...</h2>
<form action="#" method="post">
<input type="text" size="25" name="firstname" placeholder="First Name" value="<?php echo $fn; ?>"/>
<input type="text" size="25" name="lastname" placeholder="Last Name" value="<?php echo $ln; ?>"/>
<input type="text" size="25" name="username" placeholder="Username" value="<?php echo $un; ?>"/>
<input type="text" size="25" name="email" placeholder="Email" value="<?php echo $em; ?>">
<input type="text" size="25" name="email2" placeholder="Repeat Email" value="<?php echo $em2; ?>"/>
<input type="password" size="32" name="password" placeholder="Password"/>
<input type="password" size="32" name="password2" placeholder="Repeat Password"/><br />
<input type="submit" name="reg" value="Sign Up!"/>
</form>
</td>
</tr>
</table>
My biggest problem is with the:
<form action="#" method="post">
<input type="text" size="25" name="firstname" placeholder="First Name" value="<?php echo $fn; ?>"/>
<input type="text" size="25" name="lastname" placeholder="Last Name" value="<?php echo $ln; ?>"/>
<input type="text" size="25" name="username" placeholder="Username" value="<?php echo $un; ?>"/>
<input type="text" size="25" name="email" placeholder="Email" value="<?php echo $em; ?>">
<input type="text" size="25" name="email2" placeholder="Repeat Email" value="<?php echo $em2; ?>"/>
<input type="password" size="32" name="password" placeholder="Password"/>
<input type="password" size="32" name="password2" placeholder="Repeat Password"/><br />
<input type="submit" name="reg" value="Sign Up!"/>
</form>
I want to be able to press the submit button and have it stay on the same page.
I've tried leaving the blank I've tried a few other suggestions but I keep coming up with nothing. I've been trying to figure it out for 2 days now and it just won't budge. When pressing the submit button on my site in xampp, it just takes me to another page that says OBJECT NOT FOUND...etc.
If anyone can help, it would be greatly appreciated! I really don't want to have to start all over with my coding just because of one mistake.
Header.inc.php
<?php
include("inc/scripts/mysql_connect.inc.php");
?>
<html>
<head>
<link href="css\main.css" rel="stylesheet" type="text/css">
<title>website</title>
</head>
<body>
<div class="headerMenu">
<div id="wrapper">
<div class="logo">
<img src="images/Logo.png">
</div>
<div class="search_box">
<form method="GET" action="search.php" id="search">
<input name="q" type="text" size="60" placeholder="Search..."
</form>
</div>
<div id="menu">
Home
About
Sign Up
Log in
</div>
</div>
<br />
<br />
<br />
<br />
TRY USING $_SERVER['PHP_SELF']
http://php.net/manual/en/reserved.variables.server.php
By staying on the same page , I think you mean you want to submit the page , refresh & send data. if you mean that , so you may use this as your tag :
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" >
However , if you want your page not to be refreshed , you need to work with Jquery , JavaScript etc.
Your problem is this line in your inc\incfiles\header.inc.php
<input name="q" type="text" size="60" placeholder="Search..."
You are missing the closing bracket -
<input name="q" type="text" size="60" placeholder="Search..." />
^^
because of that, the closing form tag on the next line is not beinging parsed, so your form in index.php is being nestled inside the <form method="GET" action="search.php" id="search">
Instead of form action="#" write form action="" Notice there are 2 ticks with nothing in between.

How to get form fields refilled when data is incorrect

The script for handling the action of my form redirects to the form page if the values are not in proper format. I want to fill the textfields and textarea with the faulty data the user entered on redirect to the form page. I have written the following script which redirects the page on wrong value submission, but does not fill the fields thereafter.
script on form page:
<?php
if(session_id('stat')=="true")
{
$isbn=$_SESSION['var1'] ;
$name=$_SESSION['var2'] ;
$author=$_SESSION['var3'] ;
$publisher=$_SESSION['var4'];
$price=$_SESSION['var5'];
$descrip=$_SESSION['var6'];
$status=$_SESSION['stat'];
}
else
{
$isbn="";
$name="";
$author="";
$publisher="";
$price="";
$descrip="";
$status=false;
}
?>
The html part of the form:
<form action="scripts/addscript.php" method="POST" enctype="multipart/form-data" name="form1" id="form1">
<label for="isbn">ISBN</label>
<input type="text" name="isbn" id="isbn" value="<?php $isbn ?>"/>
<p>
<label for="name">Name</label>
<input type="text" name="name" id="name" value="<?php echo $name; ?>"/>
</p>
<p>
<label for="author">Author</label>
<input type="text" name="author" id="author" value="<?php echo $author; ?>"/>
</p>
<p>
<label for="publisher">Publisher</label>
<input type="text" name="publisher" id="publisher" value="<?php echo $publisher; ?>"/>
</p>
<p>
<label for="price">Price</label>
<input type="text" name="price" id="price" value="<?php echo $price;?>"/>
</p>
<p>
<label for="description">Description</label>
<textarea name="description" id="description" cols="45" rows="5"><?php echo $descrip; ?></textarea>
</p>
<p>
<label for="img">Select an image for the book:
<input type="file" name="img" id="img" />
</label>
<input type="submit" name="submit" id="submit" value="Submit"/>
</p>
</form>
The redirecting script on addscript.php to which the form values are submitted:
<?php
// Get values from form
$isbn=$_POST['isbn'];
$name=$_POST['name'];
$author=$_POST['author'];
$publisher=$_POST['publisher'];
$price=$_POST['price'];
$descrip=$_POST['description'];
$_SESSION['var1'] = $isbn;
$_SESSION['var2'] = $name;
$_SESSION['var3'] = $author;
$_SESSION['var4'] = $publisher;
$_SESSION['var5'] = $price;
$_SESSION['var6'] = $descrip;
if(strlen($isbn)==0||strlen($name)==0||strlen($author)==0||strlen($publisher)==0||strlen($price)==0)
{
$_SESSION['stat']="true";
header('Location: ' . $_SERVER['HTTP_REFERER']);
}
Please telll me where is the problem and how can I solve the issue?
Thanks in advance.
session_start() must be called at the top of your PHP script to use the $_SESSION variable.

Categories