PHP - Using Php To Upload A File And Import That Data Into A Mysql Table
I think this is the right section to post this is in.....
Anyway.....I'm building a web site that requires i have functionality to upload a tab delimited file (or some file format that is easiest) via php and insert the data into MYSQL. I've searched for many third party scripts but none seem to work. So I've decided to move to the community to see if someone can give me insight on how i might accomplish this script. I have some third party scripts but I'm not sure if they'd be of any use. Thank you kindly Similar TutorialsI am trying to import csv file to wordpress using database.the files are uploaded in database but its not coming in wordpress . The code is as below: <?php if(isset($_POST['submit'])) { $fname=$_FILES["file"]["name"]; $datetime=$_FILES["file"][""]; $chk_ext = explode(".",$fname); if(strtolower(($chk_ext[1]) == "csv")) { $filename = $_FILES['file']['tmp_name']; $handle = fopen($filename, "r"); while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) { $fname=addslashes($data[0]); $datetime=addslashes($data[1]); $products=addslashes($data[2]); $preset=addslashes($data[3]); $format=addslashes($data[4]); $sql = "INSERT into ".$wpdb->prefix ."facebook(filename,datetime,products,preset,format) values('$fname','$datetime','$products','$preset','$format')"; mysql_query($sql) or die(mysql_error()); } fclose($handle); echo "Successfully Imported"; } else { echo "Invalid File"; } } ?> <form enctype="multipart/form-data" action="" method="post" name="uploadDetails"> <table cellpadding="4" cellspacing="0" border="1"> <tr> <td><label for="upload_a_file">Upload File:</label></td> <td><input type="file" name="file" id="upload_a_file" /></td> </tr> <tr> </tr> </table> <input type="hidden" name="fd_upload" value="1" /> <input type="submit" value="Submit" class="allbutton" name="submit" /> </form> Hope you will help me Hello, this script originally works by reading a physical copy of 'bans.txt' located in the same directory. How could I get it to read the remote bans.txt located here and parse info from it like the on-site copy? the remote file: http://108.163.211.219/bans.txt Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><title>Data Tables and Cascading Style Sheets Gallery</title> <style>/* Tema: Soft Table - A Simple table style with the use of the soft brown color Author: Newton de G?es Horta Site: -- Country Origin: Brazil */ table { font-size:0.9em; font-family: Arial, Helvetica, verdana sans-serif; background-color:#fff; border-collapse: collapse; width: 100%; } caption { font-size: 25px; color: #1ba6b2; font-weight: bold; text-align: left; background: url(http://www.nghorta.com/csstg/header_bg.jpg) no-repeat top left; padding: 10px; margin-bottom: 2px; } thead th { border-right: 1px solid #fff; color:#fff; text-align:center; padding:2px; text-transform:uppercase; height:25px; background-color: #a3c159; font-weight: normal; } tfoot { color:#1ba6b2; padding:2px; text-transform:uppercase; font-size:1.2em; font-weigth: bold; margin-top:6px; border-top: 6px solid #e9f7f6; } tbody tr { background-color:#fff; border-bottom: 1px solid #f0f0f0; } tbody td { color:#414141; padding:5px; text-align:left; } tbody th { text-align:left; padding:2px; } tbody td a, tbody th a { color:#6C8C37; text-decoration:none; font-weight:normal; display:block; background: transparent url(http://www.nghorta.com/csstg/links_yellow.gif) no-repeat 0% 50%; padding-left:15px; } tbody td a:hover, tbody th a:hover { color:#009193; text-decoration:none; } /* tr:nth-child(even) { background-color: grey; } */ </style></head> <body> <table summary="Submitted table designs"> <thead><tr> <th style="font-size:12px" scope="col"><center>Nickname</center></th> <th style="font-size:12px" scope="col"><center>Admin</center></th> <th style="font-size:12px" scope="col"><center>Banned</center></th> <th style="font-size:12px" scope="col"><center>Reason</center></th> <th style="font-size:12px" scope="col"><center>SteamID</center></th> <th style="font-size:12px" scope="col"><center>Length</center></th> <th style="font-size:12px" scope="col"><center>Status</center></th> </tr></thead> <tbody> <!-- <tr><th scope="row" id="r100"><a href="100.php">rows table template</a></th> <td><a href="http://www.adobati.it">Omar '0m4r' Adobati</a></td><td>Italy</td> <td>Simple, clean and a quite classic table template :)</td> <td><a href="http://www.adobati.it/labs/CSSTable/0m4r.table.css" title="Download the rows table template CSS file">Download</a></td> <td>test</td> <td>test2</td> </tr> --> <?php // Credits to justin as he was able to understand my messy PHP code and do this much better code for me. function buildBanList($arr) { $filename = "bans.txt"; $bans = array(); $tmp_array = array(); // Build Ban Array if (file_exists($filename)) { foreach( $arr as $line ) { if( substr(trim($line), 0, 7) == '"STEAM_' ) { $tmp_array["user_steamid"] = str_replace('"', '', trim($line)); } if( substr(trim($line), 0, 6) == '"time"' ) { $tmp = explode(' ', trim($line)); $tmp_array["user_bantime"] = str_replace('"', '', $tmp[1]); } if( substr(trim($line), 0, 15) == '"modified_time"' ) { $tmp = explode(' ', trim($line)); $tmp_array["user_modified"] = str_replace('"', '', $tmp[1]); } if( substr(trim($line), 0, 7) == '"unban"' ) { $tmp = explode(' ', trim($line)); $tmp_array["user_unban"] = str_replace('"', '', $tmp[1]); } if( substr(trim($line), 0, 7) == '"admin"' ) { $tmp = explode('" "', trim($line)); $tmp2 = explode('(', $tmp[1]); $tmp_array["admin_name"] = str_replace('"', '', $tmp2[0]); } if( substr(trim($line), 0, 6) == '"name"' ) { $tmp = explode('" "', trim($line)); $tmp_array["user_name"] = str_replace('"', '', $tmp[1]); } if( substr(trim($line), 0, 8) == '"reason"' ) { $tmp = explode('" "', trim($line)); $tmp_array["user_reason"] = str_replace('"', '', $tmp[1]); } // Save ban record to main array once detected end. if( substr(trim($line), 0, 1) == '}' ) { // If console ban then set required fields. if( $tmp_array["admin_name"] == "") $tmp_array["admin_name"] = "Console"; array_push($bans, $tmp_array); $tmp_array = array(); } } } //Sort Array by Ban Date $tmp = array(); foreach($bans as &$ma) $tmp[] = &$ma["user_bantime"]; array_multisort($tmp, SORT_DESC, $bans); return $bans; } //Begin Presentation $file = file("./bans.txt"); date_default_timezone_set("Europe/London"); $bans = buildBanList($file); foreach ($bans as $ban) { echo '<tr> '; // Output if ($ban["user_name"] != '') echo '<td style="text-align:center; font-size: 12px">'.$ban["user_name"].'</td><td style="text-align:center; font-size: 12px" class="admin">'; else echo '<td style="text-align:center; font-size: 12px"><span style="color:#FF0000">N/A</span></td><td style="text-align:center; font-size: 12px" class="admin">'; echo $ban["admin_name"].'</td><td style="text-align:center; font-size: 12px">'.date('H:i - d/m/y',$ban["user_bantime"]).'</td>'; /* Unban date. if ($ban["user_unban"] != "0") { echo date('H:i - d/m/y',$ban["user_unban"]); } else { echo "Never"; }*/ echo '<td style="text-align:left; font-size: 11px">'.$ban["user_reason"].'</td>'; // Status $today = strtotime("now"); echo '</td><td style="text-align:center; font-size: 12px">'.$ban["user_steamid"].' </td>'; // Ban Length $date1 = date('y-m-d H:i:s',$ban["user_bantime"]); $date2 = date('y-m-d H:i:s',$ban["user_unban"]); $to_time=strtotime($date1); $from_time=strtotime($date2); $ban_length = round(abs($to_time - $from_time) / 60,0); if ($ban["user_unban"] != "0") { // Days if ($ban_length >= 1440) { $ban_length = round(abs($to_time - $from_time) / 24 / 60 / 60,0); // Years couldn't be arsed to think of another way to do it. if ( $ban_length >= 365 ) { $ban_length = round(abs($to_time - $from_time) / 360 / 24 / 60 / 60,0); if ($bans_length > 1) echo "<td style=\"text-align:center; font-size: 12px\">".$ban_length." Years </td>"; else echo "<td style=\"text-align:center; font-size: 12px\">".$ban_length." Year </td>"; } else echo "<td style=\"text-align:center; font-size: 12px\">".$ban_length." Days </td>"; } // Hours else if ($bans_length >= 60) { $ban_length = round(abs($to_time - $from_time) / 60 / 60,0); if ($bans_length > 1) echo "<td style=\"text-align:center; font-size: 12px\">".$ban_length." Hours </td>"; else echo "<td style=\"text-align:center; font-size: 12px\">".$ban_length." Hour </td>"; } else echo "<td style=\"text-align:center; font-size: 12px\">".$ban_length." Minutes </td>"; } else { echo "<td style=\"text-align:center; font-size: 12px\">Permanent</td>"; } if ($ban["user_unban"] == "0") echo '<td style="text-align:center; font-size: 12px"><span style="color:#FF0000">Banned</span></td>'; else if ( $today > $ban["user_unban"] ) echo '<td style="text-align:center; font-size: 12px"><span style="color:#008000">Expired</span></td>'; else echo '<td style="text-align:center; font-size: 12px"><span style="color:#FF0000">Banned</span></td>'; echo '</tr>'; } ?></table> <center><p>Web-based ULX bans by Russy.</p></center> </div> </body> </html> I've tried experimenting w/ stuff like Code: [Select] $filename = "http://108.163.211.219/bans.txt"; $contents = file_get_contents($filename); but it doesn't seem to want to work. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Import a CSV File with PHP & MySQL</title> </head> <body> <form action="" method="post" enctype="multipart/form-data" name="csv" id="csv"> Choose your file: <br /> <input name="csv" type="file" id="csv" /> <input type="submit" name="Submit" value="Submit" /> </form> </body> Hi all, I'm developing a website and i need to upload a xml spreadsheet and see data at screen just to verify if it is correct. So far so good. But after the user see the data in the screen, he should be able to import that file to mssql. The problem is, in this second page where i show the data that the XML spreadsheet contains, i don't have the file location to submit the file again. How can i resolve this problem? Any ideas? Thanks in advance. Regards This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=330652.0 Hi! I hope somebody can help me what im do wrong. i have checked that the data from the file is in $source_file but nothing imports to the database Code: [Select] <?php include('config.php'); include('opendb.php'); if(isset($_POST['upload'])) { $source_file = @$_POST['userfile']; //$source_file = fopen('http://localhost/test/upload/test.csv', 'r'); $target_table = 'foretag'; function csv_file_to_mysql_table($source_file, $target_table, $max_line_length=10000) { if (($handle = fopen("$source_file", "r")) !== FALSE) { $columns = fgetcsv($handle, $max_line_length, ","); foreach ($columns as $column) { $column = str_replace(".","",$column); } $insert_query_prefix = "INSERT INTO $target_table (".join(",",$columns).")\nVALUES"; while (($data = fgetcsv($handle, $max_line_length, ";")) !== FALSE) { while (count($data)<count($columns)) array_push($data, NULL); $query = "$insert_query_prefix (".join(",",quote_all_array($data)).");"; mysql_query($query); } fclose($handle); } } function quote_all_array($values) { foreach ($values as $key=>$value) if (is_array($value)) $values[$key] = quote_all_array($value); else $values[$key] = quote_all($value); return $values; } function quote_all($value) { if (is_null($value)) return "NULL"; $value = "'" . mysql_real_escape_string($value) . "'"; return $value; } } include('closedb.php'); echo "<br>done<br>"; ?> I need some help getting started in writing the php code that would import a text file of name/value pairs and then create an html table with those values. The datafile looks something like this: [number]-[attribute]=[value]; 1-Host=server1.abc.dev.jkl;2-Date=Wed Aug 12 2010;3-Set=abc.123.cde;4-Time=01:00:03;5-Length=00:36:09;6-Size=41.54 GB;7-Status=Succeeded; 1-Host=server2.abc.dev.qrs;2-Date=Wed Aug 12 2010;3-Set=gls202.kul_lvm;5-Length=06:20:33;7-Status=Succeeded; 1-Host=server9.mra.dev.xyz;2-Date=Wed Aug 11 2010;3-Set=gls101.aie_lvm;4-Time=01:00:02; Let's say I have an html table: Code: [Select] <table id="stats"> tr> <th>Host</th> <th>Date</th> <th>Set</th> <th>Time</th> <th>Length</th> <th>Size</th> <th>Status</th> </tr> <tr> <td>server1.abc.dev.jkl</td> <td>Wed Aug 12 2010</td> <td>abc.123.cde</td> <td>01:00:03</td> <td>00:36:09</td> <td>41.54 GB</td> <td>Succeeded</td> </tr> </table> I've looked around all day at various samples. I've seen the fgetcsv function. I'm not sure what would be the best approach to load this into data into a table. Using a regex, then load into array or hash and then print this out? I'm assuming i would have to create print statements to produce the html tags. Also, with the sample records I provided. There will be instances where not all the attributes (1-7) have values. So, i'm envisioning empty cells for that record which is fine. I can also change the way the datafile is generated and remove the [number], so its just [attribute]=[value] if that makes it easier. Is there a good mapping technique for this? Thank you for your help. Hey guys i have a problem, I have a form to upload 2 image files however sometimes i want to only upload the one file, but if i only upload one image, it tells me that it can't upload because there is no name for the second image. I tried fixing it with if (isset($fieldname2)) however i just realised that $feildname2 is always set so im not quite sure how to fix? Code: [Select] ($action == "add"){ $add = $_POST['add']; $reference = $_POST['reference']; $category = $_POST['category']; $sub_cat = $_POST['sub_cat']; $fieldname = 'file'; $fieldname2 = 'file2'; error_reporting(E_ALL); ini_set('display_errors',1); is_uploaded_file($_FILES[$fieldname]['tmp_name']); getimagesize($_FILES[$fieldname]['tmp_name']); if (isset($fieldname2)) { is_uploaded_file($_FILES[$fieldname2]['tmp_name']); getimagesize($_FILES[$fieldname2]['tmp_name']); } $now = time(); while(file_exists($uploadFilename = $uploadsDirectory.$_FILES[$fieldname]['name'])) { $now++; } if (isset($fieldname2)) { while(file_exists($uploadFilename2 = $uploadsDirectory.$_FILES[$fieldname2]['name'])) { $now++; } } move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename); if (isset($fieldname2)) { move_uploaded_file($_FILES[$fieldname2]['tmp_name'], $uploadFilename2); } $sqlname = $_FILES[$fieldname]['name']; if (isset($fieldname2)) { $sqlname2 = $_FILES[$fieldname2]['name']; } $id = mysql_insert_id(); $query = "INSERT INTO cakes (id, reference, category, sub_cat, image, image2) VALUES ('$id', '$reference', '$category', '$sub_cat','$sqlname','$sqlname2')"; $sql = mysql_query($query) or die (mysql_error()); } echo("<form name='add' method='post' enctype='multipart/form-data' action='?action=add'>"); echo("<input type='hidden' name='MAX_FILE_SIZE' value='3000000"); echo("<input type='hidden' name='?action=add'>"); echo("<table class=main cellspacing=0 cellpadding=2 width=60%>"); echo("<tr><td>Reference: </td><td align='right'><input type='text' size=50 name='reference' value='$reference'></td></tr>"); echo("<tr><td>Category: </td><td align='center'><select name='category'><option>Occasional</option><option>Special</option><option>Figures</option><option>Novelty</option><option>Wedding</option></SELECT></td></tr>"); echo("<tr><td>Sub Category: </td><td align='center'><select name='sub_cat'><option></option><option>Birthday</option><option>Anniversary</option><option>Christmas</option><option>Christening</option><option>Valentine</option><option>Mothers Day</option><option>Fathers Day</option><option>Easter</option></select></td></tr>"); echo("<tr><td>Cake Image: </td><td align='center'><input id='file' type='file' name='file'></td></tr>"); echo("<tr><td>Cake Image 2: </td><td align='center'><input id='file2' type='file' name='file2'></td></tr>"); echo("Before uploading an image please resize the image to 290px x 218px"); echo("<tr><td></td><td><div align='right'><input type='Submit'></div></td></tr>"); echo("</table>"); so what i have going on is that i need help writing a basic script to upload original and copy with resize for thumbnail. then also need to rename both image files with content in the form. My server supports GD Library and that imagemagik or whatever it is lol. upload dirs orig: ../media/photos/ thumb: ../media/photos/thumb/ mySQL DB: name: m_photos fields: id(INT) m_cat(varchar) m_sub_cat(varchar) pic(varchar) description(varchar) p_group(varchar) I have the form written up for how it should look like: Code: [Select] <form action="upload.php" method="post" enctype="multipart/form-data"> Upload an image for processing<br /> <input type="file" name="Image"><br /> <select name="sub_group"> <option value="Photo Shoot">Photo Shoot</option> <option value="Live Performances">Live Performances</option> <option value="Randoms">Randoms</option> <option value="Fan Photos">Fan Photos</option> </select><br /> Location: <input type="text" name="p_group" /><br /> Date of Pic: <input type="text" name="date" /><br /> Description: <input type="text" name="description" /><br /> <input type="submit" value="Upload"> </form> so what needs to happen is for the file upload name. it needs to grab a count from "p_group" database to give it a starting number in a "00" pattern and then the date of pic needs to go in there next then the p_group name. so when the files gets uploaded it would look something like this after upload. "03 - Oct 21, 2011 - The Mex.jpg" NOTE: all pics must be converted to ".jpg" extension. both the orig and thumb will use that same file name cuz they just go into different dirs re-sizing for the thumbnail should be done by aspect ratio and needs to either be 300px width or 400px height. so if anyone would like to help me out please do. im not the greatest at writing in php yet hi- i'm trying to browse for a CSV file and then upload it to my mysql database. i found the code below and not working. i don't get any errors. the connection to the database is ok bcz i get the existing results but not the ones from the CSV file added to the db.. any ideas? Code: [Select] <?php ob_start(); require_once('../../connections/congif.php'); mysql_select_db($dbname, $db); $sql_get_project="SELECT * FROM gifts_tbl ORDER BY autoID DESC LIMIT 25"; $get_project = mysql_query($sql_get_project, $db) or die(mysql_error()); $row_get_project = mysql_fetch_assoc($get_project); //database connect info here //check for file upload if(isset($_FILES['csv_file']) && is_uploaded_file($_FILES['csv_file']['tmp_name'])){ //upload directory $upload_dir = "csv_dir/"; //create file name $file_path = $upload_dir . $_FILES['csv_file']['name']; //move uploaded file to upload dir if (!move_uploaded_file($_FILES['csv_file']['tmp_name'], $file_path)) { //error moving upload file echo "Error moving file upload"; } //open the csv file for reading $handle = fopen($file_path, 'r'); //turn off autocommit and delete the product table mysql_query("BEGIN"); while (($data = fgetcsv($handle, 1000, ',')) !== FALSE) { //Access field data in $data array ex. $name = $data[0]; //Use data to insert into db $sql = sprintf("INSERT INTO gifts_tbl (player_id) VALUES ('%s)", mysql_real_escape_string($name) ); mysql_query($sql) or (mysql_query("ROLLBACK") and die(mysql_error() . " - $sql")); } unlink($file_path); } ob_flush(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Gifts</title> </head> <body> <h1>Testing for CSV upload</h1> <form action="" method="post"> <input type="file" name="csv_file"> <input type="submit" name="csv_submit" value="Upload CSV File"> </form> <h2>Results</h2> <?php do { ?> <ul> <li><?php echo $row_get_project['player_id']; ?></li> </ul> <?php } while ($row_get_project = mysql_fetch_assoc($get_project)); ?> </body> </html> Hello to all, I have problem figuring out how to properly display data fetched from MySQL database in a HTML table. In the below example I am using two while loops, where the second one is nested inside first one, that check two different expressions fetching data from tables found in a MySQL database. The second expression compares the two tables IDs and after their match it displays the email of the account holder in each column in the HTML table. The main problem is that the 'email' row is displayed properly while its while expression is not nested and alone(meaning the other data is omitted or commented out), but either nested or neighbored to the first while loop, it is displayed horizontally and the other data ('validity', 'valid_from', 'valid_to') is not displayed.'
Can someone help me on this, I guess the problem lies in the while loop? <thead> <tr> <th data-column-id="id" data-type="numeric">ID</th> <th data-column-id="email">Subscriber's Email</th> <th data-column-id="validity">Validity</th> <th data-column-id="valid_from">Valid From</th> <th data-column-id="valid_to">Valid To</th> </tr> </thead> Here is part of the PHP code:
<?php while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { echo ' <tr> <td>'.$row["id"].'</td> '; while ($row1 = $stmt1->fetch(PDO::FETCH_ASSOC)) { echo ' <td>'.$row1["email"].'</td> '; } if($row["validity"] == 1) { echo '<td>'.$row["validity"].' month</td>'; }else{ echo '<td>'.$row["validity"].' months</td>'; } echo ' <td>'.$row["valid_from"].'</td> <td>'.$row["valid_to"].'</td> </tr>'; } ?>
Thank you. I receive files/images and loop through an array as follows:
$files=rearrfiles( $_FILES['image']); foreach($files as $key=>$item) { if(is_array($item) && !empty($item['name']) && !empty($item['tmp_name'])){ //$_POST['imageFile']=$item['name']; //echo $item['name']; if($error!=true && !uploadImageB(array('image'=>'image'), DB_EXTENTION."mod_projects_images", $naming, $search = $editId, $dir, 'photo')) { $error=true; $action='Edit'; $message.='<br>Images were unable to be uploaded.'; } } }The function uploadImageB() is as follows: function uploadImageB($info, $table, $naming, $search, $path, $add='uploaded', $maxw=1280, $maxh=1280, $dynamic=true, $id='Id', $thumbMaxWidth = 120) { global $connection; if(!$_POST){ global $HTTP_POST_VARS; @$_POST=$HTTP_POST_VARS;} if(!$_FILES){ global $HTTP_POST_FILES; @$_FILES=$HTTP_POST_FILES;} if(is_array($info) && !empty($info) && $table!='' && !empty($path)) { $error=false; $d=$naming; foreach($info as $key=>$val) { $names[$val]=$dynamic==true?$add.'_'.$result[$id].'_'.$d.'_.'.strtolower(mygetext($_FILES[$val]['name'])):$add.strtolower(mygetext($_FILES[$val]['name'])); if(is_array(@$_FILES[$val]) && !empty($_FILES[$val]['name']) && !empty($names[$val])) { if(!singMove($path, $names[$val], $_FILES[$val], array(), array('gif', 'jpeg', 'jpg', 'png', 'bmp', 'svg'))) { $error=true; break; } else{ $valid[$val]=$names[$val]; resizeImage($path.$names[$val], $maxw, $maxh); make_thumb($path.$names[$val],$names[$val], $path, $thumbMaxWidth); } } } if($error==true) return false; elseif(!empty($valid)) { $connection->info=$info; $connection->input=$valid; $connection->id=array('field'=>$id, 'val'=>addslashes($result[$id])); $connection->makenew($table); $connection->return_db($connection->query); } } return true; }I get the error: Images were unable to be uploaded. Any help? what's wrong with this ? i can't upload files that upload during insert/submit form was gone , only files upload during the update remain , is the way query for update multiple files is wrong ? $targetDir1= "folder/pda-semakan/ic/"; if(isset($_FILES['ic'])){ $fileName1 = $_FILES['ic']['name']; $targetFilePath1 = $targetDir1 . $fileName1; //$main_tmp2 = $_FILES['ic']['tmp_name']; $move2 =move_uploaded_file($_FILES["ic"]["tmp_name"], $targetFilePath1); } $targetDir2= "folder/pda-semakan/sijil_lahir/"; if(isset($_FILES['sijilkelahiran'])){ $fileName2 = $_FILES['sijilkelahiran']['name']; $targetFilePath2 = $targetDir2 . $fileName2; $move3 =move_uploaded_file($_FILES["sijilkelahiran"]["tmp_name"], $targetFilePath2); } $targetDir3= "folder/pda-semakan/sijil_spm/"; if(isset($_FILES['sijilspm'])){ $fileName3 = $_FILES['sijilspm']['name']; $targetFilePath3 = $targetDir3 . $fileName3; $move4 =move_uploaded_file($_FILES["sijilspm"]["tmp_name"], $targetFilePath3); } $query1=("UPDATE semakan_dokumen set student_id='$noMatrik', email= '$stdEmail', surat_tawaran='$fileName', ic='$fileName1',sijil_lahir='$fileName2',sijil_spm= '$fileName3' where email= '$stdEmail'");
hello, I need xml file as playlist.xml and i want to retrive data from my mysql table. I have the following code as i am trying to use php code inside playlist.xml file. Code: [Select] <?xml version="1.0" encoding="utf-8"?> <xml> <?php $dbhost='localhost'; $dbuser='pavel'; $dbpass='pavel123'; mysql_connect($dbhost,$dbuser,$dbpass); mysql_select_db("amarmusic"); $sql=("select *from bband where artist='Meghdol' and album='Drohe Montre Valobasha';"); $res = mysql_query($sql); while ($result = mysql_fetch_array($res)){ ?> <track> <path> <? $result['link']?></path> <title><? $result['title']?></title> </track> <? } ?> </xml> but unfortunately its not working. any1 have any idea how to fix it? please help me. Hey guys, first post and I've just returned to PHP after about 4 years of no coding, so be gentle! In a nutshell I'm creating a photo album and I've pretty much got the majority of it complete, apart from a few tweaks and the obvious ongoing development. I'm at the stage now where I need to moderate images being uploaded, so I've made an admin only script which displays the uploaded images with links that say approve and delete. Uploaded images are stored in uploads/ which are left there until i move them to img/, plus the filename is stored in mysql so I can "<img src='../uploads/".$row['filename']."' width='200'>". Now, I would like to make the Approve button move the image from uploads/ to img/ and I'd like the delete button to remove both the entry from MySQL and the file from the uploads folder and I'm not too sure on how to make it work. Here's what I have so far in the mod.php file (mod for moderation) Code: [Select] $image = mysql_query("SELECT * FROM images WHERE id"); while($row = mysql_fetch_assoc($image)) { echo " <table> <td> <tr> <img src='../uploads/".$row['filename']."' width='200'><br /> </tr> </td> <td> <tr> <a href=''>Approve</a> <a href=''>Delete</a> </tr> </td> </table> "; } You'll have to ignore the table tags, I'm still getting used to positioning items on the screen lol. Any clues would be greatly appreciated Live long and prosper. I have a script that is supposed to allow a user to add their details to a members table in the database. It acts as if the user has been added to the database by stating the thank you message, but there is no entry into the database. I can connect to the database and have another script running OK that allows me to view all of the information in the members table with a loop (this data was entered using php my admin's GUI). Here is the script that is supposed to add the member. Any help would be greatly appreciated. <?php error_reporting(-1); $user_name = "root"; $password = ""; $database = "test"; $server = "localhost"; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO members (fname, sname, email, password, gender) VALUES ('$_POST[fname]','$_POST[sname]','$_POST[email]','$_POST[password]','$_POST[gender]')"; $result = mysql_query($SQL); mysql_close($db_handle); print "Thanks for joining us ".$_POST['fname']."."; } else { print "Database NOT Found"; mysql_close($db_handle); } ?> Hi Guys, I have stuck with my problem and i am nothing to php, i already posted this to another php script forum, but haven't solve, so i wondering if anyone here help me and many thanks. this is all about game scores from .xml file inside the xml file itself as: Code: [Select] <gesmes:Envelope> <gesmes:subject>Reference Scores</gesmes:subject> - <gesmes:Sender> <gesmes:name>Game Information Scores</gesmes:name> </gesmes:Sender> - <Cube> - <Cube time="2010-10-13"> <Cube scores="GameA1" value="1.5803"/> <Cube scores="GameA2" value="21.35"/> ............etc <Cube scores="GameA15" value="135"/> </Cube> </Cube> </gesmes:Envelope> then i got php script that can save all data of .xml above to mysql, look like <?php class Scores_Converter { var $xml_file = "http://192.168.1.112/gamescores/scores-daily.xml"; var $mysql_host, $mysql_user, $mysql_pass, $mysql_db, $mysql_table; var $scores_values = array(); //Load convertion scores function Scores_Converter($host,$user,$pass,$db,$tb) { $this->mysql_host = $host; $this->mysql_user = $user; $this->mysql_pass = $pass; $this->mysql_db = $db; $this->mysql_table = $tb; $this->checkLastUpdated(); $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); $sql = "SELECT * FROM ".$this->mysql_table; $rs = mysql_query($sql,$conn); while($row = mysql_fetch_array($rs)) { $this->scores_values[$row['scores']] = $row['value']; } } /* Perform the actual conversion, defaults to 1.00 GameA1 to GameA3 */ function convert($amount=1,$from="GameA1",$to="GameA3",$decimals=2) { return(number_format(($amount/$this->scores_values[$from])*$this->scores_values[$to],$decimals)); } /* Check to see how long since the data was last updated */ function checkLastUpdated() { $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); $sql = "SHOW TABLE STATUS FROM ".$this->mysql_db." LIKE '".$this->mysql_table."'"; $rs = mysql_query($sql,$conn); if(mysql_num_rows($rs) == 0 ) { $this->createTable(); } else { $row = mysql_fetch_array($rs); if(time() > (strtotime($row["Update_time"])+(12*60*60)) ) { $this->downloadValueScores(); } } } /* Download xml file, extract exchange values and store values in database */ function downloadValueScores() { $scores_domain = substr($this->xml_file,0,strpos($this->xml_file,"/")); $scores_file = substr($this->xml_file,strpos($this->xml_file,"/")); $fp = @fsockopen($scores_domain, 80, $errno, $errstr, 10); if($fp) { $out = "GET ".$scores_file." HTTP/1.1\r\n"; $out .= "Host: ".$scores_domain."\r\n"; $out .= "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8) Gecko/20051111 Firefox/1.5\r\n"; $out .= "Connection: Close\r\n\r\n"; fwrite($fp, $out); while (!feof($fp)) { $buffer .= fgets($fp, 128); } fclose($fp); $pattern = "{<Cube\s*scores='(\w*)'\s*value='([\d\.]*)'/>}is"; preg_match_all($pattern,$buffer,$xml_values); array_shift($xml_values); for($i=0;$i<count($xml_values[0]);$i++) { $exchange_value[$xml_values[0][$i]] = $xml_values[1][$i]; } $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); foreach($exchange_value as $scores=>$value) { if((is_numeric($value)) && ($value != 0)) { $sql = "SELECT * FROM ".$this->mysql_table." WHERE scores='".$scores."'"; $rs = mysql_query($sql,$conn) or die(mysql_error()); if(mysql_num_rows($rs) > 0) { $sql = "UPDATE ".$this->mysql_table." SET value=".$value." WHERE scores='".$scores."'"; } else { $sql = "INSERT INTO ".$this->mysql_table." VALUES('".$scores."',".$value.")"; } $rs = mysql_query($sql,$conn) or die(mysql_error()); } } } } /* Create the scores table */ function createTable() { $conn = mysql_connect($this->mysql_host,$this->mysql_user,$this->mysql_pass); $rs = mysql_select_db($this->mysql_db,$conn); $sql = "CREATE TABLE ".$this->mysql_table." ( scores char(3) NOT NULL default '', value float NOT NULL default '0', PRIMARY KEY(scores) ) ENGINE=MyISAM"; $rs = mysql_query($sql,$conn) or die(mysql_error()); $sql = "INSERT INTO ".$this->mysql_table." VALUES('GameA0',1)"; $rs = mysql_query($sql,$conn) or die(mysql_error()); $this->downloadValueScores(); } } ?> but that php script above just create table of mysql below CREATE TABLE IF NOT EXISTS `scrore_table` ( `scores` char(3) NOT NULL default '', `value` float NOT NULL default '0', PRIMARY KEY (`scores`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; INSERT INTO `scrore_table` (`scores`, `value`) VALUES ('GameA0', 1), ('GameA1', 1.5651), ......etc ('GameA15', 95.572); while of my existing database table look like: CREATE TABLE IF NOT EXISTS `scrore_table` ( `scrore_id` int(11) NOT NULL auto_increment, `scrore_title` varchar(32) collate utf8_bin NOT NULL default '', `scores` varchar(3) collate utf8_bin NOT NULL default '', `decimal_place` char(1) collate utf8_bin NOT NULL, `value` float(15,8) NOT NULL, `date_updated` datetime NOT NULL default '0000-00-00 00:00:00', PRIMARY KEY (`currency_id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; ; INSERT INTO `scrore_table` (`scrore_id`, `scrore_title`, `scores`, `decimal_place`, `value`, `date_updated`) VALUES (1, 'Game Class A0', 'GameA0', '2', 1.00000000, '2010-04-06 22:00:54'), (2, 'Game Class A1', 'GameA1', '2', 1.52600002, '2010-04-06 22:00:54'), ..............................etc (14, 'Game Class A15', 'GameA15', '2', 1.13999999, '2010-04-06 22:00:54'); as i said i newbie to php then i dont know how to modify the php code above able to automatically create the table and insert/update new fields e.g. scrore_id, scrore_title,decimal_place, date_updated also all values to my existing database i looking for some helps and thanks in advance.. Hello, can someone help me with my proggraming problem please. Am new in this so i still have lots problems. I need to put all data from my MySQL table in one table in html. There is catch... i need to design output to give me table with x rows and 3 columns, so it means while reading data from database it need put every 4th in new row. And if there isnt 3 data (or better say if there isnt 3 full <td>) in row code will automatically add empty <td> or 2 in table. So...did somebody do this before or have some code ? All i got for now is Code: [Select] $td ='<td align="center"><img src="'.$row['name'].'.png" /> <p style="font-family:Verdana, Geneva, sans-serif; font-size:15px"> Number: <b style="font-size:40px;">'.$row['serial'].'</b></p> <br><img width="90" height="29" src="'.$logo.'"/></td>'; $tr ='<tr>'.$td.'</tr>'; $html='<table border="1" align="center">'.$tr.'</table>'; Thanks. I have MySQL table with the following fields: user=>varchar product=>varchar Amount=>int Date=>date Note=>tinytext I can't add value to these field by the following php code: $date = date("Y.m.d"); $query = "INSERT INTO order VALUES ('farhad', 'Mango', '10', '$date', 'hello')"; $result = mysql_query($query) or die(mysql_error()); I receive the following warning: Warning: date(): It is not safe to rely on the system's timezone settings. You are *required* to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected 'Europe/Paris' for '2.0/DST' instead in C:\inetpub\wwwroot\Okern\~order.php on line 10 Call Stack: 0.0047 325856 1. {main}() C:\inetpub\wwwroot\Okern\~order.php:0 0.0274 344912 2. date() C:\inetpub\wwwroot\Okern\~order.php:10 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('farhad', 'Mango', '10', '2011.04.17', 'hello')' at line 1 |