move_uploaded_file doesnt work suddenly - php

hello every one i am newbie i try to create a website i used this function move_uploaded_file its worke with some probleme like french caracter not supported but its move the file from my computer to the destination then i changed some code in php.ini to solve the problem then i uninstall the wamp server and reinstall it again no this function does to resolve the problem i simplyfied the code but still not working
if(isset($_POST['ajouter'])){
$file= $_FILES['cour']['name'];
$file_loc= $_FILES['cour']['tmp_name'];
$file_size = $_FILES['cour']['size'];
$file_type = $_FILES['cour']['type'];
$fichier = 'cours_pdf/';
move_uploaded_file($file_loc,$fichier.$file);
$q = $db->prepare("INSERT INTO tbl_uploads (file,type,size,categorie)
VALUES(:file,:file_type,:file_size,'defau')");
$q->bindValue(':file',$file);
$q->bindValue(':file_type',$file_type);
$q->bindValue(':file_size',$file_size);
$q->execute();
}
and the html code
<div id="forms" style="max-width:350px;" >
<form class="form-horizontal" action="up.php" method="post" enctype="multipart/form-data">
<div class="form-group">
<label class="btn btn-success btn-file">Browse
<input type="file" name="cour" hidden>
</label>
</div>
<div class="form-group" >
<label for="categorie">choisir la categorie ou enregistrer votre cours</label>
<select class="form-control" name="categorie" required>
<option value="cardiologie">cardiologie</option>
<option value="chirurgie_general">chirurgie_general</option>
<option value="chirurgie_thoracique">chirurgie_thoracique</option>
<option value="dermatologie">dermatologie</option>
<option value="endocrinologie">endocrinologie</option>
<option value="gynecologie">gynecologie</option>
<option value="hematologie">hematologie</option>
<option value="infectiologie">infectiologie</option>
<option value="neurologie">neurologie</option>
<option value="orl">orl</option>
<option value="pediatrie">pediatrie</option>
<option value="urologie">urologie</option>
<option value="gastro_enterologie">gastro_enterologie</option>
<option value="psychiatrie">psychiatrie</option>
</select>
</div>
<input type="submit" class="btn btn-warning" name="ajouter" value="envoyer">
</form>
</div>
please help me iam siack here and forgive my weak english thanks

The field for inputting file is hidden, remove hidden from your input.
<label class="btn btn-success btn-file">
Browse <input type="file" name="cour"> <!-- removed hiddedn -->
</label>

Related

how i can send the selected option from the database to the server in php

i have this form who get the values from the user and database(select tag)
<form class="form-signin" method="POST" action="ajoutement2.php">
<label class="sr-only" for="Nom_de_la_Categorie2">Nom de la Catégorie</label>
<input class="form-control" type="text" name="Nom_de_la_Categorie2" placeholder="Nom de la Catégorie" required autofocus><br>
<select class="custom-select">
<option disabled selected>sélectionnez la catégorie supérieure</option>
<?php while($row1 = mysqli_fetch_array($reponse1)):;?>
<option><?php echo $row1[1];?></option>
<?php endwhile;?>
</select><br><br>
<input class="btn btn-lg btn-primary btn-block" type="submit" value="Ajouter"></form?
and i want to get the value of the selected option(in the select tag) to use later
HTML:
<form class="form-signin" method="POST" action="ajoutement2.php">
<label class="sr-only" for="Nom_de_la_Categorie2">Nom de la Catégorie</label>
<input class="form-control" type="text" name="Nom_de_la_Categorie2" placeholder="Nom de la Catégorie" required autofocus><br>
<select class="custom-select" name="foo">
<option disabled selected>sélectionnez la catégorie supérieure</option>
<?php while($row1 = mysqli_fetch_array($reponse1)):;?>
<option>
<?php echo $row1[1];?>
</option>
<?php endwhile;?>
</select><br><br>
<input class="btn btn-lg btn-primary btn-block" type="submit" value="Ajouter">
</form>
PHP:
inside your PHP file ajoutement2.php, you can get the select value by using $_POST['foo'], something like:
$parentCategory = $_POST['foo'];

Form $_POST is empty (sometimes) but raw post data is fine

Heres my form:
<form method="POST" enctype="multipart/form-data" action="/my-account/update">
<select name="userType" class="form-control" >
<option value="0">0</option>
<option value="1">1</option>
<option value="2" selected="selected">2</option>
</select>
<select name="userIsInSearch" class="form-control" >
<option value="1" selected="selected">1</option>
<option value="0">0</option>
</select>
<input type="text" class="form-control" id="fwn" name="signupfname">
<input type="text" class="form-control" id="sn" name="signupsname">
<input type="text" class="form-control" id="usrf" name="signupemail">
<input type="password" class="form-control" id="pwdf" name="signuppass">
<input type="password" class="form-control" id="pwdfc" name="signuppassconf">
<input type="submit" value="Update!" class="btn btn-green" />
</form>
I've noticed that 9/10 the form POSTs completely fine but sometimes it has a problem, I've noticed this on another form on the website too and I cant figure out what is causing it.
I have found a way to make the problem happen everytime, by simply typing "alert(" (without quotations) into any of the input fields causes the entire POST to be empty but php://input is fine.
The system is in codeigniter and I have tried dumping $_POST and php://input at the top of the index.php file and have the same results so I dont think it is codeigniter causing it.
Any help or ideas greatly appreciated!

jQuery Chosen Plugin Insert Multiple data into database

I have problem with this :
Please visit http://s13.postimg.org/na4ppenfb/Stack.jpg
I use jQuery choosen. I have download that, from this address : http://harvesthq.github.io/chosen/, but I have modified that. this my code, can anybody help my problem :
<div class="side-by-side clearfix">
<div><em>Dosen Pembimbing</em>
<select data-placeholder="DOSEN PEMBIMBING KP" style="width:350px;" class="chosen-select" tabindex="5" id="dosen_pembimbing_kp" name="dosen_pembimbing_kp">
<option disabled selected>PILIH DOSEN PEMBIMBING</option>
<?php
include('config.php');
$query="SELECT * FROM dosen";
$daftar=mysql_query($query);
while ($dosen=mysql_fetch_object($daftar))
{
echo"<option>$dosen->nama</option>";
}
?>
</select>
</div>
<div><em>Mahasiswa</em>
<select data-placeholder="Pilih Mahasiswa KP" style="width:350px;" class="chosen-select" multiple tabindex="6" id="mhs" name="mhs">
<option value=""></option>
<?php
include('config.php');
$query="SELECT * FROM mahasiswa_kp";
$daftar=mysql_query($query);
while ($mhs=mysql_fetch_object($daftar))
{
echo"<option value='$mhs->nim_mhs_kp'>$mhs->nim_mhs_kp</option>";
}
?>
</select>
</div>
<div></div>
<div></div>
<div class="side-by-side clearfix">
<p> </p>
<p>
<input type="submit" name="login" value="Simpan" />
<input type="reset" name="reset" id="reset" value="Reset" class="ui-widget ui-widget-content padding ui-corner-all"/>
</p>
</div>
</div>
</div>
</div>
Please help me for insert data into database with PHP code.

Get selected text from dropdown in PHP

I am totally new in PHP, in fact the reason I am doing this is to customize a wordpress plugin so it can fit my need. So far I have a default form, what I am doing now is to add a country dropdown. Here's how I add it
<div class="control-group">
<label class="control-label" for="Country">Country :</label>
<div class="controls">
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<span class="help-inline"></span>
</div>
</div>
So far I only able to retrieve the value of selected item with
$cscf['country'];
How can I get the display text which is the country name in this case ?
You can use a hidden field, and with JavaScript and jQuery you can set the value to this field, when the selected value of your dropdown changes.
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<input type="hidden" name="country" id="country_hidden">
<script>
$(document).ready(function() {
$("#itemType_id").change(function(){
$("#country_hidden").val(("#itemType_id").find(":selected").text());
});
});
</script>
Then when your page is submitted, you can get the name of the country by using
$_POST["country"]
<select name="text selection" onchange="getText(this)">
<option value="">Select text</option>
<option value="1">my text 1</option>
<option value="2">my text 2</option>
</select>
First put a java script function on the attribute "onchange" of the select.
Then, create your function that will transfer the text in a text box by using getElementById
<script>
function getText(element) {
var textHolder = element.options[element.selectedIndex].text
document.getElementById("txt_holder").value = textHolder;
}
</script>
Then create a temporary holder:
<input type="" name="txt_holder" id="txt_holder"> type should be hidden
Then assign it in a PHP variable:
$variableName=$_POST['txt_holder'];
Try this
<?php
if(isset($_POST['save']))
{
$arrayemail = $_POST['cscf'];
$mail = $arrayemail['country'];
$explode=explode('#',$mail);
// print_r($explode);
if(isset($explode[0]))
echo ucfirst($explode[0]);
}
?>
<form method="post">
<div class="controls">
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<span class="help-inline"></span>
</div>
<div class="controls">
<input type="submit" name='save' value="Save"/>
<span class="help-inline"></span>
</div>
</form>
Try it like,
<?php
if(isset($_POST['save']))
{
//Let $_POST['cscf']['country']= malaysia#email.com
// you can explode by # and get the 0 index name of country
$cnt=explode('#',$_POST['cscf']['country']);
if(isset($cnt[0]))// check if name exists in email
echo ucfirst($cnt[0]);// will echo Malaysia
}
?>
<form method="post">
<div class="controls">
<select id="itemType_id" name="cscf[country]" class="input-xlarge">
<option value="malaysia#email.com">Malaysia</option>
<option value="indonesia#email.com">Indonesia</option>
</select>
<span class="help-inline"></span>
</div>
<div class="controls">
<input type="submit" name='save' value="Save"/>
<span class="help-inline"></span>
</div>
</form>

How to populate google maps with form data in jQuery mobile

I was hoping someone can point me in the right direction. I'm looking to have a form in my mobile version of my site that will take either the zip code or city and state plus a radius around that location and display the number of locations of a particular business.
<form id="mobileMapper" action="mapresults.php" method="post">
<div data-role="fieldcontain" class="ui-hide-label formContainer">
<label for="ziCity">City & State, or Zip:</label>
<input type="text" name="zipCity" id="zipCity" value="" placeholder="ex: Chicago, IL or 60602" />
</div>
<div data-role="fieldcontain">
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<label for="radius">Radius:</label>
<select name="radius" id="radius">
<option value="5">5 miles</option>
<option value="10">10 miles</option>
<option value="20">20 miles</option>
</select>
</div>
<div class="ui-block-b"><button type="submit" data-theme="b">Submit</button></div>
</fieldset>
</div>
</form>
Thanks
You can use the Google Places library.

Categories