This question already has answers here:
How to fix "Headers already sent" error in PHP
(11 answers)
Closed 9 years ago.
I'm aware of the fact that for header(Location) to work, no output must be sent before. The problem is that I've checked my code so many times but can't find what is actually being sent as output, thus preventing my header(Location) from working.
Can anyone spot the error?
<div id="content">
<h2>Lägg till</h2>
<p>Fyll i fälten och klicka på Lägg till för att skapa en ny kontakt i listan.</p>
<?php
$editid = $_GET['contact_id'];
$query = "SELECT *, Persons.p_id FROM Persons INNER JOIN Pictures ON (Pictures.p_id = Persons.p_id) WHERE Persons.p_id = " . $editid;
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$name = $row['name'];
$address = $row['address'];
$birthday = $row['birthday'];
$picture = $row['source'];
$p_id = $row['p_id'];
}
?>
<form action="" id="addressForm" method="post">
<ul>
<li><label for="name"><strong>Namn</strong></label><input type="text" name="name" id="name"/></li>
<li><label for="address"><strong>Adress</strong></label><input type="text" name="address" id="address"/></li>
<li><label for="year"><strong>Födelsedag</strong></label>
<select id="year" name="year">
<option value="2013">2013</option>
<option value="2012">2012</option>
<option value="2011">2011</option>
<option value="2010">2010</option>
<option value="2009">2009</option>
<option value="2008">2008</option>
<option value="2007">2007</option>
<option value="2006">2006</option>
<option value="2005">2005</option>
<option value="2004">2004</option>
<option value="2003">2003</option>
<option value="2002">2002</option>
<option value="2001">2001</option>
<option value="2000">2000</option>
<option value="1999">1999</option>
<option value="1998">1998</option>
<option value="1997">1997</option>
<option value="1996">1996</option>
<option value="1995">1995</option>
<option value="1994">1994</option>
<option value="1993">1993</option>
<option value="1992">1992</option>
<option value="1991">1991</option>
<option value="1990">1990</option>
</select>
<select name="month">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
</select>
<select name="day">
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
</select>
</li>
<li><label for="picture"><strong>Bild (URL)</strong></label><input type="text" name="picture" id="picture"/></li>
<li><input type="submit" id="submit" name="submit" value="Lägg till"/></li>
</ul>
</form>
<?php
if(isset ($_POST['submit']))
{
$editname = mysql_real_escape_string(htmlspecialchars($_POST['name']));
$editaddress = mysql_real_escape_string(htmlspecialchars($_POST['address']));
$editpicture = mysql_real_escape_string(htmlspecialchars($_POST['picture']));
$year = $_POST['year'];
$month = $_POST['month'];
$day = $_POST['day'];
if ($month < 10)
{
$month = "0$month";
}
if ($day < 10)
{
$day = "0$day";
}
$editbirthday = $year . "-" . $month . "-" . $day;
if (!empty($name) && !empty($address)){
$update = "UPDATE Persons SET name = '$editname', address = '$editaddress', birthday = '$editbirthday' WHERE p_id = '$editid'";
$result = mysql_query($update);
$query = "SELECT * FROM Persons WHERE p_id = '$editid' LIMIT 1";
$result = mysql_query($query);
while ($row = mysql_fetch_array($result)) {
$p_id = $row['p_id'];
$update = "UPDATE Pictures SET source = '$editpicture' WHERE p_id = '$editid'";
$result = mysql_query($update);
header('Location: index.php');
}
}
}
?>
</div>
Remember that an output could be:
Whitespace before <?php or after ?>
UTF-8 Byte Order Mark
Error messages or notices
print, echo
Raw <html> areas before <?php code.
So you're hitting the final point of this list...
You must put the header ABOVE any HTML output. You can just put it at the top of your document in this case. So just put all the PHP at the top.
Put the whole if statement from the following, to the top of the PHP file. I don't think this will cause any issues.
if(isset ($_POST['submit']))
I hope this helps
You already have output. Headers MUST be set before any output is sent.
"Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP."
Refer to the documentation about it. Hope this helps.
no output
no whitespace
save file without BOM
Related
I am trying to retain the value which is selected in my drop down list, I am currently using:
<?php if ($_POST['day']==1) {echo "selected='selected'"; } ?>
to achieve this, I am just wondering if there is a more effective way of doing this because in my day drop down list I have 32 values including default, month 13 including default and year 51 including default. any suggestions would be appreciated.
Use a for loop.
For example, using a month with 31 days:
for($i=1; $i<32; $i++){
echo "<option value='$i'".($i==$_POST["day"] ? " selected" : null).">$i</option>";
}
If $_POST["day"]==1, this will output:
<option value='1' selected>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
<option value='6'>6</option>
<option value='7'>7</option>
<option value='8'>8</option>
<option value='9'>9</option>
<option value='10'>10</option>
<option value='11'>11</option>
<option value='12'>12</option>
<option value='13'>13</option>
<option value='14'>14</option>
<option value='15'>15</option>
<option value='16'>16</option>
<option value='17'>17</option>
<option value='18'>18</option>
<option value='19'>19</option>
<option value='20'>20</option>
<option value='21'>21</option>
<option value='22'>22</option>
<option value='23'>23</option>
<option value='24'>24</option>
<option value='25'>25</option>
<option value='26'>26</option>
<option value='27'>27</option>
<option value='28'>28</option>
<option value='29'>29</option>
<option value='30'>30</option>
<option value='31'>31</option>
Completed:
//Days
echo "<select name='day'><option value='default' disabled>Select a day</option>";
for($i=1; $i<32; $i++){
echo "<option value='$i'".($i==$_POST["day"] ? " selected" : null).">$i</option>";
}
echo "</select>";
//Months
echo "<select name='month'><option value='default' disabled>Select a month</option>";
for($i=0; $i<30; $i++){
echo "<option value='$i'".($i==$_POST["month"] ? " selected" : null).">$i</option>";
}
echo "</select>";
//Years
echo "<select name='year'><option value='default' disabled>Select a year</option>";
for($i=2016; $i<2056; $i++){
echo "<option value='$i'".($i==$_POST["year"] ? " selected" : null).">$i</option>";
}
echo "</select>";
My query is not sending chosen state to database,
<?php
if( !isset( $_SESSION ) ){
session_start();
}
$con=mysqli_connect("localhost", "root", "", "test");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// escape variables for security
$firstname = mysqli_real_escape_string($con, $_POST['firstname']);
$lastname = mysqli_real_escape_string($con, $_POST['lastname']);
$number = mysqli_real_escape_string($con, $_POST['number']);
$email = mysqli_real_escape_string($con, $_POST['email']);
$addressone = mysqli_real_escape_string($con, $_POST['addressone']);
$addresstwo = mysqli_real_escape_string($con, $_POST['addresstwo']);
$city = mysqli_real_escape_string($con, $_POST['city']);
$state = mysqli_real_escape_string($con, $_POST['state']);
$zip = mysqli_real_escape_string($con, $_POST['zip']);
$sql="UPDATE users SET `firstname`='$firstname', `lastname` = '$lastname',`number`='$number', `email` = '$email',`addressone`='$addressone', `addresstwo` = '$addresstwo',`city`='$city', `state` = '$state', `zip` = '$zip' WHERE `id`='" .$_SESSION['id']."'";
if (!mysqli_query($con,$sql)) {
die('Error: ' . mysqli_error($con));
}
header("Location:dashboard.php");
mysqli_close($con);
?>
The part of this form is
<div class="form-group">
<label class="col-md-5 control-label" for="state">State</label>
<div class="col-md-1">
<select id="state" name="state" class="form-control" value="<?php echo $state; ?>">
<option value="1">Select</option>
<option value="2">Alabama</option>
<option value="3">Alaska</option>
<option value="4">Arizona</option>
<option value="5">Arkansas</option>
<option value="6">California</option>
<option value="7">Colorado</option>
<option value="8">Connecticut</option>
<option value="9">Delaware</option>
<option value="10">District of Colombia</option>
<option value="11">Florida</option>
<option value="12">Georgia</option>
<option value="13">Hawaii</option>
<option value="14">Idaho</option>
<option value="15">Illinois</option>
<option value="16">Indiana</option>
<option value="17">Iowa</option>
<option value="18">Kansas</option>
<option value="19">Kentucky</option>
<option value="20">Louisiana</option>
<option value="21">Maine</option>
<option value="22">Maryland</option>
<option value="23">Massachusetts</option>
<option value="24">Michigan</option>
<option value="25">Minnesota</option>
<option value="26">Mississippi</option>
<option value="27">Missouri</option>
<option value="28">Montana</option>
<option value="29">Nebraska</option>
<option value="30">Nevada</option>
<option value="31">New Hampshire</option>
<option value="32">New Jersey</option>
<option value="33">New Mexico</option>
<option value="34">New York</option>
<option value="35">North Carolina</option>
<option value="36">North Dakota</option>
<option value="37">Ohio</option>
<option value="38">Oklahoma</option>
<option value="39">Oregon</option>
<option value="40">Pennsylvania</option>
<option value="41">Rhode Island</option>
<option value="42">South Carolina</option>
<option value="43">South Dakota</option>
<option value="44">Tennessee</option>
<option value="45">Texas</option>
<option value="46">Utah</option>
<option value="47">Vermont</option>
<option value="48">Washington</option>
<option value="49">West Virginia</option>
<option value="50">Wisconsin</option>
<option value="51">Wyoming</option>
<option value="52">American Samoa</option>
<option value="57">Federated States of Micronesia</option>
<option value="53">Guam</option>
<option value="58">Marshall Islands</option>
<option value="54">Northern Mariana Islands</option>
<option value="55">Puerto Rico</option>
<option value="56">Virgin Islands</option>
<option value="59">Palau</option>
<option value="60">AA</option>
<option value="61">AE</option>
<option value="62">AP</option>
</select>
</div>
</div>
your query is wrong
This one
$sql="UPDATE users SET `firstname`='$firstname', `lastname` = '$lastname',`number`='$number', `email` = '$email',`addressone`='$addressone', `addresstwo` = '$addresstwo',`city`='$city', `state` = '$state', `zip` = '$zip' WHERE `id`='" .$_SESSION['id']."'";
remove ``
its should be like this
$sql="UPDATE users SET firstname='$firstname', lastname = '$lastname',number='$number', email = '$email',addressone='$addressone', addresstwo= '$addresstwo',`city`='$city', state = '$state', zip = '$zip' WHERE id='" .$_SESSION['id']."'";
I'm Giovanni,
I got a problem on my code, seems my code work but why the result is unmatch with the values on my combobox..
Can you tell me what's wrong?
Here's my code (on controller. function pencarian_indeks)
function pencarian_indeks() {
//muat library form validation
$this->load->library('form_validation');
if(isset($_POST['submit']))
{
//set aturan validasi untuk setiap field isian
$this->form_validation->set_rules('tanggal', 'Tanggal', 'required');
$this->form_validation->set_rules('kategori', 'Kategori', 'required');
$this->form_validation->set_rules('tahun', 'Tahun', 'required');
$this->form_validation->set_rules('bulan', 'Bulan', 'required');
//cek apakah form validasi berhasil
if ($this->form_validation->run() == FALSE)//jika validasi gagal
{
$this->session->set_flashdata('pesan', validation_errors());
redirect(base_url() . 'indeks');
}
else //jika validasi berhasil
{
$data['kategori'] = $this->input->post('kategori');
$data['tanggal'] = $this->input->post('tanggal');
$data['bulan'] = $this->input->post('bulan');
$data['tahun'] = $this->input->post('tahun');
$this->db->where('DAY(created_at)',$data['tanggal']);
$this->db->where('MONTH(created_at)',$data['bulan']);
$this->db->where('YEAR(created_at)',$data['tahun']);
$this->db->where('kategori', $data['kategori']);
$this->db->from('news');
//Pagination init
$pagination['base_url'] = base_url().'/pencarian/index/page/';
$pagination['total_rows'] = $this->db->count_all_results();
$pagination['full_tag_open'] = "<p><div class=\"pagination\">";
$pagination['full_tag_close'] = "</div></p>";
$pagination['cur_tag_open'] = "<span class=\"current\">";
$pagination['cur_tag_close'] = "</span>";
$pagination['num_tag_open'] = "<span class=\"disabled\">";
$pagination['num_tag_close'] = "</span>";
$pagination['per_page'] = "3";
$pagination['uri_segment'] = 4;
$pagination['num_links'] = 4;
$this->pagination->initialize($pagination);
$data['query'] = $this->news_model->indeks_berita($pagination['per_page'],$this->uri->segment(4,0),$data['tahun'],$data['bulan'],$data['tanggal'],$data['kategori']);
print_r($data['query']);//coba dicek dlu datanya..
exit;
$this->load->vars($data);
$data['hasil5'] = $this->news_model->tampil_populer(2);
$data = array_merge($data,admin_info());
$this->parser->parse('frontend/indeks/indeks',$data);
}
} else {
echo "Hasil Pencarian Tidak Ditemukan!!";
}
}
and on my model (function indeks_berita)
function indeks_berita($perPage, $uri,$tanggal,$bulan,$tahun,$kategori) {
$this->db->select('*');
if($tahun)
$this->db->where('YEAR(created_at)',$tahun);
if($bulan)
$this->db->where('MONTH(created_at)',$bulan);
if($tanggal)
$this->db->where('DAY(created_at)',$tanggal);
if($kategori)
$this->db->where('kategori', $kategori);
$this->db->order_by('id', 'asc');
$getData = $this->db->get('news', $perPage, $uri);
print_r ($this->db->last_query());
//print_r ($getData->result_array());
exit();
if ($getData->num_rows() > 0){
return $getData->result_array();
}else{
return null;
}
}
on my view (the comboboxes)
<p>Lihat Arsip Tanggal :
<select name="kategori">
<option value="" selected>Pilih kategori</option>
<option value="news">News</option>
<option value="bandung_city">Bandung City</option>
<option value="hot_gossip">Hot Gossip</option>
<option value="sainstek">Sains & Tek</option>
<option value="kriminal">Kriminalitas</option>
<option value="persibnews">#PERSIBONTHENEWS</option>
</select>
<select name="tahun">
<option value="" selected>Pilih Tahun</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
<option value="2017">2017</option>
<option value="2018">2018</option>
</select>
<select name="bulan">
<option value="" selected>Pilih Bulan</option>
<option value="1">Januari</option>
<option value="2">Februari</option>
<option value="3">Maret</option>
<option value="4">April</option>
<option value="5">Mei</option>
<option value="6">Juni</option>
<option value="7">Juli</option>
<option value="8">Agustus</option>
<option value="9">September</option>
<option value="10">Oktober</option>
<option value="11">November</option>
<option value="12">Desember</option>
</select>
<select name="tanggal">
<option value="" selected>Pilih</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>
<input type="submit" value="Cari!" name="cari" id="cari"/>
And here's the output query when I submitted that code :
SELECT * FROM (`news`) WHERE YEAR(created_at) = '2' AND MONTH(created_at) = '17' AND DAY(created_at) = 'bandung_city' AND `kategori` = '2014' ORDER BY `id` asc LIMIT 3
(seems not right)
Thank you, I'm glad if you help me to find what's wrong
Your form action seems to be incorrect you do not have any indeks method inside indeks contorller.
Change is as below
<form action="<?php echo base_url(); ?>indeks/pencarian_indeks" method="post">
It seems like that passing the order of the arguments to your model function is wrong.
Instead of this
$data['query'] = $this->news_model->indeks_berita(
$pagination['per_page'],
$this->uri->segment(4,0),
$data['tahun'], // it seems that model function accepts tangall as 3rd arg
$data['bulan'],
$data['tanggal'],// it seems that model function accepts tahun as 5th arg
$data['kategori']
);
Try
$data['query'] = $this->news_model->indeks_berita(
$pagination['per_page'],
$this->uri->segment(4,0),
$data['tanggal'],
$data['bulan'],
$data['tahun'],
$data['kategori']
);
Ok, i want to upload an image from my computer to the host/database, everything works fine and it all uploads to the database (image name VARCHAR as to just be wording not image), except the image doesn't want to move and I get this warning:
Upload: 6285.jpg
Type: image/jpeg
Size: 68.1669921875 kB
Temp file: /tmp/php1Be59N
Warning: move_uploaded_file(/public_html/pages/CMX/images/products/oils/6285.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/littlepe/public_html/pages/CMX/pages/extras/allFunctions.php on line 875
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php1Be59N' to '/public_html/pages/CMX/images/products/oils/6285.jpg' in /home/littlepe/public_html/pages/CMX/pages/extras/allFunctions.php on line 875
Stored in: /public_html/pages/CMX/images/products/oils/6285.jpg Upload another? or Go home?
I have been through every type of directory, the first is the absolute path:
/home/public_html/pages/CMX/images/products/oils/6285.jpg
/public_html/pages/CMX/images/products/oils/6285.jpg
/pages/CMX/images/products/oils/6285.jpg
/CMX/images/products/oils/6285.jpg
/images/products/oils/6285.jpg
/products/oils/6285.jpg
/oils/6285.jpg
The directory is writeable and correct (I would show you but cannot post images as of yet).
My Form code:
$user_check=$_SESSION['login_user'];
$sqlCommand = "(SELECT * FROM userAccount WHERE email='$user_check')";
$query = mysqli_query($con,$sqlCommand) or die("Error: ".mysqli_error($con));
$column = mysqli_fetch_array($query);
if($column['admin'] != NULL){
echo "<section class='userName'><h3>".$column['firstName']." ".$column['surname']."</h3></section>";
echo "<section class='address'>".$column['addressLine1']."<br />".$column['addressLine2']."<br />".$column['county']."<br />".$column['country']."<br />".$column['postCode']."</section>";
echo "<section class='email'><h3>".$column['email']."</h3></section>";
echo "<hr />";
echo "<section class='upNewProduct' style='height:400px;overflow:auto;'><h3>Upload New Product</h3>
<form action='extras/uploadProcess.php' method='post' enctype='multipart/form-data'>
Product Name: <input type='text' name='productName' /><br />
Product Image Sub-Catagory: <select name='prodImgCat' id='prodImgCat'>
<option selected>Choose a Sub Catagory for Image</option>
<option value='oils/'>Oil</option>
<option value='chain/'>Chain</option>
<option value='coolant/'>Coolant</option>
<option value='filter/'>Filter</option>
</select><br />
Product Image: <input type='file' name='productImg' /><br />
Description: <textarea type='text' name='shortDesc' value='' maxlength='1500' cols='22' rows='6' tabindex='6' id='shortDesc'></textarea><br />
Features: <textarea type='text' name='longDesc' value='' maxlength='1500' cols='22' rows='6' tabindex='6' id='longDesc'></textarea><br />
Price: <input type='text' name='price' /> <strong style='font-size:8pt;'>(Do <u>NOT</u> enter £ / $ / € currency symbols. <u>ONLY</u> enter numerals. <u>e.g:</u> 99.99 )</strong><br />
Catagory: <select name='catagory' id='catagory'>
<option selected>Choose a Catagory</option>
<option value='Helmets'>Helmets</option>
<option value='Gloves'>Gloves</option>
<option value='Boots'>Boots</option>
<option value='Body Protection'>Body Protection</option>
<option value='Clothing'>Clothing</option>
<option value='Bike Parts'>Bike Parts</option>
<option value='Accessories'>Accessories</option>
</select><br />
Sub-Catagory: <select name='subCat' id='subCat'>
<option selected>Choose a Sub Catagory</option>
<option value='Oil'>Oil</option>
<option value='Chain'>Chain</option>
<option value='Coolant'>Coolant</option>
</select><br />
Brand: <select name='brand' id='brand'>
<option selected>Choose a brand</option>
<option value='100%'>100%</option>
<option value='Acerbis'>Acerbis</option>
<option value='Airoh'>Airoh</option>
<option value='Akrapovic'>Akrapovic</option>
<option value='Alias'>Alias</option>
<option value='Alpinestars'>Alpinestars</option>
<option value='Answer Racing'>Answer Racing</option>
<option value='Apico'>Apico</option>
<option value='Arai'>Arai</option>
<option value='Artrax'>Artrax</option>
<option value='Asterisk'>Asterisk</option>
<option value='Beer Optics'>Beer Optics</option>
<option value='Bell'>Bell</option>
<option value='Blackrock'>Blackrock</option>
<option value='Bolt'>Bolt</option>
<option value='Cycra'>Cycra</option>
<option value='Deft Family'>Deft Family</option>
<option value='DEP'>DEP</option>
<option value='Dragon'>Dragon</option>
<option value='DRC'>DRC</option>
<option value='Dunlop'>Dunlop</option>
<option value='EKS Brand'>EKS Brand</option>
<option value='Engine Ice'>Engine Ice</option>
<option value='EVS'>EVS</option>
<option value='Factory Arme'>Factory Arme</option>
<option value='Factory Effex'>Factory Effex</option>
<option value='Fly Racing'>Fly Racing</option>
<option value='Forcefield Armour'>Forcefield Armour</option>
<option value='Forma'>Forma</option>
<option value='Fro Systems'>Fro Systems</option>
<option value='Gaerne'>Gaerne</option>
<option value='Goldentyre'>Goldentyre</option>
<option value='GoPole'>GoPole</option>
<option value='GoPro'>GoPro</option>
<option value='HiFlo Filtro'>HiFlo Filtro</option>
<option value='JT Braking'>JT Braking</option>
<option value='K-Edge'>K-Edge</option>
<option value='Kryptonite'>Kryptonite</option>
<option value='Lazer'>Lazer</option>
<option value='Leatt'>Leatt</option>
<option value='Matrix Concepts'>Matrix Concepts</option>
<option value='Mechanix Wear'>Mechanix Wear</option>
<option value='Motion Pro'>Motion Pro</option>
<option value='Motorex'>Motorex</option>
<option value='Muc Off'>Muc Off</option>
<option value='No Toil'>No Toil</option>
<option value='Oakley'>Oakley</option>
<option value='ODI Troy Lee'>ODI Troy Lee</option>
<option value='Ogio'>Ogio</option>
<option value='One Industries'>One Industries</option>
<option value='Park Tool'>Park Tool</option>
<option value='POD'>POD</option>
<option value='Polisport'>Polisport</option>
<option value='Pro Clean'>Pro Clean</option>
<option value='Progrip'>Progrip</option>
<option value='Putoline'>Putoline</option>
<option value='Race FX'>Race FX</option>
<option value='Raptor Titanium'>Raptor Titanium</option>
<option value='Renthal'>Renthal</option>
<option value='Rip n Roll'>Rip n Roll</option>
<option value='Risk Racing'>Risk Racing</option>
<option value='RK Chains'>RK Chains</option>
<option value='SBS Brakes'>SBS Brakes</option>
<option value='Science in Sport'>Science in Sport</option>
<option value='Scott'>Scott</option>
<option value='Seven'>Seven</option>
<option value='Shoei'>Shoei</option>
<option value='Shot'>Shot</option>
<option value='Sidi'>Sidi</option>
<option value='SixSixOne'>SixSixOne</option>
<option value='SM Pro Platinum'>SM Pro Platinum</option>
<option value='Smith'>Smith</option>
<option value='Spada'>Spada</option>
<option value='Sunline'>Sunline</option>
<option value='Suomy'>Suomy</option>
<option value='THH'>THH</option>
<option value='Thor'>Thor</option>
<option value='Troy Lee Designs'>Troy Lee Designs</option>
<option value='Twin Air'>Twin Air</option>
<option value='Venhill'>Venhill</option>
<option value='VP Racing'>VP Racing</option>
<option value='Wizard Wash'>Wizard Wash</option>
<option value='Yoshimura'>Yoshimura</option>
<option value='Zeta'>Zeta</option>
</select>
<input id='contactBtn' type='submit' name='submit' value='Submit Product' tabindex='7' />
</form>
</section>";
My PHP code:
if (!$_POST['productName'] | !$_POST['prodImgCat'] | !$_POST['shortDesc'] | !$_POST['longDesc'] | !$_POST['price'] | !$_POST['catagory'] | !$_POST['subCat'] | !$_POST['brand']){
die('You did not complete all of the required fields! Try Again?');
}
$productName = $_POST['productName'];
$prodImgCat = $_POST['prodImgCat'];
$shortDesc = $_POST['shortDesc'];
$longDesc = $_POST['longDesc'];
$price = $_POST['price'];
$catagory = $_POST['catagory'];
$subCat = $_POST['subCat'];
$brand= $_POST['brand'];
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["productImg"]["name"]);
$extension = end($temp);
if ((($_FILES["productImg"]["type"] == "image/gif")|| ($_FILES["productImg"]["type"] == "image/jpeg")|| ($_FILES["productImg"]["type"] == "image/jpg")|| ($_FILES["productImg"]["type"] == "image/pjpeg")|| ($_FILES["productImg"]["type"] == "image/x-png")|| ($_FILES["productImg"]["type"] == "image/png"))&& ($_FILES["productImg"]["size"] < 200000)&& in_array($extension, $allowedExts)){
if ($_FILES["productImg"]["error"] > 0){
echo "Return Code: " . $_FILES["productImg"]["error"] . "<br>";
}else{
echo "Upload: " . $_FILES["productImg"]["name"] . "<br>";
echo "Type: " . $_FILES["productImg"]["type"] . "<br>";
echo "Size: " . ($_FILES["productImg"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["productImg"]["tmp_name"] . "<br>";
if (file_exists("/public_html/pages/CMX/images/products/".$_POST['prodImgCat'].$_FILES['productImg']['name']."")){
echo $_FILES['productImg']['name']." already exists.";
}else{
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! LINE 875 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
move_uploaded_file($_FILES['productImg']['tmp_name'], "/public_html/pages/CMX/images/products/".$_POST['prodImgCat'].$_FILES['productImg']['name']);
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
echo "Stored in: "."/public_html/pages/CMX/images/products/".$_POST['prodImgCat'].$_FILES['productImg']['name']." <a href='http://www.littlepenguindesigns.co.uk/pages/CMX/pages/userAccount.php'>Upload another?</a> or <a href='http://www.littlepenguindesigns.co.uk/pages/CMX/pages/index.php'>Go home?</a>";
}
}
}else{
echo "Invalid file";
}
$productImgLocation = "".$_POST['prodImgCat']."".$_FILES['productImg']['name']."";
$insertProduct = ("INSERT INTO product (productName, productImg, shortDesc, longDesc, price, catagory, subCat, brand) VALUES ('".$_POST['productName']."', '".$productImgLocation."' '".$_POST['shortDesc']."', '".$_POST['longDesc']."', '".$_POST['price']."', '".$_POST['catagory']."', '".$_POST['subCat']."', '".$_POST['brand']."')");
$add_product = mysqli_query($con,$insertProduct);
mysqli_close($con);
So after all of that my question is this, what the flaming heck am I doing wrong here?, the file and directory are there and yet it doesn't want to move from the tmp folder to the chosen folder, please help as this is really starting to annoy me.
NOTE: My injection,etc. code is going to amended once i have completed the upload form, so please refrain from just posting about injections and the like, thank you.
Hey, i just wanted to know if you guys know why this does not work.
http://www.anitard.org/siggen/siggen_stripes/
When you've uploaded an image the script gets the file path from the form and then when you press create a signature is supposed to appear with the image you uploaded, but it doesn't!
If anyone know what the problem is, please let me know.
this is my code
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Signature Generator</title>
</head>
<body>
<div style="float:left; width: 280px; margin-right: 3px;">
<form name="frm" method="post">
<p></p>
<p>Enter Text:
<input name="user" type="text" size="20" class="textbox">
<br /><br />
<p> Color:
<select name="color2">
<option value="color_standard">Standard</option>
<option value="color_blue">Blue</option>
<option value="color_lightblue">Light blue</option>
<option value="color_red">Red</option>
<option value="color_yellow">Yellow</option>
<option value="color_green">Green</option>
<option value="color_purple">Purple</option>
</select>
<br /><br />
<i><font size="1" face="verdana">Choose if your going to use one of our "anime" pictures or upload your own image.</font></i>
<br />
<script type="text/javascript">
function annClick()
{
document.getElementById('butta').disabled = true;
document.getElementById('strup').disabled = true;
document.getElementById('namez').disabled = false;
}
function ownClick()
{
document.getElementById('butta').disabled = false;
document.getElementById('strup').disabled = false;
document.getElementById('namez').disabled = true;
}
</script>
<input type="radio" name="checktype" id="ann" onclick="javascript:annClick();" value="1"> Anime<br>
<input type="radio" name="checktype" id="own" onclick="javascript:ownClick();" value="2"> Upload<br>
<br />
<u>Anime</u><br />
<select name="anime" id="namez" size="9" disabled="true" onclick="document.getElementById( 'imgUpload' ).src=this.value+'.png';" />
<option value="hack_twillight">.hack//Legend of the Twilight Bracelet</option>
<option value="hack_roots">.hack//Roots</option>
<option value="hack_sign">.hack//SIGN</option>
<option value="07_ghost">07-Ghost</option>
<option value="12_kingdoms">12 kokuki ( 12 kingdoms )</option>
<option value="afro_samurai">Afro Samurai</option>
<option value="ah_my_goddess">Ah! My Goddess</option>
<option value="ai_yori_aoshi">Ai yori Aoshi</option>
<option value="ai_yori_aoshi_enishi">Ai yori Aoshi ~enishi~</option>
<option value="air_gear">Air Gear </option>
<option value="air_tv">Air TV</option>
<option value="aishiteru_ze_baby">Aishiteru ze Baby</option>
<option value="akagi">Akagi</option>
<option value="akikan">Akikan!</option>
<option value="allison_to_lillia">Allison to Lillia</option>
<option value="amaenaideyo">Amaenaideyo</option>
<option value="amaenaideyo_katsu">Amaenaideyo Katsu</option>
<option value="amatsuki">Amatsuki</option>
<option value="angel_heart">Angel heart</option>
<option value="angelic_layer">Angelic layer</option>
<option value="antique_bakery">Antique bakery</option>
<option value="aria_the_animation">ARIA The animation</option>
<option value="aria_the_natural">ARIA The natural</option>
<option value="aria_the_origination">ARIA The origination</option>
<option value="asu_no_yoichi">Asu no yoichi</option>
<option value="ayakashi">Ayakashi</option>
<option value="azumanga_daioh">Azumanga daioh</option>
<option value="baccano">Baccano</option>
<option value="bakuretsu_tenshi">Bakuretsu Tenshi</option>
<option value="bamboo_blade">Bamboo blade</option>
<option value="basilisk">Basilisk</option>
<option value="berserk">Berserk</option>
<option value="basquash">Basquash</option>
<option value="beck">Beck</option>
<option value="black_cat">Black Cat</option>
<option value="black_lagoon">Black Lagoon</option>
<option value="black_lagoon_the_second_barrage">Black Lagoon the second barrage</option>
<option value="bleach">Bleach</option>
<option value="blood">Blood+</option>
<option value="bokura_ga_ita">Bokura ga ita</option>
<option value="bokura_no">Bokura no</option>
<option value="bokusatsu_tenshi_dokuro_chan">Bokusatsu tenshi dokuro chan</option>
<option value="bokusatsu_tenshi_dokuro_chan_second.png">Bokusatsu tenshi dokuro chan 2</option>
<option value="bounen_no_xamd">Bounen no xamd</option>
<option value="busou_renkin">Busou renkin</option>
<option value="canvas2">Canvas 2</option>
<option value="capeta">Capeta</option>
<option value="card_captor_sakura">Card captor sakura</option>
<option value="casshern_sins">Casshern sins</option>
<option value="chaos_head">Chaos head</option>
<option value="chis_sweet_home">Chi's sweet home</option>
<option value="chobits">Chobits</option>
<option value="chocotto_sister">Choccotto_sister</option>
<option value="chrno_crusade">Chrno crusade</option>
<option value="clannad">Clannad</option>
<option value="claymore">Claymore</option>
<option value="cluster_edge">Cluster edge</option>
<option value="code_geass">Code geass</option>
<option value="code_geass_r2">Code geass R2</option>
<option value="cosplay_complex">Cosplay complex</option>
<option value="cowbow_bebop">Cowboy bebop</option>
<option value="crayon_shin_chan">Crayon shin chan</option>
<option value="cross_game">Cross game</option>
<option value="d_gray_man">D.Gray Man</option>
<option value="dn_angel">DN Angel</option>
<option value="da_capo">Da capo</option>
<option value="da_capo_ii">Da capo II</option>
<option value="darker_than_black">Darker than black</option>
<option value="dears">DearS</option>
<option value="death_note">Death note</option>
<option value="dennou_coil">Dennou coil</option>
<option value="desert_punk">Desert punk</option>
<option value="devil_may_cry">Devil may cry</option>
<option value="doujin_work">Doujin work</option>
<option value="dragon_ball">Dragon ball</option>
<option value="dragon_ball_gt">Dragon ball GT</option>
<option value="dragon_ball_z">Dragon ball Z</option>
<option value="dragonaut_the_resonance">Dragonaut -the resonance-</option>
<option value="fate_stay_night">Fate/stay night</option>
<option value="final_approach">Final approach</option>
<option value="flame_of_recca">Flame of recca</option>
<option value="flcl">FLCL</option>
<option value="fruits_basket">Fruits basket</option>
<option value="full_metal_panic">Full metal panic</option>
<option value="full_metal_panic_second_raid">Full metal panic secondn raid</option>
<option value="full_metal_panic_fumoffu">Full metal panic fumoffu</option>
<option value="full_moon_wo_sagashite">Full moon wo sagashite</option>
<option value="fullmetal_alchemist">Fullmetal alchemist</option>
<option value="fullmetal_alchemist_brotherhood">Fullmetal alchemist brotherhood</option>
<option value="fushigi_yuugi">Fushigi yuugi</option>
<option value="h20">H2O ~footprints in the sand~</option>
<option value="haibane_renmei">Haibane renmei</option>
<option value="hajime_no_ippo">Hajime no ippo</option>
<option value="hana_yori_dango">Hana yori dango</option>
<option value="hanasakeru_seishonen">Hanasakeru seishonen</option>
<option value="hanaukyo_maids">Hanaukyo maids</option>
<option value="hanaukyo_maids_le_verite">Hanaukyo maids le verite</option>
<option value="hanbun_no_tsukai">Hanbun no tsukai</option>
<option value="hand_maid_may">Hand maid may</option>
<option value="happiness">Happiness</option>
<option value="happy_lesson">Happy lesson</option>
<option value="hatsukoi_limited">Hatsukoi limited</option>
<option value="hayate_no_gotoku">Hayate no gotoku</option>
<option value="hayate_no_gotoky_2">Hayate no gotoku 2</option>
<option value="he_is_my_master">He is my master</option>
<option value="hellsing">Hellsing</option>
<option value="heroic_age">Heroic Age</option>
<option value="hetalia_axis_powers">Hetalia axis powers</option>
<option value="hidamari_sketch">Hidamari sketch</option>
<option value="hidamari_sketch_x365">Hidamari sketch x365</option>
<option value="high_school_girls">High school girls ( Girls high )</option>
<option value="higurashi_no_naku_koro_ni">Higurashi no naku koro ni</option>
<option value="higurashi_no_naku_koro_ni_kai">Higurashi no naku koro ni kai</option>
<option value="higurashi_no_naku_koro_ni_rei">Higurashi no naku koro ni rei</option>
<option value="hikaru_no_go">Hikaru no go</option>
<option value="himawari">Himawari</option>
<option value="himitsu_the_revelation">Himitsu the revelation</option>
<option value="honey_and_clover">Honey and clover</option>
<option value="honey_and_clover2">Honey and clover 2</option>
<option value="hunter_x_hunter">Hunter x hunter</option>
<option value="hyakko">Hyakko</option>
<option value="k_on">K-on</option>
<option value="kaiba">Kaiba</option>
<option value="kaleido_star">Kaleido star</option>
<option value="kamen_no_maid_guy">Kamen no maid guy</option>
<option value="kamisama_kazoku">Kamisama kazoku</option>
<option value="kannagi">Kannagi</option>
<option value="kanokon">Kanokon</option>
<option value="kanon">Kanon</option>
<option value="karin">Karin</option>
<option value="kasimasi">Kasimasi</option>
<option value="katekyo_hitman_reborn">Katekyo hitman reborn</option>
<option value="kaze_no_stigma">Kaze no stigma</option>
<option value="kekkaishi">Kekkaishi</option>
<option value="kemono_no_souja_erin">Kemono no souja erin</option>
<option value="kenichi">Kenichi</option>
<option value="kiba">Kiba</option>
<option value="kiddy_grade">Kiddy grade</option>
<option value="kimi_ga_nozomu_eien">Kimi ga nozomu eien</option>
<option value="kimikiss_pure_rouge">Kimikiss pure rouge</option>
<option value="kirarin_revolution">Kirarin revolution</option>
<option value="kodomo_no_jikan">Kodomo no jikan</option>
<option value="koharu_biyori">Koharu biyori</option>
<option value="koihime_musou">Koihime Musou</option>
<option value="kurenai">Kurenai</option>
<option value="kurogane_no_linebarrel">Kurogane no linebarell</option>
<option value="kurokami">Kurokami</option>
<option value="kuroshitsuji">Kuroshitsuji</option>
<option value="kyo_kara_maoh">Kyo kara maoh</option>
<option value="kurozuka">Kurozuka</option>
<option value="kyouran_kazoku_nikki">Kyouran kazoku nikki</option>
<option value="nabari_no_ou">Nabari no ou</option>
<option value="nana">Nana</option>
<option value="naruto">Naruto</option>
<option value="naruto_shippuuden">Naruto shippuuden</option>
<option value="natsu_no_arashi">Natsu no arashi</option>
<option value="natsume_yuujinchou">Natsume yuujinchou</option>
<option value="zoku_natsume_yuujinchou">Zoku natsume yuuijinchou</option>
<option value="negima">Negima!?</option>
<option value="neo_angelique_abyss">Neo angelique abyss</option>
<option value="neon_genesis_evangelion">Neon genesis evangelion</option>
<option value="nhk_ni_youkoso">Nhk ni youkoso</option>
<option value="night_head_genesis">Night head genesis</option>
<option value="ninja_scroll">Ninja scroll</option>
<option value="nodame_cantabile">Nodame cantabile</option>
<option value="nodame_cantabile_paris">Nodame cantabile paris</option>
<option value="noein">Noein</option>
<option value="noir">Noir</option>
<option value="queens_blade">Queens blade</option>
<option value="ragnarok">Ragnarok</option>
<option value="rahxephon">RahXephon</option>
<option value="ranma">Ranma ½</option>
<option value="real_drive">RD sennou chosashitsu</option>
<option value="read_or_die">Read or die</option>
<option value="rec">REC</option>
<option value="rental_magica">Rental magica</option>
<option value="ristorante_paradiso">Ristorante paradiso</option>
<option value="rizelmine">Rizelmine</option>
<option value="romeo_x_juliet">Romeo x juliet</option>
<option value="rosario_to_vampire">Rosario to vampire</option>
<option value="rozen_maiden">Rozen maiden</option>
<option value="rurouni_kenshin">Rurouni kenshin</option>
<option value="tactical_roar">Tactical roar</option>
<option value="tale_of_abyss">Tale of abyss</option>
<option value="tales_of_symphonia">Tales of symphonia</option>
<option value="tears_to_tiara">Tears to tiara</option>
<option value="gurren_lagann">Tengen toppa gurren lagann</option>
<option value="tenjou_tenge">Tnjou tenge</option>
<option value="tenshi_na_konamaiki">Tenshi na konamaiki</option>
<option value="birdy">Tetsuwan birdy decode</option>
<option value="tsukiyomi_moon_phase">Tsukiyomi moon phase</option>
<option value="index">To aru majutsu no index</option>
<option value="to_love_ru">To love ru</option>
<option value="today_in_class_5_2">Today in class 5-2</option>
<option value="toshokan_sensou">Toshokan sensou</option>
<option value="tokyo_mew_mew">Tokyo mew mew</option>
<option value="toradora">Toradora</option>
<option value="touch">Touch</option>
<option value="trigun">Trigun</option>
<option value="trinity_blood">Trinity blood</option>
<option value="true_tears">True tears</option>
<option value="tsubasa_chronicles">Tsubasa chronicles</option>
<option value="utawarerumono">Utawarerumono</option>
</select>
<br />
<br /><br />
<input type="submit" class="button" value="Create">
<br />
</p>
</form>
<br />
<table width="364" height="112" border="0" cellpadding="3">
<tr>
<td width="350">
<?php
if (isset($_REQUEST['anime']) && !empty($_REQUEST['anime'])) {
echo "<img type=\"image\" width=\"350\" height=\"100\" border=\"0\" src=\"sig.php?user=".$_REQUEST['user']."&anime=".$_REQUEST['anime']."&color2=".$_REQUEST['color2']."\" />";
} elseif (isset($_REQUEST['animeinput']) && !empty($_REQUEST['animeinput'])) {
echo "<img type=\"image\" width=\"350\" height=\"100\" border=\"0\" src=\"sig.php?user=".$_REQUEST['user']."&anime=".substr($_REQUEST['animeinput'],0,15)."&color2=".$_REQUEST['color2']."\" />";
}
?>
</td>
</tr>
</table>
</div>
<div style="float:left;">
<script type="text/javascript">
// description : upload the image to the server
// notes : 1. open a new window
// 2. submit the form to it
function UploadImage()
{
window.open("","upload_image");
document.getElementById( 'frmUpload' ).target="upload_image";
document.getElementById( 'frmUpload' ).submit();
}
// description : set the src of the image to the uploaded one
function SetImageFile( pImgSrc )
{
document.getElementById( 'imgUpload' ).src=pImgSrc;
}
function setInputFile( pSRC )
{
document.frm.animeinput.value=pSRC;
}
</script>
<form action="<?php echo $_server['php-self']; ?>" method="post" enctype="multipart/form-data" id="something" class="uniForm">
<input name="new_image" id="new_image" size="20" type="file" class="fileUpload" />
<button name="submit" type="submit" class="submitButton">Upload</button>
<br />
<br />
<table>
<tr>
<td>
<em><font size="1" face="verdana">Preview of your picture/anime picture </font></em><br />
</td>
</tr>
</table>
<table width="270" height="67" style="border:1px solid;">
<tr>
<td width="270" height="67">
<img src="loading.gif" name="imgUpload" width="270" height="67" border="0" id="imgUpload">
</td>
</tr>
</table>
</form>
<?php
if(isset($_POST['submit'])){
if (isset ($_FILES['new_image'])){
$imagename = $_FILES['new_image']['name'];
$source = $_FILES['new_image']['tmp_name'];
$target = "temporary_images/".$imagename;
move_uploaded_file($source, $target);
$imagepath = $imagename;
$save = "temporary_images/" . $imagepath; //This is the new file you saving
$file = "temporary_images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 350;
$modheight = 100;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
$save = "temporary_images/sml_" . $imagepath; //This is the new file you saving
$file = "temporary_images/" . $imagepath; //This is the original file
list($width, $height) = getimagesize($file) ;
$modwidth = 80;
$modheight = 100;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100) ;
echo "Large image: <img src='temporary_images/".$imagepath."'><br>";
echo "<form>";
echo '<input type="text" value="' .$imagepath. '" name="animeinput" id="animeinput" size="20" class="textbox">';
echo "</form>";
}
}
?>
<?php
// Define the folder to clean
// (keep trailing slashes)
$captchaFolder = 'temporary_images/';
// Filetypes to check (you can also use *.*)
$fileTypes = '*.jpg';
// Here you can define after how many
// minutes the files should get deleted
$expire_time = 1;
// Find all files of the given file type
foreach (glob($captchaFolder . $fileTypes) as $Filename) {
// Read file creation time
$FileCreationTime = filectime($Filename);
// Calculate file age in seconds
$FileAge = time() - $FileCreationTime;
// Is the file older than the given time span?
if ($FileAge > ($expire_time * 60)){
// Now do something with the olders files...
print "The file $Filename is older than $expire_time minutes\n";
unlink($Filename);
// For example deleting files:
//unlink($Filename);
}
}
?>
</div>
</body>
</html>
Try this:
<form name="frm" method="post" action="urlhere.php" enctype="multipart/form-data">