I have 2 nested tables. Parent table row contains child table. Both tables can add rows if needed by add button. parent table values inserts in product_size table in database and child table values inserts in product_color table. Parent table contains sizes and child table contains color and quantity of items of that size. i want to insert child table values(color & quantity) across parent table row. Means parent first row child table values should insert across parent first row only and the child table values that is in second row of parent table should insert across parent second row. Currently my code takes all Child table values from all rows of parent table and inserts in database across first row and then takes all Child table values from all rows of parent table again and inserts in database across second row of parent table. Please Check my code and help me point out where is the problem in my code. here is the picture of my Html table.
function addRow(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[1].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
if (i == colCount - 1) //last column which adds child table
{
//Get child table id of first row
var tableID = table.rows[1].cells[i].childNodes[1].getAttribute("id");
//Replace all occurances of parent table id's with new unique table id for child table before writing the information to DOM
newcell.innerHTML = table.rows[1].cells[i].innerHTML.replace(new RegExp(tableID,"g"), "dataTable" + Math.floor((Math.random() * 1000) + 1));
}
else //For other columns there is no need to assign unique id for controls
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
function deleteRow(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
function addRow1(tableID) {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
var row = table.insertRow(rowCount);
var colCount = table.rows[1].cells.length;
for(var i=0; i<colCount; i++) {
var newcell = row.insertCell(i);
newcell.innerHTML = table.rows[1].cells[i].innerHTML;
//alert(newcell.childNodes);
switch(newcell.childNodes[0].type) {
case "text":
newcell.childNodes[0].value = "";
break;
case "checkbox":
newcell.childNodes[0].checked = false;
break;
case "select-one":
newcell.childNodes[0].selectedIndex = 0;
break;
}
}
}
function deleteRow1(tableID) {
try {
var table = document.getElementById(tableID);
var rowCount = table.rows.length;
for(var i=0; i<rowCount; i++) {
var row = table.rows[i];
var chkbox = row.cells[0].childNodes[0];
if(null != chkbox && true == chkbox.checked) {
if(rowCount <= 1) {
alert("Cannot delete all the rows.");
break;
}
table.deleteRow(i);
rowCount--;
i--;
}
}
}catch(e) {
alert(e);
}
}
table {
border-collapse: collapse;
width: 100%;
border:1px solid #1E90FF;
}
th, td {
text-align: left;
padding: 8px;
border:1px solid #1E90FF;
}
th {
background-color: #1E90FF;
color: white;
}
<TABLE id="dataTable">
<thead>
<tr>
<th style="text-align: center;"> Select </th>
<th style="text-align: center;"> <b>Size</b> </th>
<th style="text-align: center;"> <b>Color & Quantity</b> </th>
</tr>
</thead>
<tbody>
<tr id='C1' class='customer'>
<td><input type="checkbox" name="chk"/></td>
<td><select name="size[]" id="size" required="" >
<option value="">Select Size</option>
<option value="Small">Small</option>
<option value=">Medium">Medium</option>
<option value="Large">Large</option>
</select></td>
<td>
<TABLE style="margin-top: 20px;" id="dataTable1" width="400px" border="1">
<thead>
<th> Select </th>
<th> <b>Color Quantity</b> </th>
</thead>
<TR>
<TD><INPUT type="checkbox" name="chk"/></TD>
<TD>
<select name="color[]" required="" >
<option value="">Select Color</option>
<option value="Alizarin">Alizarin</option>
<option value="Amaranth">Amaranth</option>
<option value="Amber">Amber</option>
<option value="Amethyst">Amethyst</option>
<option value="Apricot">Apricot</option>
<option value="Aqua">Aqua</option>
<option value="Aquamarine">Aquamarine</option>
<option value="Asparagus">Asparagus</option>
<option value="Auburn">Auburn</option>
<option value="Azure">Azure</option>
<option value="Beige">Beige</option>
<option value="Bistre">Bistre</option>
<option value="Black">Black</option>
<option value="Blue">Blue</option>
<option value="Blue Green">Blue Green</option>
<option value="Blue Violet">Blue Violet</option>
<option value="Bondi Blue">Bondi Blue</option>
<option value="Brass">Brass</option>
<option value="Bronze">Bronze</option>
<option value="Brown">Brown</option>
<option value="Buff">Buff</option>
<option value="Burgundy">Burgundy</option>
<option value="Burnt Orange">Burnt Orange</option>
<option value="Burnt Sienna">Burnt Sienna</option>
<option value="Burnt Umber">Burnt Umber</option>
<option value="Camouflage Green">Camouflage Green</option>
<option value="Caput Mortuum">Caput Mortuum</option>
<option value="Cardinal">Cardinal</option>
<option value="Carmine">Carmine</option>
<option value="Carrot orange">Carrot orange</option>
<option value="Celadon">Celadon</option>
<option value="Cerise">Cerise</option>
<option value="Cerulean">Cerulean</option>
<option value="Champagne">Champagne</option>
<option value="Charcoal">Charcoal</option>
<option value="Chartreuse">Chartreuse</option>
<option value="Cherry Blossom Pink">Cherry Blossom Pink</option>
<option value="Chestnut">Chestnut</option>
<option value="Chocolate">Chocolate</option>
<option value="Cinnabar">Cinnabar</option>
<option value="Cinnamon">Cinnamon</option>
<option value="Cobalt"> Cobalt</option>
<option value="Copper">Copper</option>
<option value="Coral">Coral</option>
<option value="Corn">Corn</option>
<option value="Cornflower">Cornflower</option>
<option value="Cream">Cream</option>
<option value="Crimson">Crimson</option>
<option value="Cyan">Cyan</option>
<option value="Dandelion">Dandelion</option>
<option value="Denim">Denim</option>
<option value="Ecru">Ecru</option>
<option value="Emerald">Emerald</option>
<option value="Eggplant">Eggplant</option>
<option value="Falu red">Falu red</option>
<option value="Fern green">Fern green</option>
<option value="Firebrick">Firebrick</option>
<option value="Flax">Flax</option>
<option value="Forest green">Forest green</option>
<option value="French Rose">French Rose</option>
<option value="Fuchsia">Fuchsia</option>
<option value="Gamboge">Gamboge</option>
<option value="Gold">Gold</option>
<option value="Goldenrod">Goldenrod</option>
<option value="Green">Green</option>
<option value="Grey">Grey</option>
<option value="Han Purple">Han Purple</option>
<option value="Harlequin">Harlequin</option>
<option value="Heliotrope">Heliotrope</option>
<option value="Hollywood Cerise">Hollywood Cerise</option>
<option value="Indigo">Indigo</option>
<option value="Ivory">Ivory</option>
<option value="Jade">Jade</option>
<option value="Kelly green">Kelly green</option>
<option value="Khaki">Khaki</option>
<option value="Lavender">Lavender</option>
<option value="Lawn green">Lawn green</option>
<option value="Lemon">Lemon</option>
<option value="Lemon chiffon">Lemon chiffon</option>
<option value="Lilac">Lilac</option>
<option value="Lime">Lime</option>
<option value="Lime green">Lime green</option>
<option value="Linen">Linen</option>
<option value="Magenta">Magenta</option>
<option value="Magnolia">Magnolia</option>
<option value="Malachite">Malachite</option>
<option value="Maroon">Maroon</option>
<option value="Mauve">Mauve</option>
<option value="Midnight Blue">Midnight Blue</option>
<option value="Mint green">Mint green</option>
<option value="Misty rose">Misty rose</option>
<option value="Moss green">Moss green</option>
<option value="Mustard">Mustard</option>
<option value="Myrtle">Myrtle</option>
<option value="Navajo white">Navajo white</option>
<option value="Navy Blue">Navy Blue</option>
<option value="Ochre">Ochre</option>
<option value="Office green">Office green</option>
<option value="Olive">Olive</option>
<option value="Olivine">Olivine</option>
<option value="Orange">Orange</option>
<option value="Orchid">Orchid</option>
<option value="Papaya whip">Papaya whip</option>
<option value="Peach">Peach</option>
<option value="Pear">Pear</option>
<option value="Periwinkle">Periwinkle</option>
<option value="Persimmon">Persimmon</option>
<option value="Pine Green">Pine Green</option>
<option value="Pink">Pink</option>
<option value="Platinum">Platinum</option>
<option value="Plum">Plum</option>
<option value="Powder blue">Powder blue</option>
<option value="Puce">Puce</option>
<option value="Prussian blue">Prussian blue</option>
<option value="Psychedelic purple">Psychedelic purple</option>
<option value="Pumpkin">Pumpkin</option>
<option value="Purple">Purple</option>
<option value="Quartz Grey">Quartz Grey</option>
<option value="Raw umber">Raw umber</option>
<option value="Razzmatazz">Razzmatazz</option>
<option value="Red">Red</option>
<option value="Robin egg blue">Robin egg blue</option>
<option value="Rose">Rose</option>
<option value="Royal blue">Royal blue</option>
<option value="Royal purple">Royal purple</option>
<option value="Ruby">Ruby</option>
<option value="Russet">Russet</option>
<option value="Rust">Rust</option>
<option value="Safety orange">Safety orange</option>
<option value="Saffron">Saffron</option>
<option value="Salmon">Salmon</option>
<option value="Sandy brown">Sandy brown</option>
<option value="Sangria">Sangria</option>
<option value="Sapphire">Sapphire</option>
<option value="Scarlet">Scarlet</option>
<option value="School bus yellow">School bus yellow</option>
<option value="Sea Green">Sea Green</option>
<option value="Seashell">Seashell</option>
<option value="Sepia">Sepia</option>
<option value="Shamrock green">Shamrock green</option>
<option value="Shocking Pink">Shocking Pink</option>
<option value="Silver">Silver</option>
<option value="Sky Blue">Sky Blue</option>
<option value="Slate grey">Slate grey</option>
<option value="Smalt">Smalt</option>
<option value="Spring bud">Spring bud</option>
<option value="Spring green">Spring green</option>
<option value="Steel blue">Steel blue</option>
<option value="Tan">Tan</option>
<option value="Tangerine">Tangerine</option>
<option value="Taupe">Taupe</option>
<option value="Teal">Teal</option>
<option value="Tenné">Tenné</option>
<option value="Terra cotta">Terra cotta</option>
<option value="Thistle">Thistle</option>
<option value="Titanium White">Titanium White</option>
<option value="Tomato">Tomato</option>
<option value="Turquoise">Turquoise</option>
<option value="Tyrian purple">Tyrian purple</option>
<option value="Ultramarine">Ultramarine</option>
<option value="Van Dyke Brown">Van Dyke Brown</option>
<option value="Vermilion">Vermilion</option>
<option value="Violet">Violet</option>
<option value="Viridian">Viridian</option>
<option value="Wheat">Wheat</option>
<option value="White">White</option>
<option value="Wisteria">Wisteria</option>
<option value="Xanthic">Xanthic</option>
<option value="Yellow">Yellow</option>
<option value="Zucchini">Zucchini</option>
</select>
<input style="width: 120px; height: 26px; " oninput="javascript: if (this.value.length > this.maxLength) this.value = this.value.slice(0, this.maxLength);" type="number" name="dress_quantity[]" class="qty1" min="1" max="1000" maxlength="4" placeholder="Size Quantity" value="" required="">
</TD>
</TR>
</TABLE>
<INPUT type="button" value="Add Row" onclick="addRow1('dataTable1')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow1('dataTable1')" />
</td>
</tr>
</tbody>
</TABLE>
<INPUT type="button" value="Add Row" onclick="addRow('dataTable')" />
<INPUT type="button" value="Delete Row" onclick="deleteRow('dataTable')" />
PHP CODE:
if (isset($_POST['submit']))
{
$con=mysqli_connect("localhost", "root", "");
mysqli_select_db($con,"login");
for ($i=0; $i<count($_POST['size']); $i++){
$size = $_POST['size'][$i];
$qry1="INSERT INTO product_size (product_size) VALUES ('$size')";
$result1=mysqli_query($con,$qry1);
$product_size_id = mysqli_insert_id($con);
for ($j=0; $j<count($_POST['color']); $j++){
$quantity = $_POST['dress_quantity'][$j];
$color = $_POST['color'][$j];
$qry2="INSERT INTO product_color (product_size_id, product_color, product_quantity) VALUES ('$product_size_id', '$color', '$quantity')";
$result2=mysqli_query($con,$qry2);
if($result2)
{
echo '<script>alert("Record Added Successfully!")</script>';
echo '<script>window.location="try.php"</script>';
}
else
{
die("Error While Adding Stock! Please Try Again.");
}
}
}
}
Related
I am building a lightweight school management system, that takes in grades directly from the database, how do I update all values at the same time. Please help
<?php
$mydb->setQuery("SELECT * FROM tblbible");
loadresult();
function loadresult(){
global $mydb;
$cur = $mydb->loadResultList();
foreach ($cur as $result) {
echo '<tr>';
echo '<td> <input type="hidden" name="studentID" value="'. $result->studentID.'" /></td>';
?>
<?php
$rowz = mysql_query("SELECT * FROM tblstudent where studentID = '$result->studentID' ")or die(mysql_error());
$detailz = mysql_fetch_array($rowz);
echo '<td>'.$detailz['name'].' '.$detailz['initial'].' '.$detailz['lastname'].'</td>';
?>
<?php
echo '<td> <select name="studentID[]" class="form-control" required>
<option>Select Grade</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select></td>';
echo '<td> <select name="studentID[]" class="form-control" required>
<option>Select Grade</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select></td>';
echo '<td> <select name="studentID[]" class="form-control" required>
<option>Select Grade</option>
<option value="4">4</option>
<option value="3">3</option>
<option value="2">2</option>
<option value="1">1</option>
</select></td>';
?>
<?php
echo '</tr>';
}
?>
then the insert function below:
<?php
function doInsert(){
if (isset($_POST['save'])){
if ($_POST['value1'] == "" OR $_POST['value2'] == "" OR $_POST['value3'] == "") {
$messageStats = false;
message("All fields are required!","alert alert-success alert-dismissable");
redirect('index.php?page=5');
}else{
$studentID = $_POST['studentID'];
for($i = 0; $i<10; $i++) {
foreach( ($studentID) as $key => $value ) :
$cla = new Bible();
$value1 = $_POST['value1'];
$value2 = $_POST['value2'];
$value3 = $_POST['value3'];
$cla->sing =$value1;
$cla->verses =$value2;
$cla->prayer =$value3;
$cla->update($studentID);
redirect('index.php?page=5');
message("Report generated successfully!", "info");
endforeach;
}
}
}
}
And I would love to add all those in a one click button.
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']
);
i'm working on a php script wherein i must add certain score value at each row. I was able to display all the rows but i'm not sure on how would I able to store each of the given score in a variable and what query should I make to add all of them.
Here's my code
<?php
echo '<html>';
?>
<body>
<table border=0 cellspacing=0 cellpadding=0>
<?php
$connect = mysql_connect('localhost', 'root', '');
$db = 'labs';
$tb = 'comments';
$seldb = mysql_select_db($db, $connect);
echo '<form method="POST" action="..'.$_SERVER["PHP_SELF"].'">';
$query = mysql_query('SELECT com_id, comments FROM comments ORDER BY com_id ASC');
while($i = mysql_fetch_assoc($query)) {
echo'<tr><td>'.$i['comments'].'</td>';
echo'<td><select name="score" id="score" size="1">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="35">35</option>
<option value="40">40</option>
<option value="45">45</option>
<option value="50">50</option>
</select></td></tr>';
echo'<br>';
}
echo'<input type="submit" name="submit" value="submit">';
echo'</form>';
if(isset($_POST['submit'])) {
//not sure if all the scores will be stored in here.
$id = $_POST['id'];
$query = mysql_query('insert query here');
}
?>
</table>
</body>
</html>
any suggestions are appreciated. Thanks in advance.:D
I think you need the id of each changed row (maybe as a hidden field for each row. Then just do a loop through all received rows and UPDATE each one.
You might also want to change all of your form field names to use the array format. This way it's easier to make your PHP loop throught them.
Sample row:
echo'<tr><td>'.$i['comments'].'</td>';
echo'<td><select name="score['.$i["id"].']" id="score" size="1">
<option value="5">5</option>
<option value="5">10</option>
<option value="5">15</option>
<option value="5">20</option>
<option value="5">25</option>
<option value="5">30</option>
<option value="5">35</option>
<option value="5">40</option>
<option value="5">45</option>
<option value="5">50</option>
</select></td></tr>';
Now just loop through the $_POST["score"] array and use the appropriate ID for your update.
foreach($_POST["score"] as $id => $value{
// ESCAPE your db values!!!!!
// query stuff with $value and $id
}
Also keep in Mind
mysql is deprecated! Use mysqli
Escape anything from outside sources like $_POST before use in SQL
You just needs to make an array of your drop down box like below,
while($i = mysql_fetch_assoc($query)) {
echo'<tr><td>'.$i['comments'].'</td>';
echo'<td><select name="score[".$i['com_id']."]" id="score" size="1">
<option valyue="5">5</option>
<option valyue="5">10</option>
<option valyue="5">15</option>
<option valyue="5">20</option>
<option valyue="5">25</option>
<option valyue="5">30</option>
<option valyue="5">35</option>
<option valyue="5">40</option>
<option valyue="5">45</option>
<option valyue="5">50</option>
</select></td></tr>';
echo'<br>';
}
and you can access it for all of your comments
<option valyue="5">50</option>
should be
<option value="5">50</option>
To send the value of a comment to database you need to add a ID of the comment
you should loop something like this.
$query = mysql_query('SELECT com_id, comments FROM comments ORDER BY com_id ASC');
while($i = mysql_fetch_assoc($query)) {
echo '<form method="POST" action="..'.$_SERVER["PHP_SELF"].'">';
echo '<input type="hidden" name="id" value="'.$i['com_id'].'">';
echo'<tr><td>'.$i['comments'].'</td>';
echo'<td><select name="score" id="score" size="1">
<option value="5">5</option>
<option value="5">10</option>
<option value="5">15</option>
<option value="5">20</option>
<option value="5">25</option>
<option value="5">30</option>
<option value="5">35</option>
<option value="5">40</option>
<option value="5">45</option>
<option value="5">50</option>
</select></td></tr>';
echo'<br>';
echo'<input type="submit" name="submit" value="submit">';
echo'</form>';
}
I guess the easiest way for you is the following (a mix of the other solutions and comments):
<?php
echo '<html>';
?>
<body>
<table border=0 cellspacing=0 cellpadding=0>
<?php
$x = 0;
$connect = mysql_connect('localhost', 'root', '');
$db = 'labs';
$tb = 'comments';
$seldb = mysql_select_db($db, $connect);
echo '<form method="POST" action="..'.$_SERVER["PHP_SELF"].'">';
$query = mysql_query('SELECT com_id, comments FROM comments ORDER BY com_id ASC');
while($i = mysql_fetch_assoc($query)) {
$x++;
echo'<tr><td>'.$i['comments'].'</td>';
echo'<td><select name="score_'.$x.'" id="score" size="1">
<option value="5">5</option>
<option value="10">10</option>
<option value="15">15</option>
<option value="20">20</option>
<option value="25">25</option>
<option value="30">30</option>
<option value="35">35</option>
<option value="40">40</option>
<option value="45">45</option>
<option value="50">50</option>
</select></td></tr>';
echo'<br>';
}
echo'<input type="submit" name="submit" value="submit">';
echo'</form>';
if(isset($_POST['submit'])) {
//not sure if all the scores will be stored in here.
$id = $_POST['id'];
for($y = 0;$y <= $x; $y++)
{
//This query is no sql injection save. Please add filters for productive uses!!
$query = mysql_query('UPDATE table_name SET score = '.$_POST["score_".$y].' WHERE id='.$id);
}
?>
</table>
</body>
</html>
Code is no tested!
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
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">