Javascript document.form.submit() not working [closed] - php

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
This is the code
<?php
session_start();
require_once("config.php");
session_start();
require_once("checkuser.php");
checkuser();
if(isset($_GET['associate']))
{
$_SESSION['form']['code']=$_GET['associate'];
}
if(isset($_GET['branch']))
{
$_SESSION['form']['br_code']=$_GET['branch'];
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<link href="calendar.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="ajax.js"></script>
<script language="javascript">
function open_window1()
{
window.open("help_associate_edit.php");
}
function open_window2()
{
document.form.action="br_code_edit.php";
document.getElementById('sub').submit();
}
function check()
{
if(document.frm.br_name.value=="")
{
alert("Please specify your branch name");
document.frm.br_name.focus();
}
else if(document.frm.br_code.value=="")
{
alert("please specify Branch Code");
document.frm.br_code.focus();
}
else if(document.frm.name.value=="")
{
alert("please specify your Name");
document.frm.name.focus();
}
else if(document.frm.father_name.value=="")
{
alert("please specify your father's name ");
document.frm.father_name.focus();
}
else if(document.frm.dob.value=="")
{
alert("Enter Date Of Birth");
document.frm.dob.focus();
}
else if(document.frm.occupation.value=="")
{
alert("Enter occupation");
document.frm.occupation.focus();
}
else if(document.frm.r_address.value=="")
{
alert("please specify your address ");
document.frm.r_address.focus();
}
else if(document.frm.phone.value=="")
{
alert("please specify phone");
document.frm.phone.focus();
}
else if(document.frm.document.value=="")
{
alert("please specify document");
document.frm.document.focus();
}else if(document.frm.intro_name.value=="")
{
alert("please specify introducer name");
document.frm.intro_name.focus();
}
else if(document.frm.intro_code.value=="")
{
alert("please specify introducer code");
document.frm.intro_code.focus();
}
else if(document.frm.t_name.value=="")
{
alert("please specify Top associate name");
document.frm.intro_code.focus();
}else if(document.frm.t_code.value=="")
{
alert("please specify top associate code");
document.frm.t_code.focus();
}
else
{
document.frm.submit();
}
}
function calldel(a)
{
if (confirm("Are you sure you want to delete this?"))
{
document.frm.method="post";
document.frm.action="associate_edit_verify.php?del="+a;
document.frm.submit();
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Tulip Agritech India Limited</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<script language="JavaScript">
<!--
function mmLoadMenus() {
if (window.mm_menu_1215174111_0) return;
window.mm_menu_1215174111_0 = new Menu("root",178,30,"Verdana, Arial, Helvetica, sans-serif",14,"#555152","#FFFFFF","#F3F3F3","#457FBE","left","middle",5,0,1000,-5,7,true,true,true,0,false,false);
mm_menu_1215174111_0.addMenuItem("Ongoing Projects","location='ongoing_projects.php'");
mm_menu_1215174111_0.addMenuItem("Future Plans","location='future_plans.html'");
mm_menu_1215174111_0.hideOnMouseOut=true;
mm_menu_1215174111_0.bgColor='#CDCDCD';
mm_menu_1215174111_0.menuBorder=1;
mm_menu_1215174111_0.menuLiteBgColor='';
mm_menu_1215174111_0.menuBorderBgColor='#CDCDCD';
mm_menu_1215174111_0.writeMenus();
} // mmLoadMenus()
//-->
</script>
<script language="JavaScript" src="mm_menu.js"></script>
</head>
<? if(isset($_GET['associate']))
{?>
<body onload="call();">
<? } else
{
?>
<body>
<? } ?>
<script language="JavaScript1.2">mmLoadMenus();</script>
<div id="wrapper">
<div id="header">
<div id="header_left"><img src="images/company_logo.jpg" alt="company_logo" /></div>
<div id="header_right">
<div id="login"><img src="images/login.jpg" alt="login" width="85" height="30" border="0" /> <img src="images/register_now.jpg" alt="register_now" width="114" height="30" border="0" /></div>
<div id="search_box">
<form id="form1" name="form1" method="post" action="">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><input name="textfield" type="text" class="search_field" value="KeyWords Here..." /></td>
<td align="right" valign="middle"><input type="image" name="imageField" src="images/go.jpg" /></td>
</tr>
</table>
</form>
</div>
</div>
</div>
</div>
<div id="navigation"><br />
<div id="nav">
<div id="nav_content">
<ul id="menu">
<li>HOME</li>
<li><img src="images/nav_div.jpg" alt="nav_div" /></li>
<li>ABOUT US</li>
<li><img src="images/nav_div.jpg" alt="nav_div" /></li>
<li>ASSOCIATE</li>
<li><img src="images/nav_div.jpg" alt="nav_div" /></li>
<li style="cursor:pointer;"><a href="#" name="link3" id="link1" onmouseover="MM_showMenu(window.mm_menu_1215174111_0,0,34,null,'link3')" onmouseout="MM_startTimeout();" >PLAN & PROJECTS</a></li>
<li><img src="images/nav_div.jpg" alt="nav_div" /></li>
<li>CONTACT US</li>
</ul>
</div>
<div id="social_network"><img src="images/facebook.jpg" alt="facebook" border="0" /> <img src="images/twitter.jpg" alt="twitter" width="28" height="29" border="0" /> <img src="images/youtube.jpg" alt="youtube" width="28" height="29" border="0" /> <img src="images/space.jpg" alt="space" width="28" height="29" border="0" /></div>
</div>
</div>
<div id="inner_banner_bg">
<div id="inner_banner"><img src="images/associate_banner.jpg" alt="associate" width="1000" height="108" /></div>
</div>
<div style="width:100%; margin-top:22px;">
<div id="body">
<div align="right">
<img src="./image/logout.jpg" style="width:25px"alt="">Logout
</div><div align="center">
<p>
<table width="662"><th colspan="2">Registration Form (
* indicates the field is required)</th>
</tr>
<form name="form">
<tr>
</tr>
<tr>
<td width="173"> </td>
<td width="207"> </td>
<td width="266"></tr>
<tr>
<td height="74"><div align="left">Associate code
</div></td>
<td><input type="text" name="code" id="code" size="32" value="<?=$_SESSION['form']['code']?>"/></td>
<td width=""><input type="button" name="sub" id="sub" value="Edit" size="32" onClick="call();" /><img src="image/help-icon.jpg" width="30" height="30"><strong>Back to menu</strong></td></tr>
</form></table>
</p>
<div id="edit">
</div>
</div></div>
</div>
</div>
<div style="clear:both;"> </div>
</div>
</div>
<div id="footer_bg">
<div id="footer"><br />
<div class="footer_text" style="float:left;">HOME | ABOUT US | ASSOCIATE | PLAN & PROJECTS | CONTACT US
<p>CopyRight All Right Reserved <span class="green_text1">tulipindia.biz</span></p>
</div>
<div class="green_text1" style="float:right;"><span class="black_text1">Address:</span> <span class="green_text3">Registered Office </span><br />
<span class="black_text2">New Town, PO+PS: Diamond Harbour<br />
PIN: 743331, 24PARGANAS SOUTH, West Bengal</span> </div>
</div>
</div>
</body>
</html>
Now my question is that the document.getElementById('sub').submit(); is not working
How to get this form working?

#sub is your submit button. You want to submit the form, so:
document.getElementById("form1").submit();
Also, since is it is part of a form, it should have a 'form' property, so you can do:
document.getElementById("sub").form.submit();

You are trying to submit a button, where you should be trying to submit the form.
Or click the submit button using JS.
So either:
document.getElementById('form1').submit();
Or:
document.getElementById('sub').click();

You submit the form element, not the button element.
Give the form an id - for example "associateform", then change your javascript to read:
document.getElementById('associateform').submit();
Another method is here:
http://www.javascript-coder.com/javascript-form/javascript-form-submit.phtml

There are two forms in the page, cCheck if this is working
document.forms[0].submit();
or
document.forms[1].submit();

Related

How to send the record ID of the row the user pressed on edit button?

Substance ID saved to the session is the last record ID In the table
I need to send the record ID of the row the user pressed on edit button
each for every button selected the record ID sent is the last record ID in the table. moreover, the data table script is not working.
<link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha384-xrRywqdh3PHs8keKZN+8zzc5TX0GRTLCcmivcbNJWm2rs5C8PRhcEn3czEjhAO9o" crossorigin="anonymous"></script>
</head>
php
<div class="table-responsive">
<table class="table table-striped table-bordered" id="tableStock" style="width:100%">
<thead>
<tr>
<th>Substance Name</th>
<th>SubstanceCategory</th>
<th>Substance Quantity</th>
<th>Substance Price</th>
<th>Branch Location</th>
<th>Action</th>
</tr>
</thead>
<?php while($row=$data->fetch(PDO::FETCH_ASSOC) ) {
$_SESSION["Substance_ID"] = $row['Substance_ID'];
$_SESSION["Substance_Name"] = $row['Substance_Name'];
?>
<tr>
<td>
<?php echo $row['Substance_Name'];?>
</td>
<td>
<?php echo $row['Substance_Category']; ?>
</td>
<td>
<?php echo $row['Substance_Quantity']; ?>
</td>
<td>
<?php echo $row['Substance_Price']; ?>
</td>
<td>
<?php
if($row['Branch_ID']==0){
echo "Lebanon"; }
else{
echo "Syria";
}
?>
</td>
<td>
<a class="btn btn-success" href="updateSAtockItems.php" role="button">Update</a>
<a class="btn btn-danger" href="production.html" role="button">Delete</a>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<script>
$(document).ready(function() {
$('#dataTable').DataTable();
});
</script>
<script src="vendor/jquery/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- Core plugin JavaScript-->
<script src="vendor/jquery-easing/jquery.easing.min.js"></script>
<!-- Custom scripts for all pages-->
<script src="js/sb-admin-2.min.js"></script>
<!-- Page level plugins -->
<script src="vendor/datatables/jquery.dataTables.min.js"></script>
<script src="vendor/datatables/dataTables.bootstrap4.min.js"></script>
<!-- Page level custom scripts -->
<script src="js/demo/datatables-demo.js"></script>
</body>
</html>
The reason the session variable is always the last ID in table is because you are updating it every on every row, and therefore the last value will remain.
You could use a form to send the data over as a POST request. Then in your relevant handler, i.e. updateStockItems.php you can use $_POST['substance_ID'] to get which substance the user clicked on.
<td>
<form action="updateStockItems.php" method="POST">
<input type="hidden" name="substance_ID" value="<?php echo $row['Substance_ID']; ?>" />
<button type="submit" class="btn btn-success">Update</a>
</form>
<form action="production.html" method="POST">
<input type="hidden" name="substance_ID" value="<?php echo $row['Substance_ID']; ?>" />
<button type="submit" class="btn btn-danger">Delete</a>
</form>
</td>
Your .Datatable() is being called on a selector which does not exist. You need to change $('#dataTable') to your table's ID, so $('#tableStock').DataTable()

adding to mysql and deleting on the same page

there is my script
require('dbcon2.php');
if(isset($_GET['submit1'])) {
if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {
mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");
}
} elseif(isset($_GET['submit2'])) {
if(isset($_POST['post_id_news2'])) {
$usun = $_POST['post_id_news2'];
mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."");
} else {
echo 'Proba usunieca postu o pustym id.';
}
}
I wanted to do this on one page, before adding deleting (hehe) it was ok, but I wanted to do delete option and nothing works, zero errors I just press inputs and nothing happends.
HTML:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="pl" lang="pl">
<head>
<meta charset="utf-8">
<style type="text/css">
.cztery {
background: pink;
height:705px;
width:40%;
float:right;
}
.czteryipol {
background: red;
height:705px;
width:40%;
float:right;
}
</style>
</head>
<body>
<div class="cztery">
<h1 align="center">
<a href="html/news_podg.php" target="_blink">
PODGLĄD
</a>
</h1>
<table border="5" bordercolor="#a64dff" align="center" style="max-width:20px;">
<?php
$result = mysqli_query($connect,"SELECT autor,id_news FROM news GROUP BY id_news");
while($row = mysqli_fetch_array($result))
{
echo '<tr><td>'.$row['id_news'].'</td><td>'.$row['autor'].'</td></tr>';
}
?>
</table>
</div>
<div class="czteryipol">
<h1 align="center">
EDYCJA
</h1>
<form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">
<h2>
Autor<br> <input type="text" size="20" name="post_autor"/>
</h2>
<h2>
Dodaj artykuł:
</h2>
<textarea name="post_tresc" align="center" form="usrform"></textarea><br>
<input name="submit1" type="submit" value="OK"/><br>
</form>
<form action="kwadrat.php?go=czesc" method="post" id="usrform" align="center">
<h1 align="center">
Usuń artykuł
</h1>
<h2>
Numer artykułu<br> <input type="text" size="5" name="post_id_news2"/>
</h2>
<input name="submit2" value="OK" type="submit"/><br>
</form>
</div>
</body>
</html>
If someone can tell me where is my mistake I will be very grateful
FINAL EDIT:
Thanks for help, I fixed that:
instead of this
($_GET['submit1'])
do
($_POST['submit1'])
Probably .....
Instead of if(isset($_GET['submit1']))
Use if(isset($_POST['submit1']))
if(isset($_POST['post_id_news2'])) { //<- Here is your culprit I think
$usun = $_POST['post_id_news'];
You are checking for post_id_news2 (note 2 at the end) parameter and then trying to use post_id_news parameter.
I don't know which one you actually use, but in your case they should be the same.
Also I suggest you read this:
Escaping parameters for MySQL queries
Here is some debugging stuff: 1. Check to make sure the second submit is actually called #debug1. 2. Next check for MySQL errors #debug2 for the delete statement.
require('dbcon2.php');
if(isset($_GET['submit1'])) {
echo 'submit1: was called'; #debug1
if(isset($_POST['post_autor']) && isset($_POST['post_tresc'])) {
mysqli_query($connect,"INSERT INTO news (tresc, autor) VALUES ('$_POST[post_tresc]', '$_POST[post_autor]')");
}
}
elseif(isset($_GET['submit2'])) {
echo 'submit2: was called'; #debug1
if(isset($_POST['post_id_news2'])) {
$usun = $_POST['post_id_news'];
#debug2
if(!mysqli_query($connect,"DELETE FROM news WHERE id_news = ".$usun."")) {
echo 'MySQL error: ' . mysqli_error($connect);
}
}
else {
echo 'Proba usunieca postu o pustym id.';
}
}

How to define which image is clicked in html page and store the image name in mysql using php

my project is web image Re-Ranking. I am try to get which image is selected in the html page for update the rank of image in Mysql. My code is
index.php
<?php
include './search_image.php';
$obj_image = new Image();
if(#$_POST['Submit'])
{
$obj_image->image_name=str_replace("'", "''", $_POST['txt_image_name']);
$obj_image->Insert_into_image();
$data_image=$obj_image->get_all_image_list();
$row=mysql_num_rows($data_image);
}
?>
<!DOCTYPE HTML PUBLIC"-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Home</title>
</head>
<body bgcolor=cyan>
<script>
window.location.hash="no-back-button";
window.location.hash="Again-No-back-button";//again because google chrome don't insert first hash into history
window.onhashchange=function(){window.location.hash="no-back-button";}
</script>
<center><h1>WEB IMAGE RERANKING</H1></CENTER>
<center>
<table border=0 cellspacing=10>
<th><a href="index.php" target="right">HOME</th>
<th><a href="admin.php" target"=right">ADMIN</th>
<form method="post" enctype="multipart/form-data">
<tr>
<th width="50%">Enter Image name for search</th>
<td width="50%"><input type="text" name="txt_image_name"></input></td>
</tr>
<td width="50%"><input type="submit" name="Submit" value="Submit"></input> </td>
</tr>
</table>
</form>
</CENTER>
<?php
if($row!=0)
{
?>
<center>
<form method="post" enctype="multipart/form-data">
<table width="30%" border="0">
<?php
while($data= mysql_fetch_assoc($data_image))
{
?>
<tr>
<img src="images/<?php echo $data['image']; ?>" width="400px" height="200px" >
</tr>
<?php
}
?>
</table>
</form>
</center>
<?php
}
?>
<?php
echo" <script language='javascript' type='text/javascript'>
function loadImage(String a) {
alert('1 %s',a);
}
</script>"
?>
</body>
</html>
search_image.php
<?php
include 'db_connection.php' ;
class Image{
var
$image_id,
$image_name,
$image;
function Insert_into_image(){
}
function get_all_image_list(){
$query = "select *from stor_image where img_name='$this->image_name'";
$result = mysql_query($query);
return $result;
}
}
?>
when click on specific image update the rank of the image. So I need help to find image name or src for update the data in mysql database.
Thank you
Try this:
HTML:
<img src="images/<?php echo $data['image']; ?>" width="400px" height="200px" >
JS:
$('.gallery').click(function(){
var image_name = $(this).attr('name');
// make an ajax call with this image name and do what ever you want to do
});
HTML:
<img src="images/<?php echo $data['image']; ?>" width="400px" height="200px" >
<script>
function reply_click(clicked_id)
{
$imagename=clicked_id;
alert($imagename);
}
</script>

Name being inserted, but file is not being uploaded [closed]

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.
Closed 9 years ago.
I've an upload input field in a form. the problem that the name of the file is being inserted in the database but the file is not being uploaded to the server, and the same code is working on the same server in a different file in the same directory but in a different query. form is set to enctype="multipart/form-data",
here is the code where its not working
<!DOCTYPE html>
<html lang="en">
<head>
<?php require_once("includes/session.php"); ?>
<?php require_once("includes/dbc.php"); ?>
<?php require_once("includes/functions.php"); ?>
<?php confirm_logged_in(); ?>
<?php find_selected_post(); ?>
<?php
$target = "../upload/";
$target = $target . basename( $_FILES['post_photo']['name']);
if (intval($_GET['cat']) == 0) {
redirect_to('cat_posts.php');
}
include_once("includes/form_functions.php");
if (isset($_POST['submit'])) {
$errors = array();
$required_fields = array('post_title', 'position', 'visible', 'post_content');
$errors = array_merge($errors, check_required_fields($required_fields, $_POST));
$fields_with_lengths = array('post_title' => 30);
$errors = array_merge($errors, check_max_field_lengths($fields_with_lengths, $_POST));
$category_id = mysql_prep($_GET['cat']);
$post_title = trim(mysql_prep($_POST['post_title']));
$post_content = mysql_prep($_POST['post_content']);
$post_description = mysql_prep($_POST['post_description']);
$post_keywords = mysql_prep($_POST['post_keywords']);
$post_tags = mysql_prep($_POST['post_tags']);
$post_photo =($_FILES['post_photo']['name']);
$position = mysql_prep($_POST['position']);
$visible = mysql_prep($_POST['visible']);
if (empty($errors)) {
$query = "INSERT INTO ss_posts (
post_title, post_content, post_description, post_keywords, post_tags, post_photo, position, visible, category_id
) VALUES (
'{$post_title}', '{$post_content}', '{$post_description}', '{$post_keywords}', '{$post_tags}', '{$post_photo}', {$position}, {$visible}, {$category_id}
)";
if ($result = mysql_query($query, $connection)) {
$message = "Successfully Created.";
$new_post_id = mysql_insert_id();
redirect_to("cat_posts.php?post={$new_post_id}");
} else {
$message = "The Post Could Not Be Created.";
$message .= "<br />" . mysql_error();
}
} else {
if (count($errors) == 1) {
$message = "There was 1 error in the form.";
} else {
$message = "There were " . count($errors) . " errors in the form.";
}
}
}
?>
<?php
error_reporting(E_ALL);
echo "<pre>";
print_r($_FILES);
echo "</pre>";
echo "<br/>target: " . $target;
if (!move_uploaded_file($_FILES['post_photo']['tmp_name'], $target)) {
echo "<br/>Upload failed.";
} else {
echo "<br/>Upload done.";
}
?>
<meta charset="utf-8"/>
<title>New Post - Administration Panel</title>
<script src="js/ckeditor/ckeditor.js" type="text/javascript"></script>
<link rel="stylesheet" href="js/ckeditor/sample.css">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/form.css" type="text/css" media="screen" />
<link rel="stylesheet" href="css/button.css" type="text/css" media="screen" /> <!--[if lt IE 9]>
<link rel="stylesheet" href="css/ie.css" type="text/css" media="screen" />
<script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script src="js/jquery-1.5.2.min.js" type="text/javascript"></script>
<script src="js/hideshow.js" type="text/javascript"></script>
<script src="js/jquery.tablesorter.min.js" type="text/javascript"></script>
<script type="text/javascript" src="js/jquery.equalHeight.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$(".tablesorter").tablesorter();
}
);
$(document).ready(function() {
//When page loads...
$(".tab_content").hide(); //Hide all content
$("ul.tabs li:first").addClass("active").show(); //Activate first tab
$(".tab_content:first").show(); //Show first tab content
//On Click Event
$("ul.tabs li").click(function() {
$("ul.tabs li").removeClass("active"); //Remove any "active" class
$(this).addClass("active"); //Add "active" class to selected tab
$(".tab_content").hide(); //Hide all tab content
var activeTab = $(this).find("a").attr("href"); //Find the href attribute value to identify the active tab + content
$(activeTab).fadeIn(); //Fade in the active ID content
return false;
});
});
</script>
<script type="text/javascript">
$(function(){
$('.column').equalHeight();
});
</script>
</head>
<body>
<header id="header">
<hgroup>
<h1 class="site_title">Administration Panel</h1>
<h2 class="section_title">New Post</h2><div class="btn_view_site">
View Site</div>
</hgroup>
</header>
<!-- end of header bar -->
<section id="secondary_bar">
<div class="user">
<p>Hello, <?php echo $_SESSION['username']; ?> (Logout)</p>
</div>
<div class="breadcrumbs_container">
<article class="breadcrumbs">Administration Panel
<div class="breadcrumb_divider"></div>
<a class="current">New Post</a></article>
</div>
</section>
<!-- end of secondary bar -->
<aside id="sidebar" class="column" style="height:160%;">
<hr/>
<h3>Pages</h3>
<ul class="toggle">
<li class="icn_new_article">Add a New Page</li>
<li class="icn_edit_article">Edit/Delete a Page</li>
</ul>
<hr/>
<h3>Users</h3>
<ul class="toggle">
<li class="icn_add_user">Add New User</li>
<li class="icn_view_users">View Users</li>
</ul>
<hr/>
<h3>Blog</h3>
<ul class="toggle">
<li class="icn_categories">Create a Category</li>
<li class="icn_new_article">Create/Edit a Post</li>
<li class="icn_settings">Home Blog Settings</li>
<li class="icn_settings">Blog Settings</li>
</ul>
<hr/>
<h3>Settings</h3>
<ul class="toggle">
<li class="icn_settings">Settings</li>
<li class="icn_settings">Site Logo</li>
<li class="icn_jump_back">Logout</li>
</ul>
<footer>
<hr />
<p><strong>Copyright © 2013 Sky Define</strong></p>
<p>Powered by Sky Define</p>
</br>
</br>
</footer>
</aside><!-- end of sidebar -->
<section id="main" class="column">
<?php
move_uploaded_file($_FILES['post_photo']['tmp_name'], $target);
// output a list of the fields that had errors
if (!empty($errors)) {
echo "<p class=\"errors\">";
echo "Please review the following fields:<br />";
foreach($errors as $error) {
echo " - " . $error . "<br />";
}
echo "</p>";
}
?>
<article class="module width_full">
<header><h3>New Post</h3></header>
<div class="module_content">
<h2>Adding New Post</h2>
<?php if (!empty($message)) {echo "<p class=\"message\">" . $message . "</p>";} ?>
<?php if (!empty($errors)) { display_errors($errors); } ?>
<div class="mws-panel grid_4">
<div class="mws-panel-header">
</div>
<div class="mws-panel-body">
<form class="mws-form" enctype="multipart/form-data" action="new_post.php?cat=<?php echo $sel_category['id']; ?>" method="post">
<div class="mws-form-inline">
<?php $new_post = true; ?>
<?php if (!isset($new_post)) {$new_post = false;} ?>
<div class="mws-form-row">
<label>Post Name:</label>
<div class="mws-form-item large">
<input type="text" name="post_title" id="post_title" class="mws-textinput" placeholder="Post Name Goes Here." />
</div>
</div>
<div class="mws-form-row">
<label>Post Description:</label>
<div class="mws-form-item large">
<input type="text" name="post_description" id="post_description" class="mws-textinput" placeholder="Post Description Goes Here." />
</div>
</div>
<div class="mws-form-row">
<label>Post Keywords:</label>
<div class="mws-form-item large">
<input type="text" name="post_keywords" id="post_keywords" class="mws-textinput" placeholder="Post Keywords Goes Here, Separated By Commas!" />
</div>
</div>
<div class="mws-form-row">
<label>Post Content:</label>
<div class="mws-form-item large">
<textarea name="post_content" id="post_content" class="ckeditor" > </textarea>
</div>
</div>
<div class="mws-form-row">
<label>Post Tags:</label>
<div class="mws-form-item large">
<input type="text" name="post_tags" id="post_tags" class="mws-textinput" placeholder="Post Tags Goes Here, Separated By Commas!" />
</div>
</div>
<div class="mws-form-row">
<label>Edit Post Photo:</label>
<div class="mws-form-item large">
<input type="file" name="post_photo" id="post_photo" />
</div>
</div>
<div class="mws-form-row">
<label>Position:</label>
<div class="mws-form-item large">
<select name="position">
<?php
if (!$new_post) {
$post_set = get_posts_for_category($sel_post['category_id']);
$post_count = mysql_num_rows($post_set);
} else {
$post_set = get_posts_for_category($sel_category['id']);
$post_count = mysql_num_rows($post_set) + 1;
}
for ($count=1; $count <= $post_count; $count++) {
echo "<option value=\"{$count}\"";
if ($sel_post['position'] == $count) { echo " selected"; }
echo ">{$count}</option>";
}
?>
</select>
</div>
</div>
<div class="mws-form-row">
<label>Visible:</label>
<div class="mws-form-item large">
<input type="radio" name="visible" value="0"<?php
if ($sel_post['visible'] == 0) { echo " checked"; }
?> /> No
<input type="radio" name="visible" value="1"<?php
if ($sel_post['visible'] == 1) { echo " checked"; }
?> /> Yes
</div>
</div>
</form>
<div class="mws-button-row">
<input type="submit" name="submit" value="Add Post" class="mws-button green" />
<a class="mws-button red" href="index.php">Cancel</a>
</div>
</div>
</div>
</div>
</article>
<div class="clear"></div>
</div>
</article><!-- end of stats article -->
<div class="spacer"></div>
</section>
</body>
</html>
The way I would try to find the error:
make your errors visible:
<?php error_reporting(E_ALL); ?>
$target should be a full path.
Check your HTML form. Did you add the enctype attribute?
<form enctype="multipart/form-data" method="POST" action="script.php">
Is your Input correct?
<input type="file" name="post_photo"/>
What does the $_FILES array contents?
<?php echo print_r($_FILES); ?>
Edit
Please let us know the data these lines return:
<?php
error_reporting(E_ALL);
echo "<pre>";
print_r($_FILES);
echo "</pre>";
echo "<br/>target: " . $target;
if (!move_uploaded_file($_FILES['post_photo']['tmp_name'], $target)) {
echo "<br/>Upload failed.";
} else {
echo "<br/>Upload done."
}
?>
Edit 2 (Solution):
Your submit-button is outside the form-Tag. That's why. Fix it like this:
<form>
<input type="submit" name="submit" value="Add Post" class="mws-button green" />
</form>
Your $target should contain the root path
$target = $_SERVER['DOCUMENT_ROOT']"/upload/";
$target = $target . basename( $_FILES['post_photo']['name']);

PHP login form doesnt work, doenst reload

I hope you guys can help me. I've got a php file name login.php, in this page there is a form for submitting a name and a password, and then there is checklogin.php that connects to the bd and check if the user exists.
The problem is that when I put the info about user and then submit nothing happens. It stays on the same page (login.php).
Here is the code in login.php:
<link rel="stylesheet" type="text/css" href="StyleSheet.css" />
</head>
<style type="text/css">
#Button1
{
width: 120px;
}
#Button2
{
width: 120px;
}
</style>
<body onload="display_ct(),display_ct2();">
<form id="form1" runat="server">
<div id="wrap">
<div id="header">
<div id="Div1">
<div class="row dropdown-container fixed">
<div class="col-220">
<a id="logo" title="Back Home" href="index.htm">
<img width="220" alt="logo" src="Images/logo.jpg"/>
</a>
</div>
<div class="col-701 last">
<p> </p>
<p class="get-in-touch">
<img width="14" height="10" alt="" src="Images/flagpt.jpg"/>
<strong>
<script type="text/javascript">
function display_c() {
var refresh = 1000; // Refresh rate in milli seconds
mytime = setTimeout('display_ct()', refresh)
}
function display_ct() {
var strcount
var x = new Date()
var horas = x.getHours();
var min = x.getMinutes();
var sec = x.getSeconds();
if (horas < 10) {
horas = "0" + horas;
}
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
document.getElementById('ct').innerHTML = horas + ":" + min + ":" + sec + " ";
tt = display_c();
}
</script> <span id='ct' ></span>
</strong>
<img width="14" height="10" alt="" src="Images/flagiraque.jpg"/>
<strong>
<script type="text/javascript">
function display_c2() {
var refresh = 1000; // Refresh rate in milli seconds
mytime2 = setTimeout('display_ct2()', refresh)
}
function display_ct2() {
var strcount
var x = new Date()
var horas1 = x.getHours() + 2;
var min1 = x.getMinutes();
var sec1 = x.getSeconds();
if (horas1 < 10) {
horas1 = "0" + horas1;
}
if (horas1 > 24) {
horas1 = "0" + (horas1 - 24);
}
if (min1 < 10) {
min1 = "0" + min1;
}
if (sec1 < 10) {
sec1 = "0" + sec1;
}
document.getElementById('ct2').innerHTML = horas1 + ":" + min1 + ":" + sec1 + " ";
tt1 = display_c2();
}
</script> <span id='ct2' ></span>
</strong>
</p>
<p class="text-right">غرفة التجارة و الصناعة البرتغالية العراقية</p>
<p class="text-right1">Câmara do Comércio e Indústria Portugal-Iraque</p>
<p class="text-right">ژووری بازرگانی عیراق پۆرتگال</p>
</div>
<ul id="nav">
<li><center>Inicio <br /> بداية </center> </li>
<li onmouseover=""><center>About Us</center> <center> حول الغرفة </center>
<ul class="nav first">
<li><center>Palavra do Presidente</center> <center> كلمة الرئيس </center> </li>
<li><center> Direcção</center> <center> كلمة الرئيس </center> </li>
<li><center>Conselho Superior</center> <center>المجلس الاستشاري </center></li>
<li><center>Assembleia Geral</center> <center>الجمعية العامة</center></li>
<li><center>Conselho Fiscal</center> <center>الهيئة المالية </center></li>
<li><center>Membros Fundadores</center> <center> العضاء المؤسسين </center></li>
</ul>
</li>
<li><center>Links</center> <center> روابط</center></li>
<li><center>Protocolos</center> <center> مذكرات تفاهم </center> </li>
<li onmouseover=""><center>Noticias/Fotos/Videos</center> <center> اخبار و صور </center>
<ul class="nav first">
<li><center>Noticias</center> <center> اخبار </center> </li>
<li><center>Fotos</center> <center> صور </center> </li>
<li><center>Videos</center> <center> افلام </center> </li>
</ul>
</li>
<li onmouseover=""><center>Associados</center> <center> اعضاء </center>
<ul class="nav first">
<li><center>Como entrar</center> <center>كيفية الاشتراك </center> </li>
<li><center>Lista de Membros</center> <center> قائمة الاعضاء </center> </li>
</ul>
</li>
<li><center>Contactos</center> <center>اتصل بنا </center> </li>
</ul>
</div>
</div>
</div>
<div id="content">
<div class="hr">
</div>
<div class="row fixed">
<div class="col-220">
<ul id="news-box">
<p></p>
</ul>
</div>
<div class="col-460 ">
<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="checklogin.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3"><strong>Member Login </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="myusername" type="text" id="myusername"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="mypassword" type="password" id="mypassword"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td><input type="submit" name="submit" value="Login"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
<div class="row fixed">
<div class="col-220">
<p >
<img width="130" height="70" alt="emb" src="Images/smartcom.jpg"/><br>
<strong>
© 2012
<a href="http://www.smartcom.pt">Smartcom,
<br/></a>Intelligent Communications
</strong>
</p>
<p >
All rights reserved.
<br/>
</p>
</div>
<div class="col-460 ">
</div>
</div>
</div>
</div>
</div>
</form>
</body>
</html>
Checklogin.php:
<?php
//ob_start();
//session_start();
if(isset($_POST['submit']))
{
$host="localhost"; // Host name
$username="ccili_userccili"; // Mysql username
$password="lKUJZhn[{w#e"; // Mysql password
$db_name="ccili_BD"; // Database name
$tbl_name="User"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
//$sql="SELECT * FROM $tbl_name WHERE LOGINNAME='$myusername' and LOGINPASS='$mypassword'";
$result=mysql_query("SELECT * FROM $tbl_name WHERE LOGINNAME='$myusername' and LOGINPASS='$mypassword'");
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.htm"
session_register("myusername");
session_register("mypassword");
header("Location: login_sucess.php");
//header("Location: http://ccili.org/login_sucess.php");
die();
}
else {
echo "Wrong Username or Password";
}
}
//ob_end_flush();
?>
You have nested form tags and that doesn't quite work. The form is submitting to the first tag that has no action attribute.
Here is some more insight on the nesting issue: Can you nest html forms?
Well, let me guess the problem - Add the action and type attribute to the form

Categories