Error in storing the records in database - php

The following code for create edit form to update records. If I give all field it update correctly if I didn't change image it does not update the record. I want to update record without change image and also I want to update records by only changing the image.
<section id="main-content">
<section class="wrapper">
<h3><i class="fa fa-angle-right"></i> About Components</h3>
<!-- BASIC FORM ELELEMNTS -->
<div class="row mt">
<div class="col-lg-12">
<div class="form-panel">
<h3><i class="fa fa-angle-right"></i> Team Update</h3>
<form class="form-horizontal style-form" enctype="multipart/form-data" method="post">
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Title</label>
<div class="col-sm-10">
<textarea type="text" name="Title" class="form-control" required><?php echo $img['a_title']; ?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea type="text" name="Description" class="form-control" required><?php echo $img['a_description']; ?></textarea>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label">Picture</label>
<div class="col-sm-10">
<div class="clear" id="im">
<?php echo "<img src='/myproject/cp/image/".$img['a_image']."'height='50' width='50' >"; ?>
<button type="button" id="remove" >remove</button>
</div>
<div id="browse" style="display:none;">
<input type="file" name="imageupload" value="imageupload" />
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 col-sm-2 control-label"></label>
<div class="col-sm-10">
<input class="btn btn-theme" id="focusedInput" type="submit" name="submit" value="Submit" />
</div>
</div>
<a class="btn btn-primary" href="about.php">
<span>List view</span>
</a>
</form>
</div>
</div><!-- col-lg-12-->
</div><!-- /row --><?php
if(isset($_POST['submit']))
{
$var=$_GET['a_id'];
$file=$_SERVER['DOCUMENT_ROOT'].'myproject/cp/image/'.$img['a_image'];
unlink($file);
$var1=$_POST['Title'];
$var2=$_POST['Description'];
$image=$_FILES['imageupload']['name'];
$root=$_SERVER['DOCUMENT_ROOT'].'/myproject/cp/image/';
$file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$expo=explode(".", $_FILES["imageupload"]["name"]);
$upload_exts = end($expo);
if ((($_FILES["imageupload"]["type"] == "image/gif")|| ($_FILES["imageupload"]["type"] == "image/jpeg")|| ($_FILES["imageupload"]["type"] == "image/png")|| ($_FILES["imageupload"]["type"] == "image/jpg"))&& ($_FILES["imageupload"]["size"] < 2000000)&& in_array($upload_exts,$file_exts))
{
if ($_FILES["imageupload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["imageupload"]["error"] . "<br>";
}
else
{
$image= rand(0,9999).'.'.$upload_exts;
move_uploaded_file($_FILES["imageupload"]["tmp_name"],$root.$image);
$sql=mysql_query("UPDATE about SET a_title='".$var1."',a_description='".$var2."',a_image='".$image."' WHERE a_id='".$var."'") or die(mysql_error());
echo "<meta http-equiv=refresh content=\"0; URL=about.php\">";
}
}
}
?>

As you said in comment , when you save the edits all other details get saved but your image get's removed even if you haven't changed it , clearly it's your php code , even before checking that if you are submiting an image or not you already doing an unlink on it , you have to use the edit below :
<?php
if(isset($_POST['submit']))
{
$var=$_GET['a_id'];
$file_del =$_SERVER['DOCUMENT_ROOT'].'myproject/cp/image/'.$img['a_image'];
$var1=$_POST['Title'];
$var2=$_POST['Description'];
$image=$_FILES['imageupload']['name'];
$root=$_SERVER['DOCUMENT_ROOT'].'/myproject/cp/image/';
$file_exts = array("jpg", "bmp", "jpeg", "gif", "png");
$expo=explode(".", $_FILES["imageupload"]["name"]);
$upload_exts = end($expo);
if ((($_FILES["imageupload"]["type"] == "image/gif")|| ($_FILES["imageupload"]["type"] == "image/jpeg")|| ($_FILES["imageupload"]["type"] == "image/png")|| ($_FILES["imageupload"]["type"] == "image/jpg"))&& ($_FILES["imageupload"]["size"] < 2000000)&& in_array($upload_exts,$file_exts))
{
if ($_FILES["imageupload"]["error"] > 0)
{
echo "Return Code: " . $_FILES["imageupload"]["error"] . "<br>";
}
else
{
unlink($file_del);
$image= rand(0,9999).'.'.$upload_exts;
move_uploaded_file($_FILES["imageupload"]["tmp_name"],$root.$image);
$sql=mysql_query("UPDATE about SET a_title='".$var1."',a_description='".$var2."',a_image='".$image."' WHERE a_id='".$var."'") or die(mysql_error());
echo "<meta http-equiv=refresh content=\"0; URL=about.php\">";
}
}
}

Related

Move uploaded file in php work only sometimes when use multiple uploads

I have a web page for uploading tile image and a concept design image using that tile with a single submit button. But when uploading 2 images with a single submit, move uploaded file is not working always. Sometimes it just moves tile images only, not concept image.
Here is my code:
if(isset($_POST['upload']))
{
$name=$_POST['name'];
$size=$_POST['size'];
$finish=$_POST['finish'];
/* Concept Image */
$concept=$_FILES['concept']['name'];
$contmp=$_FILES['concept']['tmp_name'];
$location='concept';
$upload=move_uploaded_file($contmp,'concept/'.$concept);
$confile='concept/'.$concept;
/* Tile Image */
$image=$_FILES['image']['name'];
$imgtmp=$_FILES['image']['tmp_name'];
$location='tileimage';
$uploading=move_uploaded_file($imgtmp,"tileimage/".$image);
$upfile="tileimage/".$image;
$qry="insert into tile_list value('','$name','$size','$finish','$upfile','$confile')";
$ex=mysqli_query($con,$qry);
$query="insert into availcolors value('','$name','$name','$upfile','$confile')";
$exe=mysqli_query($con,$query);
}
and here is my html markup:
<form method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<label class="control-label col-sm-4">TILE IMAGE<br>
</label>
<div class="col-sm-10 col-md-offset-0 col-md-4">
<input type="file" class="form-control" name=image>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">CONCEPT 3D<br>
</label>
<div class="col-sm-10 col-md-offset-0 col-md-4">
<input type="file" class="form-control" name="concept">
</div>
</div>
<div class="col-sm-10 col-md-7 col-md-offset-4">
<button type="submit" name="upload"><img src="images/upload.jpg" alt="" width="106" height="25" class="img-responsive"></button>
</div>
<form>
Please help me to find out what is the problem
Please try this code:
<?php
//error_reporting(0);
if(isset($_POST['upload']))
{
$name = $_POST['name'];
$size = $_POST['size'];
$finish = $_POST['finish'];
/* Concept Image */
$aMyUploads = array();
foreach ($_FILES as $key => $aFile) {
for($i = 0; $i<count($aFile['error']); $i++){
//echo $aFile['error'][$i]; exit;
if(0 === $aFile['error'][$i]){
if($i == 0)
$newLocation = 'concept/'.$aFile['name'][$i];
else if($i == 1)
$newLocation = 'tileimage/'.$aFile['name'][$i];
}
if(0 === $aFile['error'][$i] && (false !== move_uploaded_file($aFile['tmp_name'][$i], $newLocation))){
$aMyUploads[] = $newLocation;
} else {
$aMyUploads[] = '';
}
}
}
if(is_array($aMyUploads)){
$confile=$aMyUploads[0];
$upfile=$aMyUploads[1];
$qry="insert into tile_list value('','$name','$size','$finish','$upfile','$confile')";
$ex=mysqli_query($con,$qry);
$query="insert into availcolors value('','$name','$name','$upfile','$confile')";
$exe=mysqli_query($con,$query);
}else{
echo "ERROR :: Not insert Please try";
}
}
?>
<html>
<form method="post" enctype="multipart/form-data" class="form-horizontal" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<div class="form-group">
<label class="control-label col-sm-4">TILE IMAGE<br></label>
<div class="col-sm-10 col-md-offset-0 col-md-4">
<input type="file" class="form-control" name="upload_files[]">
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-4">CONCEPT 3D<br></label>
<div class="col-sm-10 col-md-offset-0 col-md-4">
<input type="file" class="form-control" name="upload_files[]">
</div>
</div>
<div class="col-sm-10 col-md-7 col-md-offset-4">
<button type="submit" name="upload"><img src="images/upload.jpg" alt="" width="106" height="25" class="img-responsive"></button>
</div>
</form>
</html>

PHP doenst catch a simple POST

Here below is my code, i get strange results, for example the POST is not being caught by the PHP. If i add ($_SERVER['REQUEST_METHOD'] == 'POST') it is still not caught. It hould be a simple POST, what did i do wrong? The best i get out of this is the error message:
$url_message = 'Something went wro, please try again.';
Please help
if(isset($_POST["submit"])) {
$btc = $_POST['bitcoin'];
$eur = $_POST['euro'];
echo '1';
echo $btc;
echo '2';
echo $eur;
if($btc != "" && $eur != ""){
$user_idr = $_GET['id'];
$user_idreal = $LS->get_CU();
echo $LS->get_CU();
echo $user_idr;
if($user_idr == $user_idreal){
echo 'jemoder';
$cur = $btc;
$eur = $eur;
$user = $user_id;
$datetime = date('Y-m-d H:i:s');
$ip = $_SERVER['REMOTE_ADDR'];
if($LS->store_val($cur, $eur, $user, $datetime, $ip) != false){
$url_message = 'Gelukt';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}else{
$url_message = 'niet gelukt';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
$header_n = $LS->get_CU();
$url_message = 'Something went wro, please try again.';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
$header_n = $LS->get_CU();
$url_message = 'Some fields were left blank.';
header('Location: home.php?id=' . $header_n . '&mas=' . $url_message);
}
}else{
echo 'hallo';
}
?>
<div class="col-md-9">
<div class="span9">
<div class="space-6"></div>
<div class="row-fluid">
<div class="span12">
<form class="form-horizontal formproperties" action="<?php echo $_SERVER['PHP_SELF'] ?>#form-textfield" method="POST">
<fieldset>
<div class="container">
<div class="row-fluid">
<div class="col-xs-12 col-sm-12 col-lg-12">
<div class="col-xs-12 col-sm-12 col-lg-6 logintextsupport text-center">
<h3 class="text-left">Buy <?php echo $form_titel;?></h3>
<hr />
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-9">
<input id="<?php echo $form_id;?>" name="<?php echo $form_name;?>" type="text" placeholder="<?php echo $form_placeholder;?> *" class="form-control input-md" required="">
</div>
</div>
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-9">
<input id="euro" name="euro" type="text" placeholder=" *" class="form-control input-md" required="">
</div>
</div>
<legend>Payment Method</legend>
<div class="form-group">
<label class="col-md-1 control-label" for="password"></label>
<div class="col-md-5">
<input type="radio" name="radio" id="radio1" /> <label for="radio1" class="inline">iDeal</label><br />
</div>
<div class="col-md-4">
<input type="radio" name="radio" id="radio3" /> <label for="radio3" class="inline">Ban Contact</label>
</div>
</div>
<hr />
<div class="form-group loginboxsupport">
<label class="col-md-12 col-lg-12" for="proceed"></label>
<div class="col-md-12 col-lg-12">
<button id="proceed" type="submit" name="submit" class="btn btn-success buttonali">SUBMIT</button>
</div>
</div>
<div style="height:0.5vw;"></div>
</div>
</div>
</div>
</div>
</fieldset>
</form>
The problem was in the HTML code, at the action there is the following code
action="<?php echo $_SERVER['PHP_SELF'] ?>#form-textfield"
So the action would be a link to itself, nothing on it. Had to add a user ID:
?id=<?php echo $user_id ?>
The complete action became:
action="<?php echo $_SERVER['PHP_SELF'] ?>?id=<?php echo $user_id ?>#form-textfield"
The total start of the form:
<form class="form-horizontal formproperties" action="home.php?id=<?php echo $user_id ?>#form-textfield" method="POST">

Cannot able to increment row count in every year

I want to restrict user to upload 50 photos per year. Say for example user can upload 50 photos in 2015 and after that user gets error message. Again in 2016 user can able to upload 50 photos but the photo which user uploads in 2015 will not be deleted.
This is my upload.php
<?php
// set timeout period in seconds
$inactive = 100;
// check to see if $_SESSION['timeout'] is set
if(isset($_SESSION['timeout']) ) {
$session_life = time() - $_SESSION['timeout'];
if($session_life > $inactive)
{ session_destroy(); header("Location: logout.php"); }
}
$_SESSION['timeout'] = time();
include "lib/connection.php";
if (!isset($_SESSION['user']))
{
//die ("Access Denied");
header("location:index.php?msg=Please login with valid credentials");
}
if (isset($_SESSION['user']))
{
include "lib/top.php";
include "lib/left.php";
?>
<div class="col-md-10">
<div class="row">
<div class="col-md-12">
<ol class="breadcrumb">
<li>Home</li>
<li class="active">Upload Photo</li>
</ol>
</div>
</div>
<?php
if(!empty($_GET['msg'])) {
$message = $_GET['msg'];
print "$message";
}
?>
<div class="block block-fill-white">
<div class="header">
<h2>Upload Photo</h2>
</div>
<FORM METHOD="POST" ACTION="pic-db-upload.php" enctype = "multipart/form-data">
<div class="content controls">
<div class="form-row">
<div class="col-md-3">Title:</div>
<div class="col-md-9"><input type="text" class="form-control" id="title" name="title" required placeholder="Enter some Title"/></div>
</div>
<div class="form-row">
<div class="col-md-3">Description:</div>
<div class="col-md-9"><textarea class="form-control" id="description" name="description" required></textarea></div>
</div>
<?php
$sel="SELECT * FROM `category`";
$tab=mysql_query($sel);
?>
<div class="form-row">
<div class="col-md-3">Category:</div>
<div class="col-md-9">
<select class="form-control" name="category" required>
<option value="0">Select</option>
<?php
while($row=mysql_fetch_array($tab))
{
?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['cname']; ?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-row">
<div class="col-md-3">Thumbnail Height:</div>
<div class="col-md-9"><input type="text" class="form-control" id="theight" name="theight" required placeholder="Enter height"/></div>
</div>
<div class="form-row">
<div class="col-md-3">Thumbnail Width:</div>
<div class="col-md-9"><input type="text" class="form-control" id="twidth" name="twidth" required placeholder="Enter width"/></div>
</div>
<div class="form-row">
<div class="col-md-3">File:</div>
<div class="col-md-9">
<div class="input-group file">
<input type="text" class="form-control"/>
<input type="file" id="picture" name="picture" required/>
<span class="input-group-btn">
<button class="btn btn-primary" type="button">Browse</button>
</span>
</div>
</div>
</div>
<div class="form-row">
<div class="col-md-3"> </div>
<div class="col-md-9" style="align:midle">
<input type="reset" class="btn btn-danger">
<input type="submit" class="btn btn-primary" name="submit" value="UPLOAD">
</div>
</div>
</div>
</div>
</form>
</div>
</div>
<?php
include "lib/bottom.php";
}
?>
and this is my insert query
<?php
ini_set('display_errors', 0);
error_reporting(E_ERROR | E_WARNING | E_PARSE);
ob_start();
include("lib/connection.php");
if (!isset($_SESSION['user']))
{
//die ("Access Denied");
header("location:index.php?msg=Login with valid credentials");
}
if (isset($_SESSION['user']))
{
//======================= INSERT =================================================
if($_POST[submit]=="UPLOAD")
{
if($_POST[title]!="" && $_POST[category]!="" && $_POST[description]!="" && $_FILES[picture][name]=="")
{
header("location:upload-photo.php?msg=You have not inserted any picture ");
}
else
{
$resource = mysql_query("SELECT COUNT(id) FROM album");
$count = mysql_result($resource,0);
if ($count < 50)
{
//======================== THUMBNAIL CODE ========================
function thumb($a,$b)
{
$image_path=$a;
$new_width=$_POST[twidth];
$new_height=$_POST[theight];
$thumb_path=$b;
$ext=strtolower(end(explode('.',$image_path)));
if($ext=='jpg'||$ext=='jpeg'||$ext=='gif'||$ext=='png')
$img=#imagecreatefromjpeg($image_path);
else
die("only jpg or jpeg or gif or png format supported");
$width=imagesx($img);
$height=imagesy($img);
$tmp_img=imagecreatetruecolor($new_width,$new_height);
imagecopyresized($tmp_img,$img,0,0,0,0,$new_width,$new_height,$width,$height);
imagedestroy($img);
imagejpeg($tmp_img,$thumb_path);
}
//==================================================================
$p=md5(rand(1,1000));
$pict=$p.".jpg";
$target_path1 = "big_pic/big_".$pict;
copy($_FILES[picture][tmp_name],$target_path1);
$target_path2="thumb_pic/thumb_".$pict;
thumb($target_path1,$target_path2);
$ins = "INSERT INTO `album`(`id`,`date`,`title`,`description`,`cid`,`picture`,`thumbnail`,`default`)VALUES('',now(),'$_POST[title]','$_POST[description]','$_POST[category]','$target_path1','$target_path2','$pict')" ;
mysql_query($ins);
header("location:upload-photo.php?msg=Photo successfully uploaded");
}
else
{
header("location:upload-photo.php?msg=Sorry maximum number of photo uploaded. Please contact system administrator");
}
}
}
//======================= END INSERT =================================================
}
?>
Change the query to only count the photos in the current year:
SELECT COUNT(*) FROM album WHERE YEAR(date) = YEAR(NOW())

single quotes and double quotes not inserting in datadase using php

i am inserting data into mysql using php it's work partialy it's inserting everything but not single quotes(') ex. principle's message. and when i insert it like principle"s message. it's inserting in database but it's only displaying principle in text box after inserting. and my file is save.php is here.
<?php session_start();
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_SESSION['user'])) {
if($_GET['catId'] == '' || $_GET['catId'] == null)
header('location:../user/logout.php');
$inc = -1;
if($_POST['title'] == '' || $_POST['title'] == null) {
$inc++;$_SESSION['error'][$inc] = "TITLE IS REQUIRED";
}
$selectImg=mysql_query("SELECT pri_img FROM aboutus_tbl WHERE id=4");
if ($_GET['catId']==4) {
if($_FILES["file"]["name"]) {
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 5242880)
&& in_array($extension, $allowedExts))
$imageNewName = md5(date("l, F d, Y h:i" ,time()) . (microtime())) . "." . $extension;
else {
$inc++;$_SESSION['error'][$inc] = "IVALID IMAGE";
}
}
else {
$inc++;$_SESSION['error'][$inc] = "IMAGE IS REQUIRED";
}
}
function inputValues() {
$_SESSION['values']['title'] = $_POST['title'];
$_SESSION['values']['sub_title1'] = $_POST['sub_title1'];
$_SESSION['values']['desc1'] = $_POST['desc1'];
$_SESSION['values']['sub_title2'] = $_POST['sub_title2'];
$_SESSION['values']['desc2'] = $_POST['desc2'];
$_SESSION['values']['sub_title3'] = $_POST['sub_title3'];
$_SESSION['values']['desc3'] = $_POST['desc3'];
header("location:../../views/aboutus_content/list.php?catId=".$_GET['catId']);
}
if($inc > -1)
inputValues();
else {
require_once('../../includes/connect.php');
if($_GET['catId']==4 && isset($_FILES["file"]["name"])) {
$update="UPDATE aboutus_tbl SET title='".$_POST['title']."',sub_title1='".$_POST['sub_title1']."',desc1='".$_POST['desc1']."',sub_title2='".$_POST['sub_title2']."',desc2='".$_POST['desc2']."',sub_title3='".$_POST['sub_title3']."',desc3='".$_POST['desc3']."',pri_img='".$imageNewName."' WHERE id='".$_GET['catId']."'";
}
else{
$update="UPDATE aboutus_tbl SET title='".$_POST['title']."',sub_title1='".$_POST['sub_title1']."',desc1='".$_POST['desc1']."',sub_title2='".$_POST['sub_title2']."',desc2='".$_POST['desc2']."',sub_title3='".$_POST['sub_title3']."',desc3='".$_POST['desc3']."' WHERE id='".$_GET['catId']."'";
}
if(mysql_query($update)) {
if($_GET['catId']==4 && isset($_FILES["file"]["name"])) {
move_uploaded_file($_FILES["file"]["tmp_name"],"../../public/img/principal/".$imageNewName);
unlink("../../public/img/principal/".mysql_result($selectImg, 0, "pri_img"));
}
$_SESSION['message'] = $_POST['title']." SUCESSFULLY UPDATED";
header('location:../../views/aboutus_content/list.php?catId='.$_GET['catId']);
} else {
$_SESSION['error'] = "ERROR : '".mysql_error()."' CODE : ".mysql_errno();
inputValues();
}
}
} else
header('location:../user/logout.php')
?>
and designing file is here list.php
<?php
ob_start();
include '../../includes/header.php';
if(!isset($_GET['catId']) || $_GET['catId']=='')
header('location:../error');
$contactResult = mysql_query("SELECT * FROM aboutus_tbl WHERE id='".$_GET['catId']."'");
if(mysql_num_rows($contactResult) != 1)
header('location:../error');
else {
?>
<div class="mainbar">
<div class="page-head">
<div class="container">
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<h2><i class="fa fa-desktop"></i> <?php echo mysql_result($contactResult, 0, "title");?> Content</h2>
</div>
<div class="clearfix"></div>
</div>
</div>
</div>
<div class="container">
<?php
if(isset($_SESSION['error'])) {
echo"<div class='alert alert-danger'>";
for($i=0;$i<sizeof($_SESSION['error']);$i++)
echo "<p><b>".$_SESSION['error'][$i]."</b></p>";
echo"</div>";
unset($_SESSION['error']);
}
if(isset($_SESSION['message'])) {
echo"<div class='alert alert-success'><p><b>".$_SESSION['message']."</b></p></div>";
unset($_SESSION['message']);
}
?>
<div class="hide alert alert-danger" id="errorContainer"></div>
<div class="row">
<div class="col-lg-12">
<form action="../../controllers/aboutus_content/save.php?catId=<?php echo $_GET['catId'];?>" method="post" class="contactForms" role="form" enctype="multipart/form-data">
<div class="col-lg-6">
<div class="form-group">
<label for="title"><span class="text-danger">* </span>Title</label>
<input name="title" id="title" data-validation-allowing="'" class="form-control" placeholder="Enter Title" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['title']; echo mysql_result($contactResult, 0, "title");?>" />
</div>
<div class="form-group">
<label for="sub_title1"><span class="text-danger">* </span>Sub Title 1</label>
<input name="sub_title1" id="sub_title1" data-validation-allowing="'" class="form-control" placeholder="Enter Sub Title 1" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['sub_title1']; else echo mysql_result($contactResult, 0, "sub_title1");?>" />
</div>
<div class="form-group">
<label for="desc1"><span class="text-danger">* </span>Description 1</label>
<textarea name="desc1" id="desc1" data-validation-allowing="'" class="form-control" placeholder="Enter Description 1"><?php if(isset($_SESSION['values'])) echo $_SESSION['values']['desc1']; else echo mysql_result($contactResult, 0, "desc1");?></textarea>
</div>
<div class="form-group">
<label for="sub_title2"><span class="text-danger">* </span>Sub Title 2</label>
<input name="sub_title2" id="sub_title2" data-validation-allowing="'" class="form-control" placeholder="Enter Sub Title 2" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['sub_title2']; else echo mysql_result($contactResult, 0, "sub_title2");?>" />
</div>
<div class="form-group">
<label for="desc2"><span class="text-danger">* </span>Description 2</label>
<textarea name="desc2" id="desc2" data-validation-allowing="'" class="form-control" placeholder="Enter Description 2"><?php if(isset($_SESSION['values'])) echo $_SESSION['values']['desc2']; else echo mysql_result($contactResult, 0, "desc2");?></textarea>
</div>
</div>
<div class="col-lg-6">
<div class="form-group">
<label for="sub_title3"><span class="text-danger">* </span>Sub Title 3</label>
<input name="sub_title3" id="sub_title3" data-validation-allowing="'" class="form-control" placeholder="Enter Sub Title 3" value="<?php if(isset($_SESSION['values'])) echo $_SESSION['values']['sub_title3']; else echo mysql_result($contactResult, 0, "sub_title3");?>" />
</div>
<div class="form-group">
<label for="desc3"><span class="text-danger">* </span>Description 3</label>
<textarea name="desc3" id="desc3" data-validation-allowing="'" class="form-control" placeholder="Enter Description 3"><?php if(isset($_SESSION['values'])) echo $_SESSION['values']['desc3']; else echo mysql_result($contactResult, 0, "desc3");?></textarea>
</div>
<div class="form-group">
<label for="pri_img"><span class="text-danger">* </span>Principle Image(Only For Principal's Message)</label>
<input type="file" name="file" id="file" class="form-control">
</div>
</div>
<div class="form-group text-center">
<input type="submit" class="btn btn-info" value="Save" />
Reset
</div>
</form>
</div>
</div>
</div>
</div>
<?php
}
?>
<script type="text/javascript">
window.onload = function() {
$(document).ready(function() {
$('.aboutus_content').addClass('current');
$('.aboutus_content').addClass('open');
$(".courImgItm<?php echo $_GET['catId']?>").addClass('active');
});
}
</script>
<?php
include '../../includes/footer.php';
if(isset($_SESSION['values']))
unset($_SESSION['values']);
ob_flush();
?>
please help me.
Run your string through this first:
mysql_real_escape_string($string);
It'll fix it for ya
try using this way
in your sql query---
$m1=$_REQUEST['message'];
$msg='".str_replace("\"",""",str_replace("'","''",$m1))."';
hope this will help

Ajax File Upload And insert details and Form File Details to Db

Please I Know that some of the Topics relating to my post is here but it does not actually seems to solve my problem. I have an uploader class and my Ajax upload is working fine without PHP connection. Now after Upload am trying to call in my file class to store the details to Database but not actually working out. I have searched all around both on youtube and none see to solve my problem
error_reporting(0);
if (isset($_POST) and $_SERVER['REQUEST_METHOD'] == "POST") {
$path = "uploads/"; //set your folder path
//set the valid file extensions
$valid_formats = array("jpg", "png", "gif", "bmp", "jpeg", "GIF", "JPG", "PNG", "doc", "mp3", "txt", "docx", "pdf", "xls", "xlsx", "mp4"); //add the formats you want to upload
$name = $_FILES['myfile']['name']; //get the name of the file
$size = $_FILES['myfile']['size']; //get the size of the file
if (strlen($name)) { //check if the file is selected or cancelled after pressing the browse button.
list($txt, $ext) = explode(".", $name); //extract the name and extension of the file
if (in_array($ext, $valid_formats)) { //if the file is valid go on.
if ($size < 9433098888) { // check if the file size is more than 2 mb
$file_name = $_POST['filename'];
$new = $_POST['music_new']; //get the file name
$tmp = $_FILES['myfile']['tmp_name'];
if (move_uploaded_file($tmp, $path . $file_name.'.'.$ext)) { //
$sam->musicUpload('name','format','so on');
//please am in need of this. if i type echo $file_name works but can actually insert to my db.. i have no problem with my back end
}
else {
echo "failed";
}
} else {
echo "File size max 2 MB";
}
} else {
echo "Invalid file format..";
}
} else {
echo "Please select a file..!";
}
include'../../header.php';
echo $url;
}
<div class='category-tab shop-details-tab'><!--category-tab-->
<div class='col-sm-12'>
<ul class='nav nav-tabs'>
<li><a href='#details' data-toggle='tab'>Details</a></li>
<li><a href='#companyprofile' data-toggle='tab'>Company Profile</a></li>
<li><a href='#tag' data-toggle='tab'>Tag</a></li>
<li class='active'><a href='#reviews' data-toggle='tab'>Reviews (5)</a></li>
</ul>
</div>
<div class='tab-content'>
<div class='tab-pane fade' id='details' >
<div class='col-sm-3'>
<div class='product-image-wrapper'>
<div class='single-products'>
<div class='productinfo text-center'>
<img src='images/home/gallery1.jpg' alt='' />
<h2>$56</h2>
<p>Easy Polo Black Edition</p>
<button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
<div class='tab-pane fade' id='companyprofile' >
<div class='col-sm-3'>
<div class='product-image-wrapper'>
<div class='single-products'>
<div class='productinfo text-center'>
<img src='images/home/gallery4.jpg' alt='' />
<h2>$56</h2>
<p>Easy Polo Black Edition</p>
<button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
<div class='tab-pane fade' id='tag' >
<div class='col-sm-3'>
<div class='product-image-wrapper'>
<div class='single-products'>
<div class='productinfo text-center'>
<img src='images/home/gallery4.jpg' alt='' />
<h2>$56</h2>
<p>Easy Polo Black Edition</p>
<button type='button' class='btn btn-default add-to-cart'><i class='fa fa-shopping-cart'></i>Add to cart</button>
</div>
</div>
</div>
</div>
</div>
<div class='tab-pane fade active in' id='reviews' >
<div class='col-sm-12'>
<ul>
<li><a href=''><?php if($logged){ echo $username;}else{echo'Not Logged';}?></a></li>
<li><a href=''><i class='fa fa-clock-o'></i>12:41 PM</a></li>
<li><a href=''><i class='fa fa-calendar-o'></i>31 DEC 2014</a></li>
</ul>
<p> Plese make sure to upload Relevant files or else it will be deleted by the Head Admin(s). Thanks for Understanding</p>
<p><b>Write Your Review</b></p>
<div class="row">
<div class='tab-pane fade active in' id='reviews' >
<div class='col-sm-12'>
<h3>jQuery Ajax file upload with percentage progress bar</h3>
<form id="myform" method="post">
<div class="form-group">
<label>Enter the file name: </label>
<input class="form-control" type="text" id="filename" />
</div>
<span>
<input type="text" placeholder="Database Name" id='music_name'/>
<input type="text" placeholder="Producer"" id="music_producer" />
</span>
<br>
<span>
<input type="text" placeholder="Artist Name" id="music_artist"/>
<input type="text" placeholder="Album Name"/>
</span><br>
<textarea name="" placeholder="Music Description" id='music_desc'></textarea>
<div class="form-group">
<label>Select file: </label>
<input class="form-control" type="file" id="myfile" />
</div>
<div class="form-group">
<div class="progress">
<div class="progress-bar progress-bar-success myprogress" role="progressbar" style="width:0%">0%</div>
</div>
<div class="msg"></div>
</div>
<input type="button" id="btn" class="btn-success" value="Upload" />
</form>
<?php include'generalModal.php';
?>
</div>
</div>
</div>
</div>
</div>
</div>
</div><!--/category-tab-->
<?php
include_once'../../music/reCommend.php'; echo'
<script src="'.$url.'panel/uploadMusic/processUpload.js"></script>';
include '../../Blog/Footer.php';

Categories