My form is not submitting, My database insert class works and I have tested. But my form seems not to want to submit or post values from my form. Is there something I left out?
<form name="form1" method="post" action="sub_newsletter.php" enctype="multipart/form-data">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2">Newsletter</td>
</tr>
<tr>
<td>Name : </td>
<td><input name="name" type="text"></td>
</tr>
<tr>
<td>Email : </td>
<td><input name="email" type="text"></td>
</tr>
<tr>
<td> <input type="text" name="check_spam" id="check_spam" size="30" style="display:none;" /> </td>
<td> </td>
</tr>
<tr>
<td colspan="2" align="center"><input type="image" name="submit" src="images/sub.jpg" style="width:180px; height:70px;"></td>
</tr>
</form>
</table>
My submit script
<?php
include('includes/database.php');
include('includes/settings.php');
include('includes/newsletter.php');
if (isset($_POST['submit'])){
//to check if posting
echo $username=rtrim($_POST['name']);
echo $myemail=rtrim($_POST['email']);
//
$check=$_POST['check_spam'];
if(!empty($check)){ echo "You are spam"; } else{
$username=rtrim($_POST['name']);
$myemail=rtrim($_POST['email']);
$news = new Newsletter();
$new->first_name=$username;
$new->email=$myemail;
$new->create();
echo "<script>alert(\"Thank you for your subscription\"); </script>";
echo "<script>window.location.replace(\"index.html\"); </script>";
}
}
?>
You obviously missed submit button
<input type="submit" name="submit">
Since you have already a field with that name, just change it or use a different name.
Related
Query 1.
form submitting working fine in local , but not working in live. I removed the action and put # and also i didn't call any script for redirect but while click the submit button it is automatically redirect to the same page. i don't know how it is redirecting ?
Query 2.
In action i mentioned <?php echo $_SERVER['PHP_SELF']; ?> and also gave direct url . if i print the post value it is not coming to POST .
In both ways it is showing the error
This page isn’t working
www.XXXXXXXXXXX.com didn’t send any data.
here below i paste my short code
<?php
ob_start();
session_start();
$_SESSION['captcha'] = rand(1000,9999);
include("./config/dbconnect.php");
include("./functions/functions.php");
if($_POST){
print_r($_POST); exit;
}
?>
<table border="0" width="100%"><tr><td style="padding-left:25px">
<form name="register" method="post" action="#" enctype="multipart/form-data">
<table width="634" border="0">
<tr>
<td colspan="3" class="sub_heading"><div align="right"><span class="style_r">* Mandatory Fields</span></div></td>
</tr>
<tr>
<td height="24" colspan="3"><div align="left" class="sub_heading">Login Information</div></td>
</tr>
<tr>
<td width="178">Email<span class="style_r">*</span></td>
<td width="10">:</td>
<td width="432"><input type="text" name="email" width="14" maxlength="50" /></td>
</tr> ******************* etc <tr>
<td colspan="3"><input type="checkbox" name="terms" />
I have read, understood and agree to the Terms and Conditions of eGulfCareers.com</td>
</tr>
<tr>
<td width="178"></td>
<td width="10"></td>
<td width="432"><input type="hidden" name="register" value="1" />
<input type="submit" name="submit" value="Signup" class="submit_button" /></td>
</tr>
</table>
</form></td>
</tr>
</table> `
Suppose I have the html code below:
<FORM name="myForm" action="confirmsold.php" method="post" onsubmit="return validateFormCash()">
<table border=0 width="300" cellspacing=1 cellpadding=3 bgcolor="#353535" align="center">
<tr>
<br>
<tr>
<td bgcolor="#ffffff" colspan=2 width="30%"><b> Input Payment Details (CASH)<b></td>
</td>
</tr>
<tr>
<td bgcolor="#ffffff">Payment Type:</td>
<td bgcolor="#ffffff"><input type="text" name="paytype" value="Cash" disabled></td>
</tr>
<tr>
<td bgcolor="#ffffff">Date Sold:</td>
<td bgcolor="#ffffff"><input type="date" name="date" value="<?php echo date('Y-m-d'); ?>"></td>
</tr>
<tr>
<td bgcolor="#ffffff">Cash Amount:</td>
<td bgcolor="#ffffff"><INPUT type="TEXT" name="cashamount" size="10" maxlength="9" onkeypress="if ( isNaN( String.fromCharCode(event.keyCode) )) return false;"></INPUT></td>
</tr>
<td bgcolor="#ffffff" colspan=2 align="center">
<INPUT type="submit" name="submit" value="Submit">
</td>
</tr></form>
As you can see, it has a default value of "CASH". Now this will be submitted to a php page with an if statement:
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['paytype'] == 'Cash') {
This is the Javascript im using for the form:
function validateFormCash() {
var x = document.forms["myForm"]["cashamount"].value;
if (x == null || x == "") {
alert("Please input Cash Amount");
return false;
}
}
But the page will return an error saying undefined paytype, what am I missing here? Anyone please help.
Thank you
Write this in if conditional:
if ($_SERVER['REQUEST_METHOD'] == 'POST' && $_POST['submit']) {
To be able to catch this $_POST, you have to put input field in form. For example:
<form action="" method="POST">
<!-- some HTML here, including <table> tag -->
<tr>
<td bgcolor="#ffffff">Payment Type:</td>
<td bgcolor="#ffffff"><input type="text" name="paytype" value="Cash"></td>
</tr><tr>
<td bgcolor="#ffffff" colspan=2 align="center">
<INPUT type="submit" name="submit" value="Submit">
</td>
</tr>
<!-- Some more HTML here, including </table> end tag -->
</form>
I'm trying to do a remember me. I'm having an issue were the cookie isn't setting after a form action redirect.
I know this is not the safest way to store a password but it does matter because this is just a simple page that has no information that is important.
if(isset($_POST['signin']))
{
setcookie("cid",$id,time()+60*60);
setcookie("cpass",$pass,time()+60*60);
}
?>
<body>
<form action="login.php" method="post">
<hr/>
<table align="center">
<tr>
<td colspan="2" align="center"><?php echo #$err;?></td>
</tr>
<tr>
<th>Your email</th>
<td><input type="text" name="username" placeholder="username" value="<?php echo #$_COOKIE['cid'];?>" required/></td>
</tr>
<tr>
<th>Your password</th>
<td><input type="password" placeholder="password" name="password" value="<?php echo #$_COOKIE['cpass'];?>" required/>
</td>
</tr>
<tr>
<th>Stay Signed In</th>
<td><input type="checkbox" name="ch"/></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="signin" value="SignIn"/></td>
</tr>
</table>
</form>
</body>
Add this lines in,
if(isset($_POST['signin']))
{
setcookie("cid",$id,time()+60*60);
setcookie("cpass",$pass,time()+60*60);
}
?>
in login.php
Since your action of the form is login.php.
</table>
</form>
This is also wrong, it should be
</form>
</table>
When I'm pasting dummy text from any website to my textarea it is not saving into MySQL server but sometimes it works correctly. I don't know why it is happening.
Here is my code:
<table align="center" border="10">
<form method="post" action="insert.php" enctype="multipart/form-data">
<tr>
<td>News Title</td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td>Select Category</td>
<td>
<select name="cat">
<option>Select Your category</option>
<?php
include('db.php');
$query="select * from nav";
$run=mysql_query($query);
while($row=mysql_fetch_array($run)){
$m_id=$row[0];
$m_title=$row['m_title'];
echo "<option value='$m_id'>$m_title</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td>News Image</td>
<td><input type="file" name="news_image" /></td>
</tr>
<tr>
<td>News Description</td>
<td><textarea cols="40" rows="10" name="desc"></textarea></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="submit" name="btn" value="Insert News"/> </td>
</tr>
</form>
</table>`
<?php
if(isset($_POST['btn'])){
$news_title=$_POST['title'];
$news_cat=$_POST['cat'];
$news_desc=$_POST['desc'];
$news_image=$_FILES['news_image']['name'];
$tmp_image=$_FILES['news_image']['tmp_name'];
if($news_title=='' || $news_cat=='' || $news_desc==''){
echo "<script>alert('Any of your field is Empty')</script>";
exit();
}
else{
move_uploaded_file($tmp_image,"../images/$news_image");
$insert_query="insert into pages(cat_id,page_title,news_image,page_desc) VALUES ('$news_cat','$news_title','$news_image','$news_desc')";
$insert_run=mysql_query($insert_query);
echo "<script>alert('News Inserted...!!!')</script>";
}
}
?>`
You need to escape the input data in case it contains quote characters.
$news_title=mysql_real_escape_string($_POST['title']);
$news_cat=mysql_real_escape_string($_POST['cat']);
$news_desc=mysql_real_escape_string($_POST['desc']);
$news_image=mysql_real_escape_string($_FILES['news_image']['name']);
It would be better if you switched form the deprecated mysql extension to PDO or mysqli, and used prepared statements.
i have a little problem here. What i am trying to achieve is User types in unique id into textbox then presses load button, script is looking for this parameter in MySql database. When found match data should be loaded into textbox below.
UPDATED VERSION
<?php
mysql_connect ("localhost", "root","84946dff6e1") or die (mysql_error());
mysql_select_db ("employees");
if(isset($_POST["loadbtn"]))
{
$load = $_POST["loadbtn"];
$sql = mysql_query("SELECT * FROM titles WHERE emp_no = '$load' ");
$details = mysql_fetch_array($sql);
$savedTitle = $details["title"];
}
?>
<form method="post" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<td width="150">Employee number</td>
<td><input type="text" name="load" /></td>
<td><input type="submit" name="loadbtn" value="Load" /></td>
</tr>
</table>
</form>
<br />
<br />
<form method="get" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<td width="150">Employee Title</td>
<td><input name="salary" type="text" value="<?php echo $savedTitle; ?>"></td>
</tr>
<td width="150"> </td>
<td>
<input name="add" type="submit" id="add" value="Update">
</td>
</tr>
</table>
</form>
thank you for looking and help :)
Try this
<?php
error_reporting(-1);// show all errors when debugging
// don't use these database commands
//mysql_connect ("localhost", "root","84946dff6e1") or die (mysql_error());
//mysql_select_db ("employees");
// do it this way and don't show us your database credentials.
$conn = new mysqli('localhost', "root", "84946dff6e1", 'employees');
//declare your variables so if POST isn't true you don't have errors later
$load = "some Id";
$savedTitle = "no value yet!"; // use something interesting when testing
//you want the value of the textbox which name is load
if(isset($_POST["load"]))
{
//never trust the user directly
//$load = $_POST["load"];
// do this
$load = $conn->real_escape_string($_POST["load"]);
$result = $conn->query("SELECT * FROM titles WHERE emp_no = '$load' ");
$details = $result->fetch_assoc();
$savedTitle = $details["title"];
// show me error when testing to see if something is wrong with query
echo $conn->error;
}
?>
<form method="post" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<tr>
<td width="150">Employee number</td>
<td><input type="text" name="load" value="<?php echo $load; ?>" /></td>
<td><input type="submit" name="loadbtn" value="Load" /></td>
</tr>
</table>
</form>
<br />
<br />
<form method="get" action="changeTitleView.php">
<table width="400" border="0" cellspacing="1" cellpadding="2" align="center">
<td width="150">Employee Title</td>
<td><input name="salary" type="text" value="<?php echo $savedTitle; ?>"></td>
</tr>
<td width="150"> </td>
<td>
<input name="add" type="submit" id="add" value="Update">
</td>
</tr>
</table>
</form>
You will want to add another if branch to handle the second form which updates the title
And remember that form is GET instead of POST like the first form.
<td><input name="salary" type="text" value="<? echo $empTitle; ?>"></td>
try change that line to this:
<td><input name="salary" type="text" value="<?php echo $empTitle; ?>"></td>