PHP - Wont Insert File Name Into Sql
I've Basically got this script and everything works. Except for the part that it doesen't insert "$_FILES['file']['name']" into the image_url.
Any Ideas guys? Code: [Select] <? include "includes/config.php"; if (isset($_POST['add'])) { if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/png")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("images/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; echo $_FILES['file']['name']; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "images/" . $_FILES["file"]["name"]); } } } else { echo "Sorry, but only PNG, JPG, and GIF files are allowed."; } mysql_connect ($mysql_host, $mysql_user, $mysql_pass); mysql_select_db ($mysql_db); $image_url = "http://localhost/admin/images/". $_FILES['file']['name'] .""; $sql = "INSERT INTO test (title, link, description, image_url) VALUES ('$_POST[title]', '$_POST[link]', '$_POST[description]', '$image_url')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } header( 'Location: portfolio.php' ); mysql_close(); } ?> Code: [Select] <form enctype="multipart/form-data" method="post"> <p> <strong>TITLE</strong><br/> <input type="text" name="title" class="box"/> </p> <p> <strong>LINK</strong><br/> <input type="text" name="link" class="box"/> </p> <p> <strong>IMAGE</strong><br/> <input type="file" class="box" name="file"/> </p> <p> <strong>DESCRIPTION</strong><br/> <input type="textarea" name="description" class="box"/> </p> <p> <input name="add" type="submit" id="submit" tabindex="5" class="com_btn" value="ADD WORK"/> </p> </form> Similar TutorialsHey all Hope ya can help. its almost done just having problems with the new data getting inserted into the current table. Code: [Select] foreach($_SESSION as $key => $value) { $key = $value; } echo $item_number . "<br>" . $po_number . "<br>" . $lot_number . "<br>" . $amount ; $query = "SELECT * FROM invintory WHERE item_number ='$item_number'"; $result = mysql_query($query) or die ("couldnt execute query." . mysql_error()); while ($row = mysql_fetch_array($result)) { $onhand = $row['onhand']; } echo $onhand ; $newamount=$onhand+$amount; echo $newamount; [color=red]mysql_query("INSERT INTO invintory WHERE item_number ='$item_number'(onhand) values ('$newamount')");[/color] mysql_query("INSERT INTO recvied(item_number,po_number,lot_number,amount) values ('$item_number','$po_number','$lot_number','$amount')"); ?>The part in red seems to be the problem Hi Guys, in code below i dont see any reason why it doesnt add anything into my mysql, can u please tell me where is wrong? <?php session_start(); include ("includes/db.php"); include ("includes/function.php"); //authentication if (loggedin()==FALSE) { Header("Location: login.php"); exit(); } //username session $_SESSION['username']=='$username'; $username=$_SESSION['username']; echo "Welcome, " .$_SESSION['username']."!<p>"; //get details from user table to be passed to page(text fields) $getdetails=mysql_query("SELECT * FROM users WHERE username='$username'"); while($row = mysql_fetch_array($getdetails)) { $users_id=$row['id']; $first_name=$row['first_name']; $last_name=$row['last_name']; $email=$row['email']; } /////////////////////////////////////// //****************************// //post starts here if (isset($_POST['next']) && $_POST['next']) { $myfirstname = addslashes(strip_tags($_POST['firstname'])); $mylastname = addslashes(strip_tags($_POST['lastname'])); $myemail = addslashes(strip_tags($_POST['email'])); $mybookingdate = addslashes(strip_tags($_POST['datetime'])); $mytime = addslashes(strip_tags($_POST['time'])); $myseatnumber = addslashes(strip_tags($_POST['seatnumber'])); $ride_id=1; //check if booking exists $checkbooking=mysql_query("SELECT * FROM booking WHERE date='$mybookingdate' AND time='$mytime' AND seat_no='$myseatnumber'"); if (mysql_num_rows($checkbooking)>=1) { echo "Seat No $myseatnumber For $mybookingdate at $mytime has been already taken, Please try a different seat, time or date"; } else { $addbooking=mysql_query("INSERT INTO booking (ride_id, users_id, time, date, seat_no) VALUES ('$ride_id','$users_id','$mytime','$mybookingdate','$myseatnumber'"); } } ?> <html> <head> <link type="text/css" href="css/smoothness/jquery-ui-1.8.6.custom.css" rel="stylesheet" /> <script type="text/javascript" src="includes/jquery-1.4.2.min.js"></script> <script type="text/javascript" src="includes/jquery-ui-1.8.6.custom.min.js"></script> <script type="text/javascript"> $(function() { $('#datetime').datepicker({ dateFormat: 'dd.mm.yy' }); }); </script> </head> <body> <form name="booking" method="post" action=""> <p>First Name:<br /> <input type="text" name='firstname' value="<? echo "$first_name";?>"> <p>Last Name:<br /> <input type="text" name='lastname' value="<? echo "$last_name";?>"> <p>Email:<br /> <input type="text" name='email' value="<? echo "$email";?>"> <p>Choose a Date:<br /> <input type="text" name='datetime' id="datetime"> </p> <p> Select a Time:<br/> <select name='time'> <option value="9:00">9:00 <option value="9:07">9:07 <option value="9:14">9:14 <option value="9:21">9:21 <option value="9:28">9:28 <option value="9:35">9:35 <option value="9:42">9:42 <option value="9:49">9:49 <option value="9:56">9:56 <option value="10:03">10:03 <option value="10:10">10:10 <option value="10:17">10:17 <option value="10:24">10:24 <option value="10:31">10:31 <option value="10:38">10:38 <option value="10:45">10:45 <option value="10:52">10:52 <option value="10:59">10:59 <option value="11:02">11:02 <option value="11:09">11:09 <option value="11:16">11:16 <option value="11:23">11:23 <option value="11:30">11:30 <option value="11:37">11:37 <option value="11:44">11:44 <option value="11:51">11:51 <option value="11:58">11:58 </select> </p> <p> Select Seat Number:<br/> <select name='seatnumber'> <option value="1">Seat 1 <option value="2">Seat 2 <option value="3">Seat 3 <option value="4">Seat 4 <option value="5">Seat 5 <option value="6">Seat 6 <option value="7">Seat 7 <option value="8">Seat 8 <option value="9">Seat 9 <option value="10">Seat 10 <option value="11">Seat 11 <option value="12">Seat 12 <option value="13">Seat 13 <option value="14">Seat 14 <option value="15">Seat 15 <option value="16">Seat 16 <option value="17">Seat 17 <option value="18">Seat 18 <option value="19">Seat 19 <option value="21">Seat 20 <option value="22">Seat 22 <option value="23">Seat 23 <option value="24">Seat 24 <option value="25">Seat 25 <option value="26">Seat 26 <option value="27">Seat 27 <option value="28">Seat 28 <option value="20">Seat 29 <option value="30">Seat 30 <option value="31">Seat 31 <option value="32">Seat 32 <option value="33">Seat 33 <option value="34">Seat 34 <option value="35">Seat 35 <option value="36">Seat 36 <option value="37">Seat 37 <option value="38">Seat 38 <option value="39">Seat 39 <option value="40">Seat 40 <option value="41">Seat 41 <option value="42">Seat 42 <option value="43">Seat 43 <option value="44">Seat 44 <option value="45">Seat 45 <option value="46">Seat 46 <option value="47">Seat 47 <option value="48">Seat 48 </select> <p> <input type='submit' name='next' value='Next Step'> </form> <p> </body> </html> any help with this please? it works fine with deleting database results but the unlink wont unlink file from dir? Code: [Select] else if($action=="del") { $id = $_GET["id"]; $cls = $_GET["cls"]; $dir = "gallery/$cls"; echo "<p align=\"center\">"; $owner = mysql_fetch_array(mysql_query("SELECT uid FROM gallery WHERE id='".$id."'")); if(mod(getuid_id($id))||getuid_id($id)==$owner[0]) { $res = mysql_query("DELETE FROM gallery WHERE id='".$id."'"); $res2 = mysql_query("DELETE FROM comments WHERE pid='".$id."'"); $res3 = mysql_query("DELETE FROM rate WHERE pid='".$id."'"); if($res||res2||res3 || unlink($dir)) { echo "Photo Deleted From Gallery<br/>"; }else{ echo "Database Error!<br/>"; } }else{ echo "You can't delete this Photo"; } So I really don't think I need to paste the code but Code: [Select] <?php session_start(); ?> <?php $new_thread_page_path = 'general_discussion_threads/' . $_POST['thread_title'] . '.php'; $new_table_link = '<a href="' . $new_thread_page_path . '"' . 'class="hover" border="0" style="text-decoration:none">' . $_POST['thread_title'] . '</a>'; ?> <?php date_default_timezone_set('EST'); $date = date("m/d/y"); $hour = date("g"); $minute = date("i"); $second = date("s"); $am_pm = date("a"); $full_date = $date . ' ' . $hour . ":" . $minute . ":" . $second . $am_pm; $place_holder = '<!--the_place_holder-->'; $current_page_path = 'general_discussion_home.php'; $open_current_page = fopen($current_page_path, 'rb'); $contents_of_current_page = fread($open_current_page, filesize($current_page_path)); $template_path = 'general_discussion_threads/template.php'; $open_template = fopen($template_path, 'rb'); $template_contents = fread($open_template, filesize($template_path)); $new_thread_page_path = 'general_discussion_threads/' . $_POST['thread_title'] . '.php'; $list_file_path = 'general_discussion_threads/thread_list.txt'; $list_open = fopen($list_file_path, 'rb'); $list_open_write = fopen($list_file_path, 'a'); $open_new_thread_page = fopen($new_thread_page_path, 'w+'); $list_contents = fread($list_open, filesize($list_file_path)); $thread_exists_test = substr_count($list_contents, '<' . strtolower($_POST['thread_title'] . '>')); $invalid_character_test = substr_count($_POST['thread_title'], '<'); $invalid_character_test1 = substr_count($_POST['thread_title'], '>'); $the_users_info = $_SESSION['the_user']; $the_username1 = strstr($_SESSION['the_user'], '.'); $the_username1_wipe = str_replace($the_username1, '', $the_users_info); $the_username = str_replace('.', '', $the_username1_wipe); if (isset($_POST['new_thread_post'])) { if (($_SESSION['logged_in'] == '1') && ($invalid_character_test1 == '0') && ($invalid_character_test == '0') && ($thread_exists_test == '0') && ($_POST['thread_title'] != '') && ($_POST['thread_title'] != 'Enter the title of your Thread...')) { fwrite($open_new_thread_page, '<?php $the_thread_title = ' . '\'' . $_POST['thread_title'] . '\'' . '; ?>' . $template_contents); fclose($open_new_thread_page); fwrite($list_open_write, '<' . strtolower($_POST['thread_title']) . '>'); fclose($list_open_write); $new_contents =str_replace($place_holder, '<tr><td align="center">' . $new_table_link . '</td>' . '<td align="center">' . '<font color="#66CC00">' . $full_date . '</font>' . '</td>' . '<td align="center">' . '<font color="#66CC00">' . $the_username . '<font>' . '</td>' . '</tr>' . $place_holder, $contents_of_current_page); $open_current_page = fopen($current_page_path, 'w'); fwrite($open_current_page, $new_contents); fclose($open_current_page); $_SESSION['gd_error'] = 'Thread created succesfully!'; } elseif ($_SESSION['logged_in'] != '1') { $_SESSION['gd_error'] = 'You need to be logged in!'; } elseif ($invalid_character_test != '0') { $_SESSION['gd_error'] = 'Thread title contains invalid characters!'; } elseif ($invalid_character_test1 != '0') { $_SESSION['gd_error'] = 'Thread title contains invalid characters!'; } elseif ($thread_exists_test != '0') { $_SESSION['gd_error'] = 'Thread title unavailable!'; } elseif ($_POST['thread_title'] == '') { $_SESSION['gd_error'] = 'You must make a thread title!'; } elseif ($_POST['thread_title'] == 'Enter the title of your Thread...') { $_SESSION['gd_error'] = 'You must make a thread title!'; } } ?> So what all this does is based on user input it creates a new html page based off of the template with a few different variables based on input. Then it makes a new row and 3 cells in the home pages thread table that link to the page say who made it and what time they made it. Now it all works PERFECT (Im suprised how perfect on the first try actually) except for 1 tiny flaw which i think might be php not me but im not sure. The fwrite creates a new file but if the input contains any question marks (?) the link will work but no file will be created. For everyother character on teh standard keyboard its fine but not the question mark. What gives? thanks yall! MOD EDIT: <code></code> tags changed to proper [code] . . . [/code] BBCode tags. Well hello there, I want to create a script that writes a few PHP constants to a file called config.php. It does not work however, with the way I wrote it as below: Code: [Select] $configdata = "<?php //Configuration File \define("DBHOST", $dbhost); //DB Hostname \define("DBUSER", $dbuser); //DB Username \define("DBPASS", $dbpass); //DB Password \define("DBNAME", $dbname); //Your database name \define("DOMAIN", $domain); //Your domain name (No http, www or . ) \define("SCRIPTPATH", $scriptpath); //The folder you installed this script in \define("PREFIX", $prefix); ?>"; $file = fopen('../inc/config.php', 'w'); fwrite($file, $configdata); fclose($file); I am getting this error 'syntax error, unexpected T_STRING in ...', and I have no idea how to fix it. Strangely the below codes using PHP variables work flawlessly: Code: [Select] $configdata = "<?php //Configuration File \$dbhost = '{$dbhost}'; //DB Hostname \$dbuser = '{$dbuser}'; //DB User \$dbpass = '{$dbpass}'; //DB Password \$dbname = '{$dbname}'; //Your database name \$domain = '{$domain}'; //Your domain name (No http, www or . ) \$scriptpath = '{$scriptpath}'; //The folder you installed this script in \$prefix = '{$prefix}'; ?>"; //Write the config.php file... $file = fopen('../inc/config.php', 'w'); fwrite($file, $configdata); fclose($file); This confuses me, all I did was to change the string to output from a list of variables to a list of constants, and it gives weird errors that I have absolutely no idea how to fix. Can anyone please lemme know what I did wrong? Thanks. 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'");
I want to limit the length of an author's name in a display to 10 characters - using two lines if necessary for full display. I know I can use wordwrap of some sort to do that. However, I am not sure where/how to accomplish it. Can it be inserted in the following (and if so, where/what do I insert, specifically): Code: [Select] <?php _e('Order by','authors') ?>:<br /> <label for="authors-order-<?php echo $number; ?>-name"><input type="radio" class="radio" id="authors-order-<?php echo $number; ?>-name" name="widget-authors[<?php echo $number; ?>][order]" value="name"<?php echo 'name' == $order || '' == $order ? ' checked="checked"' : '' ?> /> <?php _e('Display name','authors' ) ?></label> NOTE: I have attached the full code in a text file if I've selected the wrong snip. Thank you! [attachment deleted by admin] Hi, I am trying to insert the contents of a csv file into a table, this is my code: public function InsertCSVFileToDB(){ $has_title_row = true; $not_done = array(); if(is_uploaded_file($_FILES['csvfile']['tmp_name'])){ $filename = basename($_FILES['csvfile']['name']); if(substr($filename, -3) == 'csv'){ $tmpfile = $_FILES['csvfile']['tmp_name']; if (($fh = fopen($tmpfile, "r")) !== FALSE) { $i = 0; while (($items = fgetcsv($fh, 10000, ",")) !== FALSE) { if($has_title_row === true && $i == 0){ // skip the first row if there is a tile row in CSV file $i++; continue; } $sql = "INSERT INTO ConfPaper SET CPRid = ".$items[0].", Pid = ".$items[1].", CPtitle = '".mysql_real_escape_string($items[2])."', CPabstract = '".mysql_real_escape_string($items[3])."', CPspage = ".mysql_real_escape_string($items[4]).", CPepage = ".mysql_real_escape_string($items[5]).", CPlastesited = now()"; if(!mysql_query($sql)){ $not_done[] = $items; } $i++; } } // if there are any not done records found: if(!empty($not_done)){ echo "<strong>There are some records could not be inserted</strong><br />"; print_r($not_done); } } else{ die('Invalid file format uploaded. Please upload CSV.'); } } else{ die('Please upload a CSV file.'); } } This is the csv file: http://www.prima.cse.salford.ac.uk:8080/~ibrarhussain/ConfPaper.csv But i keep getting this: Quote Array ( => Array ( => 9 [1] => 1 [2] => CSV1 [3] => 4 [4] => 4 [5] => 01625 584412 ) [1] => Array ( => 9 [1] => 1 [2] => CSV2 [3] => 14 [4] => 24 [5] => 01625 584412 ) ) Any ideas what the problem might be? Hope someone can help.. Thanks Thanks ahead of time, I have been working this all week end but get lost.... a. I want to insert all the lines from file1.txt into file2.txt . b. I want the all lines in file1.txt to be inserted in file2.txt starting at "<image>" tag label in file2.txt. c. I would like to overwrite all lines that start with the "<image>" tag in file2.txt with the insert (text in file1.txt contains <image> tag also). file2.txt has lines above and below the insert point <image>. The insert text (file1.txt) could be as many as twenty lines (records) all/each beginning with the<image>tag. Here is what I have done so far. <? $key = '<image>'; //a text tag in $file1 and $file2 //copy file $file = "file1.txt"; $file2= 'file2.txt"; $newfile = "filetemp.txt"; copy($file, $newfile) or exit("could not copy $file"); //load file array $fc = fopen ($file, "r"); while (!feof ($fc)) { $buffer = fgets($fc, 4096); $lines[] = $buffer; } fclose ($fc); //open same file and use "w" to clear file ,not sure this is needed $f=fopen($newfile,"w") or die("$file did not open"); /* uncomment to debug print_r($lines); print "<br>\n"; */ //loop through array 'foreach foreach($lines as $line) { fwrite($f,$line); //rewrite $line in file if (strstr($line,$key)){ //find $key in each line fwrite($f,$newline."\n"); } //rewrite $line in file } fclose($f); copy($newfile, $file2) or exit("could not copy $newfile"); ?> Again thanks ahead of time, I just keep losing the flow, old I guess. Tom <?php require_once("../includes/session.php");?> <?php require_once("../includes/connection.php");?> <?php require_once("../includes/function.php");?> <?php confirm_logged_in();?> <?php require_once("../includes/validation_functions.php");?> <?php if(isset($_POST['submit'])){ //process the form // often there are form values in $_POST $product_name = mysql_prep($_POST["product_name"]); $product_amount = (int) $_POST["product_amount"]; $visible = (int) $_POST["visible"]; foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){ $file_tmp =$_FILES['files']['tmp_name'][$key]; $uploaded_dir = "images/"; $filename = $_FILES['files']['name'][$key]; $path = $uploaded_dir . $filename; move_uploaded_file($file_tmp,"images/".$_FILES['files']['name'][$key]); $query ="INSERT INTO products ("; $query .=" name, amount, visible"; $query .=") VALUES ("; $query .=" '{$product_name}',{$product_amount},{$visible}"; $query .=")"; $result = mysqli_query($connection,$query); $last_id = mysqli_insert_id($connection); $sql.= "('$last_id','$path'),"; $sql ="INSERT INTO images ( productID, file_name ) VALUES". trim($sql,','); $results = mysqli_query($connection,$sql); // validations $required_fields = array("product_name", "product_amount"); validate_presences($required_fields); $fields_with_max_lenghts = array("product_name" => 30); validate_max_lenght($fields_with_max_lenghts); if(!empty($errors)){ $_SESSION["errors"] = $errors; redirect_to("new_product.php"); } if($result && $results ){ // Sucess $_SESSION["message"] = "Product inserted."; redirect_to("manage_content.php"); }else{ // Failure $_SESSION["message"] = "Product insertion Failed."; redirect_to("new_product.php"); } } }else{ // THis is probably a GET request redirect_to("new_product.php"); } ?> <?php if(isset($connnection)){ mysqli_close($connection); } ?>Attached Files new_product.php 1.35KB 0 downloads create_product.php 1.99KB 0 downloads I set up a Twilio number so a client could have a SMS keyword response setup... but I don't know how to get the contents of a file to be returned as the response. I am using the php functions.. I setup a system so that my client could change the responses to different keywords. Basicly it uses a webform to change the contents of a file which gets returned as a response. What I need to know is how to read in the contents of the file into this function: BTW... this works fine and will return "READ_FILE_CONTENTS_INTO_HERE" function app(){ $response = new Services_Twilio_Twiml(); $response->sms("READ_FILE_CONTENTS_INTO_HERE"); echo $response; } I tried this but it stopped the script dead: function app(){ $response = new Services_Twilio_Twiml(); $response->sms("<?php include 'file.txt'; ?>"); echo $response; } Any ideas? Thanks BTW... below is the entire php script: <?php /* Include twilio-php, the official Twilio PHP Helper Library, * which can be found at * http://www.twilio.com/docs/libraries */ include('Services/Twilio.php'); /* Controller: Match the keyword with the customized SMS reply. */ function index(){ $response = new Services_Twilio_Twiml(); $response->sms("Thank You For Contacting SweetLeafAZ.com - Reply with one of the following keywords: APP = Make Appt, CS = Current Strains, DP = Delivery Prices, SP = Current Specials."); echo $response; } function app(){ $response = new Services_Twilio_Twiml(); $response->sms("http://www.vcita.com...01f2c7d/home"); echo $response; } function cs(){ $response = new Services_Twilio_Twiml(); $response->sms("http://mobile.dudamo...sweetleafaz2"); echo $response; } function dp(){ $response = new Services_Twilio_Twiml(); $response->sms("As of Sept 26 2014, Our Delivery Rates are $2 per mile during the hours of 9am to 6pm. No deliveries will be made after 6pm."); echo $response; } function sp(){ $response = new Services_Twilio_Twiml(); $response->sms("We are currently offering FREE delivery within 10 miles for orders over $100."); echo $response; } /* Read the contents of the 'Body' field of the Request. */ $body = $_REQUEST['Body']; /* Remove formatting from $body until it is just lowercase characters without punctuation or spaces. */ $result = preg_replace("/[^A-Za-z0-9]/u", " ", $body); $result = trim($result); $result = strtolower($result); /* Router: Match the ‘Body’ field with index of keywords */ switch ($result) { case 'app’': app(); break; case 'cs': cs(); break; case 'dp': dp(); break; case 'sp': sp(); break; /* Optional: Add new routing logic above this line. */ default: index(); } im doing smting basically wrong Code: [Select] <form action="" method="post"> <?php $x=1; $images = $_GET['images']; for( $i=0; $i<$images; $i++ ) { echo '<input name="ID" type="hidden" value="1234" /> <br> <input name="ImageURL['.$i.']" type="file" value=""/><br><br>'; } ?> <input name="submit" type="submit" /> <?php $con = mysql_connect("localhost","root","root"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_query("SET NAMES 'utf8'"); mysql_select_db("international", $con); if (isset($_POST['submit'])) for( $i=0; $i<$images; $i++ ) { $query=mysql_query("INSERT INTO images (ID,ImageURL) VALUES ('$_POST[ID]','$_POST[ImageURL]')"); exit; mysql_close($con); } ?></form> Hello, i have this php code. Its for sms insertion of links in to table <table border="1"> <?PHP $db_user = 'user'; $db_pass = 'pass'; $db_name = 'name'; $db_host = 'localhost'; if(mysql_connect($db_host,$db_user,$db_pass)) { mysql_select_db($db_name); mysql_query("CREATE TABLE IF NOT EXISTS smsads(id bigint unsigned primary key auto_increment, link varchar(255), fromnum varchar(60))"); $res = mysql_query("SELECT * FROM smsads ORDER BY id DESC LIMIT 10"); while($row = mysql_fetch_object($res)) { $http_link = $row->link; if(strstr($http_link, 'http') === FALSE) $http_link = 'http://'.$http_link; echo "<tr><td><a href=\"{$http_link}\" target=\"_blank\">{$row->link}</a></td></tr>"; } } ?> </table> The problem is that i use tpl files for the visual part and all my other tables are in tpl. How can i insert the table above in my tpl file, whitout loosing its functions? im working on my website and im trying to insert text from a file into the webpage. the webpage is index.php the .txt file is indexbody.txt at the point of where the code is i would like to insert the contents of the text file into the html document so the person viewing the site can read it as if it was directly in that webpage. i hope you understand what im asking the current not working code is: <?php $myFile = "indexbody.txt"; $fh = fopen($myFile, 'r'); $theData = fread($fh, 5); fclose($fh); echo $theData;?> Hello, I'm having some frustrations right now. I have built an application form where an applicant inputs their info and then uploads their resume. Even though the resume gets uploaded to a directory on the server i would also like the file name of the resume to get inserted into the mysql database so that I can easily see which resume matches which applicant...if that makes sense. At any rate I'm able to get everything else to work, the applicant's info gets inserted into the database, the resume gets uploaded to the directory, i just can't seem to get the resume file name to also insert into the database. Most of the info i have found on this subject through googleing and the like has been a little over my head and/or a little more complex than what i'm looking for. Here is an extremely simplified version of what I have right now. I have excluded the 'connect to database' code since it's working fine and really doesn't have anything to do with this issue: Code: [Select] <?php $target_path = "docs/"; $target_path = $target_path . basename( $_FILES['resume']['name']); $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $middle_init=$_POST['middle_init']; $resume=$_POST['resume']; mysql_query("INSERT INTO `intern` VALUES ('$first_name', '$last_name', '$middle_init', '$resume')") ; if (move_uploaded_file($_FILES['resume']['tmp_name'], $target_path)); ?> HTML begins after that. At any rate, any info, help, etc. you could provide would be GREATLY appreciated! Thanks! Code I'm using if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Successfully uploaded image!"; if (file_exists("img/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "img/" . $_FILES["file"]["name"]); echo "<a href='img/$filename'>Your File</a>; } } } else { echo "Invalid file"; } mysql_query("INSERT INTO $tbl (body, name, subject, ip, timestamp, img) VALUES ('$body', '$name', '$subject', '$ip', '$timestamp', '$imglink')"); mysql_query("INSERT INTO total (ip, subject, name, board) VALUES ('$ip','$subject','$name','$dfg')"); echo "<font color='red'><font size='15'><strong><center>Successfully posted to /$tbl/"; //print("<meta http-equiv='REFRESH' content='0;url=index.php?board=$tbl'>"); If I have the query on the top it runs, and the upload img doesn't && vice versa Hi.., My code is like: Code: [Select] <?php $filename ="excelreport.xls"; print "<table border=1>"; print "<tr ><td valign=bottom><img src=http://abc/images/big.png ></img></td> <td valign=bottom><img src=http://abc/images/small.png ></img></td> </tr>"; print "</table>"; header('Content-type: application/ms-excel'); header('Content-Disposition: attachment; filename='.$filename); ?>when I open the excel file, the images alignment is from top to bottom(equal from top of image). what i want is from bottom to top(equal from bottom of image). i did try using valign in td property, but still the images equal from top of image thanks for any reply/ help I'm trying to create a INSERT query statement that makes use of the content of 'include' files. When I call up the include it simply echos it to the screen but I can't seem to capture the text string and actually make it function as part of the query. I've tried setting the include as a variable but again it only outputs to the screen. Help please! Here's a portion of the code... if (($_POST['sched_templates']) == "sched_TestingOnly.htm") { $query = include 'sched_TestingOnlyQuery1.htm'; } if (@mysql_query ($query)) { mysql_close(); // End adding Registration to the database header ('Location: redirectfile.htm'); exit(); } else { print "<p><b>Sorry, your entry could not be entered. } i need to upload files to a different folder dependint on option in form, make thumbnails, and store title and src for image and thumb in database table dependant on category. i think i'm pretty close, but there's still something wrong. Here is my upload form : Code: [Select] <form enctype="multipart/form-data" action="upload.php" method="POST"> Photo: <input type="file" name="photo"><br> Category: <select name="cat"> <option value="weddings">Weddings</option> <option value="music">Music</option> <option value="portraits">Portraits</option></select> Title: <input type="text" name="title"><br> <input type="submit" value="Upload photo"> </form> form processed by upload.php : Code: [Select] <?php require "db.php"; //Get form info $name=$_POST['name']; $title=$_POST['title']; $category=$_POST['cat']; $pic=($_FILES['photo']['name']); //set target dir source file width height $target = $cat."/"; $src = $target . basename( $_FILES['photo']['name']); $destination = $cat."/thumbs"; $thumbsrc = $destination . basename( $_FILES['photo']['name']); $width = 200; $height = 200; header("content-type: image/jpeg"); $src_img = imagecreatefromjpeg("$src"); $srcsize = getimagesize("$dest"); $dst_img = imagecreatetruecolor($width, $height); imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $width, $height, $srcsize[0], $srcsize[1]); imagejpeg($dst_img); //Unstert into db mysql_query("INSERT INTO `$category` VALUES ('$name', 'Stitle', '$src, $thumbsrc')") ; //move photo if(move_uploaded_file($_FILES['photo']['tmp_name'], $fulltarget)) { //Ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; } else { //not ok echo "Sorry, there was a problem uploading your file."; } ?> call a script from main page Code: [Select] <div class="gallery"> <?php include "weddings/get.php" ?> </div> <div class="gallery"> <?php include "music/get.php" ?> </div> get.php displays links Code: [Select] <?php include "db.php"; $cat = weddings; $q = "SELECT id, title, src, thumbsrc FROM $cat"; $result = $mysqli->query($q) or die(mysqli_error($mysqli)); if ($result) { echo "<ul id='photos'> \n"; while ($row = $result->fetch_object()) { $title = $row->title; $src = $row->src; $thsrc = $row->thumbsrc; $id = $row->id; echo "<a href='$src' class="lightbox" rel="$cat" title="$name - $title"><img src='$thsrc' id='$id' alt='$name' /></a>": } echo "</ul>"; } ?> I think i'm going along the right sort of path, but i'm not sure. I am very new to PHP and haven't wriiten an update program except in the class I took about 4 years ago using MYSQL.
The company I work for is using PDO so I am having a little bit of a learning curve.
I have a table with a checkbox at the end and I want to insert the records from the table into a new file I created called
OPPSHEDT
SHEDORD Order Number 14 Char
SHEDBORD BackOrder Number 2 Char
SHEDPKD Picked Cases 9,0 Decimal
SHEDSHP Shipped Cases 9,0 Decimal
I'm just not sure how to write the update program to read the array of records and run through the loop and insert the items checked. I saw some other examples on here and all over the internet but they were using mysql. I have a copy of the code to create my table below.
I'd appreciate the help if you can.
Thanks.
ShipEstimate.php 6.41KB
4 downloads
|