I have created a simple form. In the form there is a option to upload photo. I have created that and submitted successfully. But when I updated the mozilla firefox browser to 8.0 the form showing problem. When I submit the form in firefox 8.0 the browser hangs only because of the upload photo section, all other are working well while the same code is running in internet explorer. Then I installed old version of firefox same code is running well. I don't understand why it is happening and what will be the solution? Please help me. Thanks in advance...
Here is the code....
<?php
session_start();
if(!isset($_SESSION['user']))
{
header("Location:index.php");
exit();
}
include("./include/dbc.php");
$msg='';
if(isset($_POST['check'])){
$p=$_FILES['photo']['name'];
$q=$_FILES['photo1']['name'];
if($_REQUEST['a_name'] == '' ||$_REQUEST['b_name'] == ''||$_REQUEST['no_flats'] == ''||$p == ''||$q == '')
{
$msg='Enter Details!!';
}
if($msg==''){
$target = "images/";
$target = $target . basename( $_POST['a_name'].$_FILES['photo']['name']);
$pic=$_POST['a_name'].$_FILES['photo']['name'];
$target1 = "loc_images/";
$target1 = $target1 . basename( $_POST['a_name'].$_FILES['photo1']['name']);
$pic1=$_POST['a_name'].$_FILES['photo1']['name'];
$time=$_POST['month'].' '.$_POST['year'];
$sql= "INSERT INTO flats
SET
app_name = '$_REQUEST[a_name]',
builder = '$_REQUEST[b_name]',
loc_id = '$_REQUEST[loc]',
status_id = '$_REQUEST[status]',
no_of_flats = '$_REQUEST[no_flats]',
completion_time = '$time',
main_pic = '$pic',
loc_map = '$pic1'";
$result=mysql_query($sql) or die(mysql_error());
move_uploaded_file($_FILES['photo']['tmp_name'], $target);
move_uploaded_file($_FILES['photo1']['tmp_name'], $target1);
$id=$_REQUEST['a_name'];
$sql2 =mysql_query("select id from flats where app_name='$id'");
while ($result= mysql_fetch_row($sql2)){
$_SESSION['flat_id']=$result[0];
}
header("Location:new1.php");
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome To Prime Properties</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
</head>
<body>
<div class="container">
<div class="heading">
<div class="banner"><img src="../images/top.jpg" width="995" height="169" /></div>
<!--menu start-->
<div>
<?php include('include/menu.php');?>
</div>
<!--menu end-->
</div>
<div class="main">
<!--left menu start-->
<div class="left_menu">
<?php include('include/lm.php');?>
</div>
<!--left menu end-->
<div class="divider"></div>
<!--body contant goes here-->
<div class="right">
<div id="error">
<?php
echo $msg;
?></div>
<p>
Enter Your Credentials......</p>
<fieldset><p class="first">
<label for="a_name">Appartment Name:</label>
<input type="text" name="a_name" id="a_name"><br/></input></p>
<p>
<label for="b_name">Builder Name:</label>
<input type="text" name="b_name" id="b_name"><br/></input></p>
<p>
<label for="loc">Location:</label>
<select name="loc">
<option value="1">Maligaon</option>
<option value="2">Panbazaar</option>
<option value="3">Fancy Bazar</option>
<option value="4">Kahilipara</option>
<option value="5">Noonmati</option>
<option value="6">Lokhra</option>
<option value="7">Jalukbari</option>
<option value="8">Chandmari</option>
<option value="9">Beltola</option>
<option value="10">Dispur</option>
</select><br/></p>
<p>
<label for="status"> Status:</label>
<select name="status">
<option value="1">Ongoing</option>
<option value="2">Future</option>
<option value="3">Completed</option>
</select><br/></p>
<p><label for="no_flats">No of Flats:</label>
<input type="text" name="no_flats" id="no_flats"><br/></input></p>
<p><label for="c_time">Completion Time:</label>
<select name="month">
<option>Month</option>
<option>January</option>
<option>February</option>
<option>March</option>
<option>April</option>
<option>May</option>
<option>June</option>
<option>July</option>
<option>August</option>
<option>September</option>
<option>October</option>
<option>November</option>
<option>December</option>
</select>
<select name="year">
<option>Year</option>
<option>2012</option>
<option>2013</option>
<option>2014</option>
<option>2015</option>
<option>2016</option>
<option>2017</option>
<option>2018</option>
<option>2019</option>
<option>2020</option>
</select>
</p>
<p><label for="m_pic">Main Picture:</label>
<input type="file" name="photo"/><br/></p>
<p><label for="l_map">Location Map:</label>
<input type="file" name="photo1"/><br/></p>
<p class="submit">
<input type="hidden" name="check" value="1"/>
<button type="submit" name="submit" >NEXT</button></p>
</fieldset></div>
<!--body contant end here -->
</div>
</div>
</body>
</html>
</form>
Your:
<form id="form1" action="<?php echo $_SERVER['PHP_SELF'];?>" method="post" enctype="multipart/form-data">
Cannot be outside of the <body>, and you stuck yours outside of the <head> even.
Try to only wrap what you need in your <form></form> tags.
That is most likely the problem!
Related
This question already has an answer here:
PHP form - if honeypot input field is filled - redirect to another page
(1 answer)
Closed 9 months ago.
I have a 2-page form to gather potential client data, and using a honeypot field to stop spam from entering our database table.
The code inserts the data into the table, so that is not an issue.
What I want to have happen is if the honeypot field is NOT NULL, then I want it to redirect to the noway.html file. Otherwise, redirect to the home.html file.
index.php:
<?php
session_start();
require_once 'config/config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Purchase Form | HomePromise</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/js-cookie#2/src/js.cookie.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="../../assets/css/style.css" />
</head>
<body>
<div class="container box">
<h2 class="page-title" align="center">Purchase Form</h2><br />
<form method="post" id="refi_form" action="index2.php">
<div class="tab-content" style="margin-top:16px;">
<div class="tab-pane active" id="fins_details">
<div class="panel panel-default">
<div class="panel-body">
<div class="form-group">
<!-- Refi label: <label>What's the value of your home?</label> -->
<input type="hidden" name="branch" id="branch" class="form-control" value="Army" />
</div>
<div class="form-group">
<label>What is the sales price of your home?</label>
<select name="salesprice" id="salesprice" class="form-control">
<option value="">Select One</option>
<option value="75000">50,000 - 99,999</option>
<option value="150000">100,000 - 199,999</option>
<option value="250000">200,000 - 299,999</option>
<option value="350000">300,000 - 399,999</option>
<option value="450000">400,000 - 499,999</option>
<option value="550000">500,000 - 599,999</option>
<option value="650000">600,000 - 699,999</option>
<option value="700000">Over 700,000</option>
<span id="error_salesprice" class="text-danger"></span>
</select>
</div>
<div class="form-group">
<label>What loan amount do you want?</label>
<select name="loan_amount" id="loan_amount" class="form-control">
<option value="">Select One</option>
<option value="75000">50,000 - 99,999</option>
<option value="150000">100,000 - 199,999</option>
<option value="250000">200,000 - 299,999</option>
<option value="350000">300,000 - 399,999</option>
<option value="450000">400,000 - 499,999</option>
<option value="550000">500,000 - 599,999</option>
<option value="650000">600,000 - 699,999</option>
<option value="700000">Over 700,000</option>
<span id="error_loan_amount" class="text-danger"></span>
</select>
</div>
<div class="form-group">
<label>What is your yearly income?</label>
<select name="income" id="income" class="form-control">
<option value="">Select One</option>
<option value="25000">Under 25k</option>
<option value="37000">25k - 49k</option>
<option value="62000">50k - 74k</option>
<option value="87000">75k - 99k</option>
<option value="125000">100k - 149k</option>
<option value="175000">150k - 200k</option>
<option value="200000">Over 200k</option>
<span id="error_income" class="text-danger"></span>
</select>
</div>
<br />
<div align="right">
<input type='submit' name='save' id='btn_fins_details' style="background-color:rgb(50,50,200);color:#fff;font-size:1.5em;padding:10px;" value="Next">
</div>
</div>
</div>
</div>
</div>
</form>
</div>
</body>
<script src="../assets/js/script.js"></script>
</html>
index2.php (Note: I am only echoing the values to verify that the honeypot and other values are being stored in their sessions.):
<?php
session_start();
$_SESSION['branch'] = $_POST['branch'];
$_SESSION['salesprice'] = $_POST['salesprice'];
$_SESSION['loan_amount'] = $_POST['loan_amount'];
$_SESSION['income'] = $_POST['income'];
$_SESSION['formurl'] = $_SERVER['HTTP_REFERER'];
echo $_SESSION['branch']; ?><br><?php
echo $_SESSION['salesprice']; ?><br><?php
echo $_SESSION['loan_amount']; ?><br><?php
echo $_SESSION['income']; ?><br><?php
echo $_SESSION['formurl']; ?><br><?php
$client_url = $_POST['client_url'];
require_once 'config/config.php';
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Refinance Form | HomePromise</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet" />
<link rel="stylesheet" href="../../assets/css/style.css" />
</head>
<body>
<div class="container box">
<br />
<h2 class="page-title" align="center">Purchase Form</h2><br />
<form method="post" id="refi_form" action="submit.php">
<div class="tab-content" style="margin-top:16px;">
<div class="tab-pane active" id="fins_details">
<div class="panel panel-default">
<div class="panel-body">
<table class="center">
<tr>
<td class="left">
<div class="form-group">
<label>First Name</label>
<input type="hidden" name="formurl" value="<?php echo $_SESSION['formurl']; ?>">
<input type="hidden" name="client_url" value="<?php echo $_SESSION['client_url']; ?>">
<input type="hidden" name="ip" value="<?php echo $_SESSION['ip']; ?>"></input>
<input type="hidden" name="branch" value="<?php echo $_SESSION['branch']; ?>"></input>
<input type="hidden" name="salesprice" value="<?php echo $_SESSION['salesprice']; ?>"></input>
<input type="hidden" name="loan_amount" value="<?php echo $_SESSION['loan_amount']; ?>"></input>
<input type="hidden" name="income" value="<?php echo $_SESSION['income']; ?>"></input>
<input type="hidden" name="transaction_type" id="transaction_type" value="Purchase">
<input type="text" name="fName" id="fName" class="form-control" />
<span id="error_fName" class="text-danger"></span>
</div>
</td>
</tr>
</table>
<br />
<div class="text-message" style="display: block;">
<p>By clicking submit below, I/we acknowledge that I/we have read and agree to the User Agreement and acknowledge that I/we have read the Privacy Statement, and Disclosures.</p>
<br />
</div>
<div align="right">
<input type='submit' name='save' id='btn_personal_details' style="background-color:rgb(50,50,200);color:#fff;font-size:1.5em;padding:10px;" value="Submit">
</div>
</div>
</div>
</div>
</form>
</div>
</body>
<script src="..assets/js/script.js"></script>
</html>
submit.php:
<?php
session_start();
$_SESSION['branch'] = $_POST['branch'];
require_once 'config/config.php';
if (isset($_POST['client_url']) && $_POST['formurl'] && $_POST['ip'] && $_POST['salesprice'] && $_POST['loan_amount'] && $_POST['transaction_type'] && $_POST['fName'] && (empty($_POST['branch']))) {
$client_url = $_POST['client_url'];
$formurl = $_POST['formurl'];
$ip = $_POST['ip'];
$salesprice = $_POST['salesprice'];
$loan_amount = $_POST['loan_amount'];
$income = $_POST['income'];
$transaction_type = $_POST['transaction_type'];
$fName = $_POST['fName'];
$sql = "INSERT INTO whp (client_url, formurl, ip, salesprice, loan_amount, income, transaction_type, fName) VALUES ('$client_url', '$formurl', '$ip', '$salesprice', '$loan_amount', '$income', '$transaction_type', '$fName')";
$db_con->exec($sql);
header("Location: home.html");
} else {
header("Location: noway.html");
}
?>
Create your honeypot input (name can be whatever, in my example I'm using honeypot).
if (empty($_POST['honeypot'])){
Add that just after the $sql string is set (or just before).
empty will return true if the variable is undefined or set to false. In terms of a POST value, that means it will be true if the POST value is not set or is blank (and you should trigger home.html). If it's filled, it it will return false and you should trigger the else noway.html.
I'm updating my post with an image field. Every thing is going fine, but i lose the path of the image, son if i leave the field empty the image path is null.
I have been trying different ways of including the old path to the field image. Those are the lines that have the old path and the new path.
<input type="file" name="image" value="<?php echo $row['image']; ?>">
<input type="hidden" name="old_image" value="<?php echo $row['image']; ?>" >
I tried also with <input type="file" name="image" value="<?php echo $image; ?>"> but it doesn't work.
Any suggestion?
Thanks in advance!
:)
This is my code:
<?php
require 'database.php';
$db = mysqli_connect("", "", "", "");
$id=$_GET["id"];
$title='';
$image='';
$image_text='';
$category='';
$result = mysqli_query($db, "SELECT * FROM `images` WHERE `id` = $id ");
while ($row = mysqli_fetch_array($result))
{
$title=$row['title'];
$image=$row['image'];
$papayos = $row['papayos'];
$cantidad = $row['cantidad'];
$image_text=nl2br($row['image_text']);
$category=$row['category'];
}
?>
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Modificar. Lapapaya.org Educación y colaboración </title>
<meta name="keywords" content="colaboracion, economía del bien común, emprendimiento"/>
<meta name="description" content="Plataforma para desarrollo de proyectos productivos con bonos de intercambio"/>
<link rel="stylesheet" href="css/style.css">
<link rel="shortcut icon" type="image/png" href="images/favicon.png">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma#0.8.0/css/bulma.min.css">
<script defer src="https://use.fontawesome.com/releases/v5.3.1/js/all.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
</head>
<body>
<section class="section has-background-white">
<div class="container">
<div class="columns is-centered">
<img class="logo-intro" src="images/logo.png" alt="Logo">
<br>
</div>
</div>
</section>
<form method="POST" action='' enctype="multipart/form-data">
<div class="container">
<h1>Título del artículo</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning is-fullwidth" type="text" name="title" value="<?php echo $title; ?>" placeholder="Título">
</div>
<br>
<br>
<div>
<div class="notification"> <h1>Imagen</h1>
<input type="hidden" name="size" value="1000000">
<div class="field">
<div class="control">
<input type="file" name="image" value="<?php echo $row['image']; ?>">
<input type="hidden" name="old_image" value="<?php echo $row['image']; ?>" >
</div>
</div>
<div>
<h1>Descripción</h1>
<textarea class="textarea" name="image_text" rows="8" cols="80"><?php echo $image_text; ?></textarea>
<br>
<h1>Categoría</h1>
<div class=" select is-warning is-fullwidth">
<select type="text" class="" name="category" value="<?php echo $category; ?>">
<option value="1 ">Productos agrícolas</option>
<option value="2 ">Servicio</option>
<option value="3 ">Artesanía</option>
<option value="4 ">Arte</option>
<option value="5">Diseño Industrial</option>
<option value="6 ">Ciudad</option>
<option value="7 ">Economía</option>
<option value="8 ">Emprendimiento</option>
<option value="9 ">Programación</option>
<option value="10 ">Reflexión</option>
<option value="11">Río</option>
<option value="12 ">Seguridad alimentaria</option>
<option value="13 ">Vivienda</option>
</select>
</div>
<h1>Precio</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning" type="number" name="papayos" value="<?php echo $papayos; ?>" placeholder="Papayos">
</div>
<br>
<h1>Cantidad</h1>
<br>
<div class="field">
<div class="control">
<input class="input is-warning" type="number" name="cantidad" value="<?php echo $cantidad; ?>" placeholder="Cantidad">
</div>
<br>
<br>
<div>
<button class="button is-outlined is-medium is-fullwidth" type="update" name="update">Modificar</button>
</div>
</div>
</form>
</body>
</html>
<?php
$server = '';
$username = '';
$password = '';
$database = '';
if (isset($_POST['update'])) {
$title=$_POST['title'];
$image_text=nl2br($_POST['image_text']);
$category=$_POST['category'];
$papayos =$_POST['papayos'];
$cantidad =$_POST['cantidad'];
$total = $papayos * $cantidad;
$old_image = $_POST['old_image'];
if(isset($_FILES['image']['name']) && ($_FILES['image']['name']!="")) {
$size=$_FILES['image']['size'];
$temp=$_FILES['image']['tmp_name'];
$type=$_FILES['image']['type'];
$image_name=$_FILES['image']['name'];
unlink("images/$old_image");
move_uploaded_file($temp, "images/$image_name");
}else {
$image_name=$old_image;
}
$update=mysqli_query($db, "UPDATE images SET title = '$title', image = '$image_name', image_text = '$image_text', category = '$category', papayos = '$papayos', cantidad = '$cantidad', total = '$total' WHERE id = $id");
if ($update) {
echo "<script>alert('Datos actualizados exitosamente')</script>";
echo "<script>window.open('index.php', '_self')</script>";
}
else {
echo "<script>alert('Inserción fallida')</script>";
}
} ?>
I fixed adding this above the imput file:
<img src="images/<?php echo $image; ?>">
:)
Here's the code:
<html>
<head>
<title>emarket.com</title>
<link rel="stylesheet" type="text/css" href="./style.css"/>
</head>
<header>
<h1>emarket.com</h1>
<h1>Post Ad</h1>
</header>
<body>
<?php
if(!empty($_POST)){
$title=$_POST['title'];
$description=$_POST['description'];
$district=$_POST['district'];
$phone=$_POST['phone'];
$catagory=$_POST['catagory'];
$price=$_POST['price'];
mysql_connect("localhost","root","");
mysql_select_db("maindb");
mysql_query("INSERT into allads VALUES(NULL,'$title','$phone','$description', '$price','$district','$catagory')");
echo "<span style='background-color: deepskyblue;'>Your advert is now online!</span>";
}
?>
<form class="postad" method="post" action="">
<fieldset><caption><h2>Post New Advert</h2></caption></fieldset>
<fieldset>
<label>Title</label><br/>
<input type="text" name="title" class="form-text" required>
</fieldset>
<fieldset>
<label>Description</label><br/>
<input name="description" class="form-text" required>
</fieldset>
<fieldset>
<label>District</label><br/>
<select name="district"required>
<option selected>Colombo</option>
<option>Kandy</option>
<option>Matara</option>
<option>Galle</option>
</select>
</fieldset>
<fieldset>
<label>Category</label><br/>
<select name="catagory"required>
<option value="Electronics">Electronics</option>
<option value="Property">House and Property</option>
<option value="Auto">Automobiles</option>
<option value="Misc">Miscellaneous</option>
</select>
</fieldset>
<fieldset>
<label>Phone</label><br/>
<input type="tel" name="phone" maxlength="10" class="form-text" required>
</fieldset>
<fieldset>
<label>Price</label><br/>
Rs. <input type="number" name="price" class="form-text" required>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="submit"/>
</fieldset>
</form>
</body>
</html>
This happened after I entered the PHP parts, it was visible in Firefox before that. Other files having PHP, like the home page, works fine. In chrome not only the website is visible, it works fine too. Stuff from the form gets inserted into the sql table without any problems.
Do you have the slightest idea of how vulnerable you are to mysql injection attacks? Please start using pdo. mysql_* is deprecated.
I've cleaned the function for you. The php part will only be executed once you click the submit button.
<?php
mysql_connect("localhost","root","");
mysql_select_db("maindb");
if(isset($_POST['submit']))
{
$title=isset($_POST['title']) ? $_POST['title'] : '';
$description=isset($_POST['description']) ? $_POST['description'] : '';
$district=isset($_POST['district']) ? $_POST['district'] : '';
$phone=isset($_POST['phone']) ? $_POST['phone'] : '';
$catagory=isset($_POST['catagory']) ? $_POST['catagory'] : '';
$price=isset($_POST['price']) ? $_POST['price'] : '';
if(!empty($title) && !empty($description) && !empty($district) && !empty($phone) && !empty($catagory) && !empty($price))
{
$q = mysql_query("INSERT into allads VALUES(NULL,'$title','$phone','$description', '$price','$district','$catagory')");
if($q)
{
echo "<span style='background-color: deepskyblue;'>Your advert is now online!</span>";
}
else
{
echo "Could not update DB";
}
}
}
?>
<html>
<head>
<title>emarket.com</title>
<link rel="stylesheet" type="text/css" href="./style.css"/>
</head>
<header>
<h1>emarket.com</h1>
<h1>Post Ad</h1>
</header>
<body>
<form class="postad" method="post" action="">
<fieldset><caption><h2>Post New Advert</h2></caption></fieldset>
<fieldset>
<label>Title</label><br/>
<input type="text" name="title" class="form-text" required>
</fieldset>
<fieldset>
<label>Description</label><br/>
<input name="description" class="form-text" required>
</fieldset>
<fieldset>
<label>District</label><br/>
<select name="district"required>
<option selected>Colombo</option>
<option>Kandy</option>
<option>Matara</option>
<option>Galle</option>
</select>
</fieldset>
<fieldset>
<label>Category</label><br/>
<select name="catagory"required>
<option value="Electronics">Electronics</option>
<option value="Property">House and Property</option>
<option value="Auto">Automobiles</option>
<option value="Misc">Miscellaneous</option>
</select>
</fieldset>
<fieldset>
<label>Phone</label><br/>
<input type="tel" name="phone" maxlength="10" class="form-text" required>
</fieldset>
<fieldset>
<label>Price</label><br/>
Rs. <input type="number" name="price" class="form-text" required>
</fieldset>
<fieldset>
<input type="submit" name="submit" value="submit"/>
</fieldset>
</form>
</body>
</html>
?>
Edit :- IN situations like these, it's always better to put your php code before <html>
Also, what's your filename in which all this code exists? Put that filename in the <Form action="filenamehere.php">.
If it still doesn't work, upload it somewhere to let me have a closer look.
Your header tag should be inside the body tag.
<body>
<header>
<h1>emarket.com</h1>
<h1>Post Ad</h1>
</header>
Like #Akshay said, you should be using PDO, however you should be escaping your input using something like mysql_real_escape_string($value) before putting it into the database if you aren't using PDO.
I have a problem whit form submission. I have a html form and the action simpli doesnt want to work. maybe i am doing something wrong, but here take a look at it:
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" style="width:300px;">
<select id="type" name="type">
<option value="0">Matrix</option>
<option value="1">LoL</option>
<option value="2">Dota 2</option>
</select><br />
<textarea rows="30" cols="90" placeholder="Content here" name="content"></textarea><br />
<input type="submit" value="DODAJ">
</form>
so when i click on the button i does refresh the page but nothing is displayed. I't worked in local but when i upload it online nothnig, just a blank page. And the stuff that has to go to the database doesnt go. no errors, no nothing.
help?
Here's the complete code for that add.php page:
<?php
include '../php/db/init.php';
include '../php/db/connection.php';
protect_page();
admin_protect();
if(isset($_SESSION['logged_in'])){
if(isset($_POST['title'], $_POST['content'], $_POST['type'])){
$title = $_POST['title'];
$content = nl2br($_POST['content']);
$content_short = substr($content,0, 150);
$type = $_POST['type'];
echo $type;
die();
if(empty($title) or empty($content) or empty($type)){
$error = 'Potrebno je popuniti sva polja!';
} else {
$query = $pdo->prepare('INSERT INTO articles (article_title, article_content, article_content_short, article_timestamp, article_type) VALUES (?,?,?,?,?)');
$query->bindValue(1,$title);
$query->bindValue(2,$content);
$query->bindValue(3,$content_short);
$query->bindValue(4,time());
$query->bindValue(5,$type);
$query->execute();
redirect('http://www.matrixgamingns.com/admin/index.php');
}
}
?>
<html>
<head>
<title>Matrix Gaming Admin Panel</title>
<link rel="stylesheet" type="text/css" href="../css/admin.css">
<link rel="stylesheet" type="text/css" href="../css/reset.css">
</head>
<body>
<div id="home">
<div id="wrapper">
<?php include 'adminmenusidebar.php'; ?>
<div id="field">
<h3 style="font-size:22px;">Dodaj vest</h3>
<?php if(isset($error)){ ?>
<small style="color:#aa0000"> <?php echo $error?> </small>
<br/>
<?php }?>
<br />
<form action="add.php" method="post" autocomplete="off">
<input type="text" name="title" placeholder="Title" style="width:300px;">
<select id="type" name="type">
<option value="0">Matrix</option>
<option value="1">LoL</option>
<option value="2">Dota 2</option>
</select><br />
<textarea rows="30" cols="90" placeholder="Content here" name="content"></textarea><br />
<input type="submit" value="DODAJ">
<?php
ini_set('display_errors','On');?>
</form>
</div>
</div>
</div>
</body>
</html>
<?php
} else {
redirect('http://www.matrixgamingns.com/admin/index.php');
}
?>
Get rid of the die() after echo $type;
By including a die() function, it stops all in its tracks, just like return does and nothing gets executed afterwards.
You could use the login form example posted here: HTML Dynamic Forms Generator
I downloaded the source code for the login form and it saved me lots of time.
I'm a student assistant, and my job is to help maintain and update websites and databases for part of the campus I work at. Most of the websites have not been developed by me, and I'm pretty much a novice at a lot of the PHP, CSS and HTML components of my job.
We have a PHP webpage with a tutor request form on it (link--not being students at this campus, you won't be able to login to the page...). We took the form down during the summer and would now like to reopen it for the fall. None of the code has changed since we took the form down. When we tried to bring it back up, the page loaded fine in IE and FF, but in chrome all of the content would appear, but none of the styling--it was just text on a white background.
Then, when we tried to use the form in IE or FF, it wouldn't work. After submitting a tutor request the user should be transported to a confirmation page, however the user just returns to the form, with none of the form data being sent to our database.
I believe the problem lies somewhere in the PHP but I don't know enough about that to see the problem.
Here is the code for the webpage:
<?php
require_once("../application_processing/config.php");
session_start();
$dbinfo = new DbInfo();
$db = "sss";
$qtr = checkOpen($dbinfo, $db);
if (fetchTicket("sss/tutor_request")) {
$username = $_SESSION['username'];
$fname = $_SESSION['fname'];
$lname = $_SESSION['lname'];
if ($fname == "" || $fname == NULL) {
$fname = "SAS";
$lname = "Admin";
}
$result = getPreviousSubmission($_SESSION['username'], $dbinfo, $db, "tutor_request", $qtr);
?>
<!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" xml:lang="en-us" lang="en-us"><!-- InstanceBegin template="/Templates/sas_sss.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!--
Cal Poly Web Template v3.4
Code developed by
Information Technology Services
California Polytechnic State University
San Luis Obispo, CA 93407
-->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Tutor Request Form - Student Support Services - Cal Poly</title>
<?php require_once("../application_processing/restore.php"); ?>
<script type="text/javascript" language="javascript" src="http://sas.calpoly.edu/javascript/jquery.js"></script>
<script type="text/javascript" language="javascript" src="http://sas.calpoly.edu/javascript/form_validation_new.js"></script>
<script type="text/javascript" language="javascript" src="javascript/tut_req_app_form.js"></script>
<!-- InstanceEndEditable -->
<meta name="codebase" content="3.4" />
<meta name="layout" content="cp template" />
<meta name="author" content="Therin Irwin" />
<meta name="keywords" content="Student Academic Services" />
<meta name="description" content="Assisting in the development of academic and personal skills" />
<!--Externally linked stylesheet that stylizes the template-->
<link href="http://sas.calpoly.edu/common/css/cp_screen_3.4.css" rel="stylesheet" type="text/css" media="screen" />
<link href="http://sas.calpoly.edu/common/css/cp_print_3.4.css" rel="stylesheet" type="text/css" media="print" />
<link href="http://sas.calpoly.edu/css/screen.css" rel="stylesheet" type="text/css" media="screen" />
<link href="http://sas.calpoly.edu/css/print.css" rel="stylesheet" type="text/css" media="print" />
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
<!--Favicon-->
<link rel="shortcut icon" href="http://sas.calpoly.edu/common/images/favicon.ico" />
</head>
<body>
<!--Container div that encloses the whole template-->
<div id="container">
<!--This skiplink provides easier accessibility-->
<div id="skiplink">Skip to Content</div>
<!--Header-->
<div id="header">
<!--Cal Poly Logo-->
<div id="cplogo"><img src="http://sas.calpoly.edu/common/images/header/cp_logo.gif" alt="Cal Poly" title="Go to Cal Poly Home" width="166" height="60" /></div>
<!--The Content Area of the Header-->
<div id="headercontent">
<!--Dept Logo-->
<img src="http://sas.calpoly.edu/images/sas_logo.png" alt="dept logo" name="headerimage" width="53" height="50" id="headerimage" title="Go to department home page" />
<!--Dept Name-->
<div id="deptname">
<p id="department_name">Student Academic Services</p>
<!--Dept Info-->
<p id="optional_deptinfo">Student Support Services(<acronym>SSS</acronym>)</p>
</div>
</div>
<!--Search Box-->
<div id="search">
<form id="gs" method="get" title="Search Form" action="http://search.calstate.edu/search">
<div>
<input type="hidden" name="site" value="slo-CalPoly" />
<input type="hidden" name="output" value="xml_no_dtd" />
<input type="hidden" name="client" value="slo-CalPoly" />
<input type="hidden" name="proxystylesheet" value="slo-CalPoly" />
<input type="hidden" name="sitesearch" value="sas.calpoly.edu" />
<label for="q">Search SAS</label>
<br />
<input type="text" name="q" id="q" title="Search Text" size="12" maxlength="256" alt="Search Text" />
<input type="image" name="submit" id="submit" src="http://sas.calpoly.edu/common/images/utli_search/search.png" alt="Go" title="Submit Search Query" />
</div>
</form>
</div>
<!--California Polytechnic State University-->
<div id="cp">
<p>California Polytechnic State University</p>
</div>
</div>
<!--End Header-->
<!--Main Image-->
<div id="main-image"></div>
<!--Left Navigation-->
<div id="leftnav">
<!--For accessibility reasons, this "Navigation" text has been added for readability for screen readers-->
<h1>Navigation</h1>
<h2>SSS</h2>
<ul>
<li>What is <acronym>SSS</acronym>?</li>
<li>Services</li>
<li>Eligibility</li>
<li>Academic Enhancement</li>
<li>Graduate and Professional School Advising</li>
<li>Newsletter</li>
<li>SSS Staff</li>
<li>SSS Grant Award</li>
</ul><!--Nav Content Area 1-->
<div id="navcontent1"> <!-- InstanceBeginEditable name="navcontent1" --><!-- InstanceEndEditable --> </div>
</div>
<!--Defines 2-Column Layout-->
<div id="content-2col">
<!--Breadrumb-->
<div id="breadcrumb">Student Academic Services <!-- InstanceBeginEditable name="breadcrumb" -->> <abbr>SSS</abbr> > Tutor Request<!-- InstanceEndEditable --></div>
<!--Begin Main Body Content-->
<div id="content"> <!-- InstanceBeginEditable name="content" -->
<h1>SSS Individual Tutor Request</h1>
<?php
if ($qtr != NULL) {
?>
<h4><?php print($qtr[1]); ?></h4><br />
<h3 class="red"><?php require_once("../application_processing/error_report.php"); ?></h3>
<?php
if (mysql_num_rows($result) > 0) {
?>
<h3>Tutor Requests:</h3><p>
<?php
$first = true;
while ($row = mysql_fetch_array($result)) {
if (!$first)
print(", ");
$subj = $row[0];
$num = $row[1];
$times = $row[2];
print($subj . " " . $num);
$first = false;
}
?></p>
<?php
if (mysql_num_rows($result) >= 6) {
?>
<h3 class="red">The maximum number of tutor requests has been reached for this quarter (6).</h3>
<?php }
} ?>
<span id="error"></span>
<form action="process_tutor.php" method="post" id="TutReqApplication" name="TutReqApplication">
<fieldset>
<legend>Student Information</legend>
<div class="inputBox">
<label for="fname">Name: <?php echo($fname." ".$lname); ?></label><br /> <br />
<label for="username">Cal Poly E-mail: <?php echo($username);?>#calpoly.edu</label>
</div>
<input id="username" name="username" type="hidden" value="<?php print($username);?>" />
<input id="fname" name="fname" type="hidden" value="<?php echo($fname);?>" />
<input id="lname" name="lname" type="hidden" value="<?php echo($lname);?>" />
<div class="inputBox">
<label for="phone">Primary Number: </label><input class="phoneInput" name="phone" id="phone" type="text" maxlength="14" />
<em class="annot">e.g. 555-444-3210</em>
</div>
</fieldset>
<fieldset>
<legend>Course and Tutor Information</legend>
<div class="inputBox">
<label for="dept">Course Requested: </label>
<select id="dept" name="dept">
<option value="">Select</option>
<option value="AERO">AERO</option>
<option value="AG">AG</option>
<option value="AGB">AGB</option>
<option value="AGC">AGC</option>
<option value="AGED">AGED</option>
<option value="ANT">ANT</option>
<option value="ARCE">ARCE</option>
<option value="ARCH">ARCH</option>
<option value="ART">ART</option>
<option value="ASCI">ASCI</option>
<option value="ASTR">ASTR</option>
<option value="BIO">BIO</option>
<option value="BOT">BOT</option>
<option value="BRAE">BRAE</option>
<option value="BUS">BUS</option>
<option value="CD">CD</option>
<option value="CE">CE</option>
<option value="CHEM">CHEM</option>
<option value="CM">CM</option>
<option value="CPE">CPE</option>
<option value="CRP">CRP</option>
<option value="CRSC">CRSC</option>
<option value="CSC">CSC</option>
<option value="DANC">DANC</option>
<option value="DSCI">DSCI</option>
<option value="ECON">ECON</option>
<option value="EDES">EDES</option>
<option value="EDUC">EDUC</option>
<option value="EE">EE</option>
<option value="EHS">EHS</option>
<option value="ENGL">ENGL</option>
<option value="ENGR">ENGR</option>
<option value="ENVE">ENVE</option>
<option value="ES">ES</option>
<option value="FNR">FNR</option>
<option value="FORL">FORL</option>
<option value="FR">FR</option>
<option value="FRSC">FRSC</option>
<option value="FSN">FSN</option>
<option value="GEOG">GEOG</option>
<option value="GEOL">GEOL</option>
<option value="GER">GER</option>
<option value="GRC">GRC</option>
<option value="GSA">GSA</option>
<option value="GSB">GSB</option>
<option value="HIST">HIST</option>
<option value="HNRS">HNRS</option>
<option value="HUM">HUM</option>
<option value="IME">IME</option>
<option value="IT">IT</option>
<option value="ITAL">ITAL</option>
<option value="JOUR">JOUR</option>
<option value="JPNS">JPNS</option>
<option value="KINE">KINE</option>
<option value="LA">LA</option>
<option value="LIB">LIB</option>
<option value="LS">LS</option>
<option value="MATE">MATE</option>
<option value="MATH">MATH</option>
<option value="MCRO">MCRO</option>
<option value="ME">ME</option>
<option value="MSC">MSC</option>
<option value="MU">MU</option>
<option value="PE">PE</option>
<option value="PEM">PEM</option>
<option value="PEW">PEW</option>
<option value="PHIL">PHIL</option>
<option value="PHYS">PHYS</option>
<option value="PM">PM</option>
<option value="POLS">POLS</option>
<option value="PSC">PSC</option>
<option value="PSY">PSY</option>
<option value="REC">REC</option>
<option value="RELS">RELS</option>
<option value="SCM">SCM</option>
<option value="SOC">SOC</option>
<option value="SOCS">SOCS</option>
<option value="SPAN">SPAN</option>
<option value="SPC">SPC</option>
<option value="SS">SS</option>
<option value="STAT">STAT</option>
<option value="TH">TH</option>
<option value="VGSC">VGSC</option>
<option value="VS">VS</option>
<option value="WS">WS</option>
<option value="ZOO">ZOO</option>
</select>
<input type="text" class="medInput" name="coursenum" id="coursenum" maxlength="3" /><br />
</div>
<div class="inputBox">
<label for="instructor">Instructor: </label><input name="instructor" id="instructor" type="text" maxlength="30" />
<em class="annot">e.g. Staley, Clinton (Last, First).</em>
</div>
<div class="inputBox">
<textarea id="comments" name="comments" class="dim" cols="40" rows="5">Enter any other things you would like us to know here (available time, preferred tutor, etc.)</textarea>
</div>
</fieldset>
<fieldset>
<legend>Terms of Agreement</legend>
<p><em>I understand that by signing this contract I agree to meet with my tutor a minimum of two hours per week, a maximum of ten hours per week, for the duration of the quarter. <strong>Missing more than two (2) tutorial sessions, without prior clearance from SSS staff, including my tutor, will result in a suspension of individual tutoring services for the following quarter.</strong> I also understand that in the event that I drop my course, it is my responsibility to contact SSS to cancel this request. Failure to do so may also result in my tutor services being suspended.</em></p>
<p>By typing your full name below, you agree to adhere to the statements above and are providing an electronic signature.</p>
<div class="inputBox">
<label for="signature">Student Signature: </label><input type="text" name="signature" id="signature" maxlength="30" /><br /> <br />
<p id="errorMessage"> </p>
<input type="submit" value="Submit Tutor Request" />
</div>
</fieldset>
</form>
<?php }
else {
?>
<h3>Sorry - The application is closed for the remainder of the quarter. Try again next quarter.</h3>
<?php
}
?>
<!-- InstanceEndEditable --> </div>
<!--End Main Body Content-->
</div>
<!--Footer-->
<div id="footer">
<!--Footer Gold Bar Links-->
<div id="footer_links">
<p> CP Home <span class="textBullet">•</span> CP Find It </p>
<p> Get Adobe Reader <span class="textBullet">•</span> Microsoft Viewers </p>
</div>
<!--Footer Dept Links-->
<div id="footer_deptlinks">
<p>Staff <span class="textBullet">•</span> Site Map <span class="textBullet">•</span> Student Employment</p>
<p>Last Update: <!-- InstanceBeginEditable name="lastupdate" --><!-- #BeginDate format:Am2 -->9/20/12<!-- #EndDate --><!-- InstanceEndEditable --></p>
</div>
<!--Footer Dept Info-->
<div id="footer_deptinfo">
<p>Student Support Services<br />
Student Services, Bldg 124, Rm 119<br />
California Polytechnic State University<br />
San Luis Obispo, Ca 93407-0203<br />
805.756.1395<br />
cmargari#calpoly.edu</p>
</div>
</div>
<!--End Footer-->
</div>
</body>
<!-- InstanceEnd --></html>
<?php } ?>
I would post images of what the page looks like in IE, FF and Chrome, "but as a spam prevention mechanism, new users aren't allowed to post images."
I understand this isn't a lot to go on, but any help would be greatly appreciated!
Try using the validator web site - http://validator.w3.org
It will spot the problem for you.
EDIT
There is one for CSS as well. http://jigsaw.w3.org/css-validator/
Use the W3C Validator and clear your cache. It loads just fine for me.