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">
Related
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.");
}
}
}
}
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.
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
Am not sure how to ask this question but for most of you more experienced php programmers this is going to sound trivial... So I have successfully set up a register and login system and also an admin section where the administrator can see all the users that are currently registered. What I am wanting is for the admin to be able to edit the user's details, and also have the capability to delete/block them. Actually I have just successfully implemented a delete function.
This code here is of the page where the admin can see the users:
<?php
require('admin_sessions.php');
require("../includes/dbconnect.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Admin - iTrade Users Details</title>
<meta name="robots" content="NOFOLLOW,NOINDEX">
<link rel="stylesheet" href="../stylesheet.css" type="text/css">
<!--[if IE 7]>
<link rel="stylesheet" href="../ie7.css" type="text/css">
<script type="text/javascript">
document.createElement('nav');
document.createElement('article');
document.createElement('aside');
document.createElement('header');
document.createElement('footer');
</script>
<![endif]-->
<!--[if IE 8]>
<link rel="stylesheet" href="../ie8.css" type="text/css">
<script type="text/javascript">
document.createElement('nav');
document.createElement('article');
document.createElement('aside');
document.createElement('header');
document.createElement('footer');
</script>
<![endif]-->
<style type="text/css">
table{
border:1px solid black;
width:2508px;
}
table th{
border-bottom:1px solid black;
border-left:1px solid black;
border-top:1px solid black;
border-right:1px solid black;
}
.header_tables{
background-color:black;
color:white;
text-align:center
}
</style>
</head>
<body>
<header style="width:2570px;"><span class="header_img"><img src="../img/itradeheader.png" width="465" height="200" alt="iTrade - The Leading Online Trading Portal"></span></header>
<nav style="width:2470px;">
<ul>
<li><p>Home</p></li>
<li><p>About iTrade</p></li>
<li><p>Browse Auctions</p></li>
<li><p>F.A.Q's</p></li>
<li><p>Support</p></li>
<?php if($_SESSION['authorisation'] != 'knownuser'){
echo("<li class=\"spacer\"><p class=\"loginlogoutregister\">User Log In</p></li><li><p class=\"loginlogoutregister\">User Register</p></li>");
}
else{
echo("<li class=\"spacer\"><p class=\"loginlogoutregister\">User Logout</p></li>");
$loggedin = "<p>You are logged in.</p>";
}
if($_SESSION['authorisation'] != 'known_admin_user'){
echo("<li><p class=\"loginlogoutregister\">Admin</p></li>");
}
else{
echo("<li><p class=\"loginlogoutregister\">Admin</p></li><li><p class=\"loginlogoutregister\">Admin Logout</p></li>");
}
?>
</ul>
</nav>
<article style="width:2550px; height:100%;">
<h1>Admin - iTrade Users Details</h1>
<p>« Back to main admin page</p>
<ul>
<li>Users on iTrade</li>
<li>Admin Users on iTrade</li>
<li>Register a New Admin User</li>
</ul>
<p>Here is a table containing details about the currently registered users on iTrade:</p>
<fieldset style="width:2480px; height:100%; margin:0 auto;">
<legend style="font-size:30px; color:#000000; background-color:inherit;">A record of users on iTrade</legend>
<table>
<tr class="header_tables">
<th><u>User I.D</u></th>
<th><u>User Level</u></th>
<th><u>User-name</u></th>
<th><u>First Name</u></th>
<th><u>Last Name</u></th>
<th><u>Email</u></th>
<th><u>Password</u></th>
<th><u>Gender</u></th>
<th><u>Birthday</u></th>
<th><u>Landline Number</u></th>
<th><u>Mobile Number</u></th>
<th><u>Street Address</u></th>
<th><u>Suburb</u></th>
<th><u>City/Town</u></th>
<th><u>Province</u></th>
<th><u>Postcode</u></th>
<th><u>Closest Town</u></th>
<th><u>Confirmed?</u></th>
<th><u>Date Registered</u></th>
</tr>
<?php
$query = "SELECT * FROM user_list;";
$result = mysql_query($query, $connection) or die(mysql_error());
$users_on_itrade = " ";
while($row = mysql_fetch_array($result)){
echo("<tr>");
echo('<td>' . $row['user_id'] . '</td>');
echo('<td>' . $row['user_level'] . '</td>');
echo('<td>' . $row['user_username'] . '</td>');
echo('<td>' . $row['firstname'] . '</td>');
echo('<td>' . $row['lastname'] . '</td>');
echo('<td>' . $row['user_email'] . '</td>');
echo('<td>' . $row['user_pass'] . '</td>');
echo('<td>' . $row['gender']. '</td>');
echo('<td>' . $row['birthdate_day'] . $row['birthdate_month'] . $row['birthdate_year'] . '</td>');
echo('<td>' . $row['phoneNumber'] . '</td>');
echo('<td>' . $row['mobileNumber'] . '</td>');
echo('<td>' . $row['addressline1'] . '</td>');
echo('<td>' . $row['addressline2'] . '</td>');
echo('<td>' . $row['addressline3'] . '</td>');
echo('<td>' . $row['stateprovince'] . '</td>');
echo('<td>' . $row['postcode'] . '</td>');
echo('<td>' . $row['closest_town'] . '</td>');
echo('<td>' . $row['confirmed'] . '</td>');
echo('<td>' . $row['user_date'] . '</td>');
echo('<td>Edit</td>');
echo('<td>Delete</td>');
echo("<tr>");
}
?>
</table>
</fieldset>
</article>
<footer style="width:2550px;"><p>© Copyright 2011 iTrade LTD. Website design and development by InterKiwi Web Developers. Special thanks to the Computer Science department at the University of Otago, and the lecturers and lab administrators/demonstrators of the universities' Advanced Web Development paper.</p></footer>
</body>
</html>
This code is for the "edit" page link in "<td>Edit</td>":
<?php
require('admin_sessions.php');
require("../includes/dbconnect.php");
require('../includes/itradeuser.php');
?>
<?php
/*
This php script allows the administrator to edit a specific itrade user in the database.
*/
// creates the edit record form
// since this form is used multiple times in this file, I have made it a function that is easily reusable
function renderForm($user_id, $user_email, $user_pass, $user_pass_confirm, $user_username, $firstname, $lastname, $gender, $birthdate_day, $birthdate_month, $birthdate_year, $phoneNumber, $mobileNumber, $addressline1, $addressline2, $addressline3, $stateprovince, $postcode, $closest_town, $error)
{
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Edit Record</title>
</head>
<body>
<?php
// if there are any errors, display them
if ($error != '')
{
echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>';
}
?>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $user_id; ?>"/>
<fieldset class="userdetails">
<legend>User Credentials</legend>
<p><strong>ID:</strong> <?php echo $user_id; ?></p>
<ul>
<li><label for="user_email">Email Address:</label><input name="user_email" maxlength="50" id="user_email" size="40" type="text" value="<?php echo $user_email; ?>"><br></li>
<li><label for="user_pass">Your Password:</label><input name="user_pass" maxlength="50" id="user_pass" size="30" type="password" value="<?php echo $user_pass; ?>"><br></li>
<li><label for="user_pass_confirm">Password Again:</label><input name="user_pass_confirm" maxlength="50" id="user_pass_confirm" size="30" type="password" value="<?php echo $user_pass_confirm; ?>"><br></li>
<li><label for="user_username">Your Username:</label><input name="user_username" maxlength="50" id="user_username" size="30" type="text" value="<?php echo $user_username; ?>"></li>
</ul>
</fieldset>
<fieldset>
<legend>Contact Details</legend>
<ul>
<li><label for="firstname">First Name:</label><input name="firstname" type="text" id="firstname" size="25" maxlength="200" value="<?php echo $firstname; ?>" /><br></li>
<li><label for="lastname">Last Name:</label><input name="lastname" type="text" id="lastname" size="25" maxlength="200" value="<?php echo $lastname; ?>" /><br></li>
<li><label for="gender">Gender:</label>
<select name="gender" id="gender">
<option selected="" value=""> </option>
<option value="male">Male</option>
<option value="female">Female</option>
<option value="unspecified">Unspecified</option>
</select><br></li>
<li><label for"birthdate_day">Date of birth:</label>
<select name="birthdate_day" id="birthdate_day">
<option selected="selected" value=""></option>
<option value="1st">1</option>
<option value="2nd">2</option>
<option value="3rd">3</option>
<option value="4th">4</option>
<option value="5th">5</option>
<option value="6th">6</option>
<option value="7th">7</option>
<option value="8th">8</option>
<option value="9th">9</option>
<option value="10th">10</option>
<option value="11th">11</option>
<option value="12th">12</option>
<option value="13th">13</option>
<option value="14th">14</option>
<option value="15th">15</option>
<option value="16th">16</option>
<option value="17th">17</option>
<option value="18th">18</option>
<option value="19th">19</option>
<option value="20th">20</option>
<option value="21st">21</option>
<option value="22nd">22</option>
<option value="23rd">23</option>
<option value="24th">24</option>
<option value="25th">25</option>
<option value="26th">26</option>
<option value="27th">27</option>
<option value="28th">28</option>
<option value="29th">29</option>
<option value="30th">30</option>
<option value="31st">31</option>
</select>
<select name="birthdate_month" id="birthdate_month">
<option selected="selected" value=""></option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>
</select><br></li>
<li><label for="birthdate_year">Birth Year:</label><input name="birthdate_year" type="number" maxlength="4" id="birthdate_year" size="4" value="<?php echo $birthdate_year; ?>"><br>
</li>
<li>
<label for="phoneNumber">Home Phone:</label>
<input name="phoneNumber" type="number" maxlength="9" id="phoneNumber" size="9" value="<?php echo $phoneNumber; ?>"><br></li>
<li><label for="mobileNumber">Mobile Number:</label>
<input name="mobileNumber" type="number" maxlength="11" id="mobileNumber" size="11" value="<?php echo $mobileNumber; ?>"><span class="informational">e.g: 0276123456</span><br></li>
<li><label for="addressline1">Street Address:</label>
<input name="addressline1" maxlength="100" id="addressline1" size="40" type="text" value="<?php echo $addressline1; ?>"><br></li>
<li><label for="addressline2">Suburb:</label>
<input name="addressline2" maxlength="100" id="addressline2" size="40" type="text" value="<?php echo $addressline2; ?>"><br></li>
<li><label for="addressline3">City:</label>
<input name="addressline3" maxlength="100" id="addressline3" size="40" type="text" value="<?php echo $addressline3; ?>"><br></li>
<li><label for="stateprovince">State/Province:</label>
<select name="stateprovince" id="stateprovince">
<option selected="selected" value="<?php echo $stateprovince; ?>"></option>
<option value="northland">Northland</option>
<option value="auckland">Auckland</option>
<option value="waikato">Waikato</option>
<option value="bayofplenty">Bay of Plenty</option>
<option value="eastcoast">East Coast</option>
<option value="hawkesbay">Hawkes Bay</option>
<option value="taranaki">Taranaki</option>
<option value="kingcountry">King Country</option>
<option value="wanganui">Wanganui</option>
<option value="manawatu">Manawatu</option>
<option value="wairarapa">Wairarapa</option>
<option value="wellington">Wellington</option>
<option value="nelsonbays">Nelson Bays</option>
<option value="marlborough">Marlborough</option>
<option value="buller">Buller</option>
<option value="westland">Westland</option>
<option value="northcanterbury">North Canterbury</option>
<option value="canterbury">Canterbury</option>
<option value="midcanterbury">Mid Canterbury</option>
<option value="southcanterbury">South Canterbury</option>
<option value="northotago">North Otago</option>
<option value="otago">Otago</option>
<option value="southland">Southland</option>
<option value="chathamisl">Chatham Islands</option>
</select><br></li>
<li><label for="postcode">Post Code:</label>
<input name="postcode" type="number" maxlength="4" id="postcode" size="4" value="<?php echo $postcode; ?>"><span class="informational">Find your post code</span><br></li>
<li><label for="closest_town">Closest Town:</label>
<select name="closest_town" id="closest_town">
<option selected="selected" value=""></option>
<option value="dargaville">Northland - Dargaville</option>
<option value="kaikohe">Northland - Kaikohe</option>
<option value="kaitaia">Northland - Kaitaia</option>
<option value="kawakawa">Northland - Kawakawa</option>
<option value="kerikeri">Northland - Kerikeri</option>
<option value="maungaturoto">Northland - Maungaturoto</option>
<option value="paihia">Northland - Paihia</option>
<option value="whangarei">Northland - Whangarei</option>
<option value="0"> </option>
<option value="aucklandcity">Auckland - Auckland City</option>
<option value="franklin">Auckland - Franklin</option>
<option value="greatbarrierisland">Auckland - Great Barrier Island</option>
<option value="helensville">Auckland - Helensville</option>
<option value="hibiscuscoast">Auckland - Hibiscus Coast</option>
<option value="manukaucity">Auckland - Manukau City</option>
<option value="northshore">Auckland - North Shore</option>
<option value="papakuracity">Auckland - Papakura City</option>
<option value="waihekeisl">Auckland - Waiheke Island</option>
<option value="waitakerecity">Auckland - Waitakere City</option>
<option value="warkworth">Auckland - Warkworth</option>
<option value="wellsford">Auckland - Wellsford</option>
<option value="0"> </option>
<option value="cambridge">Waikato - Cambridge</option>
<option value="coromandel">Waikato - Coromandel</option>
<option value="hamilton">Waikato - Hamilton</option>
<option value="huntly">Waikato - Huntly</option>
<option value="matamata">Waikato - Matamata</option>
<option value="morrinsville">Waikato - Morrinsville</option>
<option value="otorohanga">Waikato - Otorohanga</option>
<option value="paeroa">Waikato - Paeroa</option>
<option value="raglan">Waikato - Raglan</option>
<option value="taumarunui">Waikato - Taumarunui</option>
<option value="teawamutu">Waikato - Te Awamutu</option>
<option value="tekuiti">Waikato - Te Kuiti</option>
<option value="thames">Waikato - Thames</option>
<option value="tokoroa_putaruru">Waikato - Tokoroa/Putaruru</option>
<option value="waihi">Waikato - Waihi</option>
<option value="waihi_beach">Waikato - Waihi Beach</option>
<option value="whangamata">Waikato - Whangamata</option>
<option value="0"> </option>
<option value="katikati">Bay of Plenty - Katikati</option>
<option value="mt_maunganui">Bay of Plenty - Mt. Maunganui</option>
<option value="opotiki">Bay of Plenty - Opotiki</option>
<option value="rotorua">Bay of Plenty - Rotorua</option>
<option value="taupo">Bay of Plenty - Taupo</option>
<option value="tauranga">Bay of Plenty - Tauranga</option>
<option value="te_puke">Bay of Plenty - Te Puke</option>
<option value="turangi">Bay of Plenty - Turangi</option>
<option value="whakatane">Bay of Plenty - Whakatane</option>
<option value="0"> </option>
<option value="gisborne">Gisborne - Gisborne</option>
<option value="ruatoria">Gisborne - Ruatoria</option>
<option value="0"> </option>
<option value="dannevirke">Hawkes Bay - Dannevirke</option>
<option value="hastings">Hawkes Bay - Hastings</option>
<option value="napier">Hawkes Bay - Napier</option>
<option value="waipukurau">Hawkes Bay - Waipukurau</option>
<option value="wairoa">Hawkes Bay - Wairoa</option>
<option value="0"> </option>
<option value="hawera">Taranaki - Hawera</option>
<option value="mokau">Taranaki - Mokau</option>
<option value="new_plymouth">Taranaki - New Plymouth</option>
<option value="opunake">Taranaki - Opunake</option>
<option value="stratford">Taranaki - Stratford</option>
<option value="0"> </option>
<option value="ohakune">Wanganui - Ohakune</option>
<option value="taihape">Wanganui - Taihape</option>
<option value="waiouru">Wanganui - Waiouru</option>
<option value="wanganui">Wanganui - Wanganui</option>
<option value="0"> </option>
<option value="bulls">Manawatu - Bulls</option>
<option value="fielding">Manawatu - Feilding</option>
<option value="levin">Manawatu - Levin</option>
<option value="manawatu">Manawatu - Manawatu</option>
<option value="marton">Manawatu - Marton</option>
<option value="palmerston_north">Manawatu - Palmerston North</option>
<option value="0"> </option>
<option value="carterton">Wairarapa - Carterton</option>
<option value="featherston">Wairarapa - Featherston</option>
<option value="greytown">Wairarapa - Greytown</option>
<option value="martinborough">Wairarapa - Martinborough</option>
<option value="masterton">Wairarapa - Masterton</option>
<option value="paihiatua">Wairarapa - Pahiatua</option>
<option value="woodville">Wairarapa - Woodville</option>
<option value="0"> </option>
<option value="kapiti">Wellington - Kapiti</option>
<option value="lower_hutt">Wellington - Lower Hutt City</option>
<option value="porirua">Wellington - Porirua</option>
<option value="upper_hutt">Wellington - Upper Hutt City</option>
<option value="wellington">Wellington - Wellington City</option>
<option value="0"> </option>
<option value="golden_bay">Nelson Bays - Golden Bay</option>
<option value="motueka">Nelson Bays - Motueka</option>
<option value="murchison">Nelson Bays - Murchison</option>
<option value="nelson">Nelson Bays - Nelson</option>
<option value="picton">Nelson Bays - Picton</option>
<option value="0"> </option>
<option value="blenheim">Marlborough - Blenheim</option>
<option value="marlborough_sounds">Marlborough - Marlborough Sounds</option>
<option value="0"> </option>
<option value="greymouth">West Coast - Greymouth</option>
<option value="hokitika">West Coast - Hokitika</option>
<option value="westport">West Coast - Westport</option>
<option value="0"> </option>
<option value="akaroa">Canterbury - Akaroa</option>
<option value="amberley">Canterbury - Amberley</option>
<option value="ashburton">Canterbury - Ashburton</option>
<option value="cheviot">Canterbury - Cheviot</option>
<option value="christchurch">Canterbury - Christchurch City</option>
<option value="darfield">Canterbury - Darfield</option>
<option value="fairlie">Canterbury - Fairlie</option>
<option value="geraldine">Canterbury - Geraldine</option>
<option value="hamnersprings">Canterbury - Hanmer Springs</option>
<option value="kaiapoi">Canterbury - Kaiapoi</option>
<option value="kaikoura">Canterbury - Kaikoura</option>
<option value="mtcook">Canterbury - Mt Cook</option>
<option value="rangiora">Canterbury - Rangiora</option>
<option value="0"> </option>
<option value="timaru_oamaru_kurow">Timaru - Oamaru - Kurow</option>
<option value="timaru_oamaru_oamaru">Timaru - Oamaru - Oamaru</option>
<option value="timaru_oamaru_timaru">Timaru - Oamaru - Timaru</option>
<option value="timaru_oamaru_twizel">Timaru - Oamaru - Twizel</option>
<option value="timaru_oamaru_waimate">Timaru - Oamaru - Waimate</option>
<option value="0"> </option>
<option value="alexandra">Otago - Alexandra</option>
<option value="balclutha">Otago - Balclutha</option>
<option value="cromwell">Otago - Cromwell</option>
<option value="dunedin">Otago - Dunedin</option>
<option value="lawrence">Otago - Lawrence</option>
<option value="milton">Otago - Milton</option>
<option value="palmerston">Otago - Palmerston</option>
<option value="queenstown">Otago - Queenstown</option>
<option value="ranfurly">Otago - Ranfurly</option>
<option value="roxburgh">Otago - Roxburgh</option>
<option value="wanaka">Otago - Wanaka</option>
<option value="0"> </option>
<option value="bluff">Southland - Bluff</option>
<option value="edendale">Southland - Edendale</option>
<option value="gore">Southland - Gore</option>
<option value="invercargill">Southland - Invercargill</option>
<option value="lumsden">Southland - Lumsden</option>
<option value="otautau">Southland - Otautau</option>
<option value="riverton">Southland - Riverton</option>
<option value="stewart_island">Southland - Stewart Island</option>
<option value="te_anau">Southland - Te Anau</option>
<option value="tokanui">Southland - Tokanui</option>
<option value="winton">Southland - Winton</option>
<option value="0"> </option>
<option value="chathamisl">Chatham Islands</option>
</select><br></li>
</ul>
</fieldset>
<input type="submit" name="submit" value="Submit">
</div>
</form>
</body>
</html>
<?php
}
// check if the form has been submitted. If it has, process the form and save it to the database
if (isset($_POST['submit'])){
if (is_numeric($_POST['user_id'])){
// get form data, making sure it is valid
$user_id = $_POST['user_id'];
$user_email = mysql_real_escape_string($_POST['user_email']);
$user_pass = mysql_real_escape_string($_POST['user_pass']);
$user_pass_confirm = mysql_real_escape_string($_POST['user_pass_confirm']);
$user_username = mysql_real_escape_string($_POST['user_username']);
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$gender = mysql_real_escape_string($_POST['gender']);//optional field
$birthdate_day = mysql_real_escape_string($_POST['birthdate_day']);
$birthdate_month = mysql_real_escape_string($_POST['birthdate_month']);
$birthdate_year = mysql_real_escape_string($_POST['birthdate_year']);
$phoneNumber = mysql_real_escape_string($_POST['phoneNumber']);
$mobileNumber = mysql_real_escape_string($_POST['mobileNumber']);
$addressline1 = mysql_real_escape_string($_POST['addressline1']);
$addressline2 = mysql_real_escape_string($_POST['addressline2']); // optional field
$addressline3 = mysql_real_escape_string($_POST['addressline3']);
$stateprovince = mysql_real_escape_string($_POST['stateprovince']);
$postcode = mysql_real_escape_string($_POST['postcode']); // optional field
$closest_town = mysql_real_escape_string($_POST['closest_town']); //optional field
$date = time();
// check that firstname/lastname fields are both filled in
if ($firstname == '' || $lastname == '' || $user_email =='' || $user_pass == '' || $user_pass_confirm == '' || $user_username == '' || $firstname =='' || $lastname == '' || $gender == '' || $birthdate_day == '' || $birthdate_month == '' || $birthdate_year == '' || $phoneNumber == '' || $mobileNumber == '' || $addressline1 == '' || $addressline2 == '' || $addressline3 == '' || $stateprovince == '' || $postcode == '' || $closest_town == ''){
// generate error message
$error = 'ERROR: Please fill in all required fields!';
//error, display form
renderForm($user_id, $user_email, $user_pass, $user_pass_confirm, $user_username, $firstname, $lastname, $gender, $birthdate_day, $birthdate_month, $birthdate_year, $phoneNumber, $mobileNumber, $addressline1, $addressline2, $addressline3, $stateprovince, $postcode, $closest_town, $error);
}
else{
// save the data to the database
mysql_query("UPDATE user_list SET user_email='$user_email', user_pass=sha1('$user_pass.$salt'), user_pass_confirm=sha1('$user_pass_confirm.$salt'), user_username='$user_username', firstname='$firstname', lastname='$lastname', gender='$gender', birthdate_day='$birthdate_day, birthdate_month='$birthdate_month', birthdate_year='$birthdate_year', phoneNumber='$phoneNumber', mobileNumber='$mobileNumber', addressline1='$addressline1', addressline2='$addressline2', addressline3='$addressline3', stateprovince='$stateprovince', postcode='$postcode', closest_town='$closest_town' WHERE user_id='$user_id'")
or die(mysql_error());
// once saved, redirect back to the view page
header("Location: itradeusers.php");
}
}
else
{
// if the 'id' isn't valid, display an error
echo 'Error! ID not valid.';
}
}
else
// if the form hasn't been submitted, get the data from the db and display the form
{
// get the 'id' value from the URL (if it exists), making sure that it is valid (checing that it is numeric/larger than 0)
if (isset($_GET['user_id']) && is_numeric($_GET['user_id']) && $_GET['user_id'] > 0)
{
// query db
$user_id = $_GET['user_id'];
$result = mysql_query("SELECT * FROM user_list WHERE user_id=$user_id")
or die(mysql_error());
$row = mysql_fetch_array($result);
// check that the 'id' matches up with a row in the databse
if($row)
{
// get data from db
$user_id = $row['user_id'];
$user_email = $row['user_email'];
$user_pass = $row['user_pass'];
$user_pass_confirm = $row['user_pass_confirm'];
$user_username = $row['user_username'];
$firstname = $row['firstname'];
$lastname = $row['lastname'];
$gender = $row['gender'];
$birthdate_day = $row['birthdate_day'];
$birthdate_month = $row['birthdate_month'];
$birthdate_year = $row['birthdate_year'];
$phoneNumber = $row['phoneNumber'];
$mobileNumber = $row['mobileNumber'];
$addressline1 = $row['addressline1'];
$addressline2 = $row['addressline2'];
$addressline3 = $row['addressline3'];
$stateprovince = $row['stateprovince'];
$postcode = $row['postcode'];
$closest_town = $row['closest_town'];
// show form
renderForm($user_id, $user_email, $user_pass, $user_pass_confirm, $user_username, $firstname, $lastname, $gender, $birthdate_day, $birthdate_month, $birthdate_year, $phoneNumber, $mobileNumber, $addressline1, $addressline2, $addressline3, $stateprovince, $postcode, $closest_town, $error);
}else
// if no match, display result
{
echo "No results!";
}
}
else
// if the 'id' in the URL isn't valid, or if there is no 'id' value, display an error
{
echo 'Error! the \'id\' is not valid.';
}
}
?>
If someone could tell me what I have done wrong, or even explain to me a better way of doing something like this, please let me know... Thanks in advance!
First of all, it looks like you're storing passwords in plain text. That is a big no no!
For updating user info have a look at the UPDATE command for mysql: http://dev.mysql.com/doc/refman/5.0/en/update.html
For the delete/block issue, you could add another column that stores the user status (deleted, blocked, active, etc). You could then check the status of this column when the user logs in or visits a page.