PHP - How To Save Different Array
good day here! I'm new in php, and i want to save diff array at the same time. is it possible?
if (isset($_POST['submit'])) { $user_Id = $_POST['user_Id']; $se_Id = $_POST['se_Id']; $status = $_POST['status']; foreach ($_POST['user_Id'] as $user_Id) <-- this is working, but I want to include the other array { mysql_query("INSERT tbl_data (user_Id,se_Id,status) VALUES ('$user_Id','$se_Id,'$status'')") or die(mysql_error()); } } help me guys. Similar TutorialsHow can i save array from inputs, witch is $igraci and it have 5 values, to mysql base, i tryed but in mysql it shows Array. This is form: <form action="dodaj_klan.php" method="post" > <p> <label>Naziv klana:</label> <input name="naziv" type="text" size="20%" /> <label>Web Sajt:</label> <input name="website" type="text" size="20%" /> <label>E-Mail:</label> <input name="email" type="text" size="20%" /> <br /><br /> <label>Igraci klana(5):</label> <input name="lider" type="radio" value="1" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="2" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="3" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="4" /> <input name="igraci[]" type="text" size="20%" /><br /> <input name="lider" type="radio" value="5" /> <input name="igraci[]" type="text" size="20%" /> <label><i>(obelezi lidera klana)</i></label> <br /><br /> <input class="button" type="submit" name="submit" value="Dodaj" /> </p> </form> Now i wonna save this igraci[] array in mysql, i tried like this but it doesn't work: $igraci = $_POST['igraci']; $query = "INSERT INTO klanovi (naziv, website, email, igraci) VALUES ('{$naziv}', '{$website}', '{$email}', '{$igraci}')"; $result = mysql_query($query, $connection); How can i do this? Thanks.. Hey, my code doesnt work and I dont know why: $update_weed_world_data_sql = "SELECT weed_factor, weed_basis FROM worlds"; $update_weed_world_data_res = mysql_query($update_weed_world_data_sql) OR DIE (mysql_error()); while($update_weed_world_data_while = mysql_fetch_assoc($update_weed_world_data_res)){ $update_weed_world_basis[''.$update_weed_world_data_while['id'].''] = $update_weed_world_data_while['weed_basis']; $update_weed_world_factor[''.$update_weed_world_data_while['id'].''] = $update_weed_world_data_while['weed_factor']; } I want to save some rows in variables identifiable by the value in the array. As example. When I want to echo $update_weed_world_factor['1'] - I want to get the row with ID 1 and the column "world_factor". I've used this code long time ago - but know something was going wrong. Thanks for helping :-) Hi, I'm trying to save data from an array to database but something is wrong. This is from i send data, as you see im using arrays [] because the user have the posibility to clone the row <div class="box-body"> <div class="form-group"> <label class="col-sm-2">Student</label> <div class="col-sm-10"> <table id="table" border="1" bordercolor="#00acc1"> <thead> <tr> <th><p>Name</p></th> <th><p>Mode</p></th> <th><p>Sport</p></th> <th> </th> </tr> </thead> <tbody> <tr> <td><select style="width:325px" name="Name[]" class="form-control"> <option value="">Select</option> <?php $search = "SELECT * FROM prof"; $data = $connect->prepare($search); $data->execute(); while($re=$data -> fetch(PDO::FETCH_ASSOC)){ echo "<option value = '".$re['id']."'>"; echo $re['n_prof'].' '.$re['ap_prof'];} ?> </select> </td> <td> <select class="form-control" name="mode[]" style="width:150px" /> <option value="">Select</option> <option value="Administrator">Administrator</option> <option value="Scholar">Scholar</option> <option value="External student">External student</option> <option value="Thesis">Thesis</option> <option value="Voluntary">Voluntary</option> </select> </td> <td> <select class="form-control" name="Sport[]" style="width:150px" /> <option value="">Select</option> <option value="Football">Football</option> <option value="Baseball">Baseball</option> <option value="Swimming">Swimming</option> <option value="Horse riding">Horse riding</option> <option value="basketball">basketball</option> </select> </td> <td class="Delete">Delete</td> </tr> </tbody> </table> <input type="button" id="add" value="+ add student" class="btn btn-primary"/> </div> </div> </div> my db.table is like this id | name | mode | sport | idstudent_fk And Im using an algorithm to read the array and every time can save every row, but im usind PDO and im having problems try{ here i insert data in a table here i got the last id from that table then ... if($_POST['name']!="" and $_POST['mode']!="" and $_POST['sport']!=""){ if(is_array($_POST['name'])){ while(list($key, $name) = each($_POST['name']) and list($val,$mode) = each($_POST['mode']) and list($id, $sport) = each($_POST['sport'])){ $sql = "INSERT INTO sports(id_studentfk, mode_stu, sport, id_projfk) values(:value, :mode, :sport, :lastid)"; $statement = $connect ->prepare($sql); $statement -> bindParam(':name', $name, PDO::PARAM_INT); $statement -> bindParam(':mode', $mode, PDO::PARAM_STR); $statement -> bindParam(':sport', $sport, PDO::PARAM_STR); $statement -> bindParam(':lastid', $lastid, PDO::PARAM_INT); $pdoExec = $statement -> execute(); } }//end if array }//end if post } catch (PDOException $e) { print 'ERROR: '. $e->getMessage(); print '<br/>Data Not Inserted'; } the idea is creating a loop to read the array and every time can insert data. Im using PDO this time is not working, im geeting this error
ERROR: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined I hope someone can help me to solve this
Hey all.. I'm trying to pick up PHP by reading ebooks and follow tutorials. I am now busy with creating a thumbnailgallery from uploaded pics per user. I want to let the visitor scroll through a row of thumbnails by clicking next or previous. There are 3 different rows of thumbnails. Here's how it looks like: <<previous (row1 of 6thumbnails) next>> <<previous (row2 of 6thumbnails) next>> <<previous (row3..... ) next>> when page loads mysql fetches rows of information for the filenames...then there is a foreach row loop that does first a do ..while loop to build up the thumbnailrows...and then creates the navigation links previous and next who send the "page"+1 or "page"-1 to _GET array so that the thumbnail 7 until 12 will be shown. The problem i run into is that i want the main code page to remember at which "page" of scrolling through the thumnails he is. Now it is that when a user scrolls one row of thumbnails and stops at the 3rd "page" of it and then clicks on a different row to go to "page" 2 of that row that all the rows jump together back to "page" 1. I thought there may be a solution in storing the number of row and the number of page into an array but can't seem to find a solution.... Has anybody got experience in this? Help would be very welcome i'm totally stuck and cant read about it in tutorials/ebooks.... greets from holland.. GJ Hey guys! I have the following script to create an excel file, the thing is that I dont want to be asked if I want to open or save the file when accessing the php file...I just want the php file directly to save the excel file. Heres the code: $filename = "test.xls"; $contents = "testdata1 \ntestdata2 \ntestdata3 \n"; header('Content-type: application/vnd.ms-excel'); header('Content-Disposition: attachment; filename='.$filename); echo $contents; Is there a way instead of using the header function, use something like: fopen, fwrite, fclose ? Thanks in advance! Cheers, $new_relation->save(); echo "after save".$requestor_profile->getId()." ".$requestee_profile->getId(); return true; }catch(PropelException $e) { echo "in die"; die($e); return false; } }//end - if (!$res) [/PHP] the echo after the save executes but when i look in my db table there is nothing???? please help??? test.php Code: [Select] <?php setcookie("test", 'tester', time()+3600*24*30 , "/", ".mystagingsite1.com"); header('Location: test2.php'); ?> test2.php Code: [Select] <?php echo '<pre>'; print_r($_COOKIE); echo '</pre>'; ?> This does not work. It's not setting the cookie at all. Is there something I am doing wrong here? Hi, I want to save an webpage into my server location, as simple as that. At present, I am reading the content of the file using curl, save that content into a text file, then save that text file. I assume there must be some straightforward way just to save www.example.com/file.html into my server directory as file.html. Can anyone help me on this, please? Thanks, -Abd I have a button that brings up my systems printer....
<button onClick="window.print()">Print this page</button>I'm trying to find a way to do the same thing but giving me the ability to save-as to my CPU. What would be nice is if I could have separate buttons to save-as a PDF and one for CSV. Each would automatically save to a file, with a comfirmation that its saved. The location would be coded in PHP for the desired format, and all the user has to do is click the button and it is placed in the appropriate folded. is this possible and easy to do across ie, firefox and chrome? Thanks for any direction. . Edited by Butterbean, 15 January 2015 - 12:09 AM. What is the best way to capture items that someone wants to purchase when they don't have an account yet? And I prefer not using cookies.
I want to save files to a directory. I am using a input type="text" to let user paste directory, then they choose the file from an upload form, then press submit. So here is my script: ============== <form method="post" action="" enctype=...> <input type="text" name="textboxDir" /> <input type="file" name="uploadedFile"/> </form> So how do I now save the uploaded file via $_POST['uploadedFile'] to the text box directory: $_POST["textBoxDir"]? Any help much appreciated! Im trying to use a cropping feature but when the image is cropped the alpha channel is lost. Anyone know where im going wrong here? if($ext == 'png') { $srcImg = imagecreatefrompng('avatars/'.$original); $newImg = imagecreatetruecolor($width, $height); imagealphablending($srcImg, true); imagesavealpha($srcImg, true); imagecopyresampled($newImg, $srcImg, 0, 0, $x1, $y1, $width, $height, $width, $height); imagepng($newImg, 'avatars/'.$user_name.'_avatar_cropped.png'); $link->query("UPDATE ".TBL_PREFIX."users SET u_avatar_cropped = '".$user_name."_avatar_cropped.png' WHERE u_username = '$user_name'") or die(print_link_error()); } Hello, I'm editing an XML file using PHP, the XML file contains a playlist of songs for a flash mp3 player. Now I'm able to edit the XML file, but I'm not able to save it . Here's my code: $random_speed = mt_rand(1,15); // Discspeed $song_title = /*mysql_real_escape_string($_GET['song_title'])*/ "My First XML Edit"; $song_artist = /*mysql_real_escape_string($_GET['song_artits'])*/ "A great author"; $song_filename = /*basename(mysql_real_escape_string($_GET['song_filename']))*/ "myfirstxmledit.mp3"; /* Open image directory and get a random image name */ $dir = "./img"; /* Scan the directory and put everything in an array */ $files = scandir($dir); /* Count the elements in the array */ $count_array = count($files); /* Pick a random index from the array */ $rand_array = array_rand( $files, 1 ); /* Pick the value of the random index */ $random_image = $files[$rand_array]; /* Loop through array and if element is not equal to "." or ".." then set the random_image variable */ if( ($random_image == "." ) || ($random_image == ".." ) ){ while( ($random_image == "." ) || ($random_image == ".." ) ){ $random_image = $files[$rand_array]; } }elseif( ($random_image != "." ) || ($random_image != ".." ) ){ echo $random_image; } /* Open the music.xml file */ $xml = new DOMDocument('1.0', 'utf-8'); $xml->formatOutput = true; $xml->preserveWhiteSpace = false; $xml->load('music.xml'); /* Begin settin new element to music.xml file */ $newItem = $xml->createElement('song'); $newItem->appendChild($xml->createElement('title', "'$song_title'")); $newItem->appendChild($xml->createElement('artist', "'$song_artist'")); $newItem->appendChild($xml->createElement('url', "songs/'$song_filename'")); $newItem->appendChild($xml->createElement('image', "img/'$random_image'")); $newItem->appendChild($xml->createElement('discspeed', $random_speed)); /* Add the new elements to the xml tag 'song' */ $xml->getElementsByTagName('song')->item(0)->appendChild($newItem); /* Save the xml file */ $xml->save(); I've tried to enter the filename in the last $xml->save() function, didn't work, added the location + filename, didn't work ... Anyone knows what or how do I save the file? Thanks! hi all, i'm trying to save an image after cropping it using jcrop (jquery plugin). i'm currently using a script i found on the internet called ImageManipulation.php (attached). its working fine, but i get a black image if i crop a gif, or png images (works great for jpg images). Code: [Select] $objImage = new ImageManipulation("../products/" . $_SESSION['image']); if ($objImage->imageok) { // get x, y, w, h from hidden inputs that are update by jcrop $objImage->setCrop($_POST['x'], $_POST['y'], $_POST['w'], $_POST['h']); $objImage->resize(150); $objImage->save("../products/" . $_SESSION['image']); } how can i fix this?? if you have a better way of using php with jcrop to save cropped images please share it thanks for the help this is the script it is supposed to get the image url and file name from the address bar and then save the image in the pics folder. it doesn't work and there are no errors, i have never used curl before so i don't know what i am doing. the $img is commented out because i don't know how to add it into the code. <?php $url = $_GET["url"]; //$img = $_GET["fileName"]; $fullpath = "/hermes/bosweb/web230/b2302/ipg.account/test_server/pics"; function save_image($url,$fullpath){ $ch = curl_init ($url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); if(file_exists($fullpath)){ unlink($fullpath); } $fp = fopen($fullpath,'x'); fwrite($fp, $rawdata); fclose($fp); } ?> this is was the end of the url looks like Code: [Select] save.php?url=http%3A%2F%2Fapi10.webresizer.com%2Fresizer%2Fdisplay.cgi%3Fsession%3DLO7WC4zoiw1z4pLFMIjK1dps3Q9HKP%26from%3Dresult.jpg%26type%3Djpg&filetype=jpg&filename=Group.jpg&filesize=39.07&width=385&height=289 Hi. I have a sort of security script which checks a few things, how can i save the url of the link that was clicked, so i can pass it through the script then if all is good, continue on to the url, if not send them somewhere else let me try to explain better with a little text picture user clicks link ----------------------> link goes to my security script --------------------> if the check passes, continue to original links url so basically i just need to know how to save the links url as a variable this script saves the image from a url to the folder were this script is saved, how can i make this code save images into specific folder such as "/image/poster_image/" <?php $img[]='http://images.rottentomatoescdn.com/images/redesign/poster_default.gif'; foreach($img as $i){ echo $i; save_image($i); // if(getimagesize(basename($i))){ // echo '<h3 style="color: green;">Image ' . basename($i) . ' Downloaded OK</h3>'; // }else{ // echo '<h3 style="color: red;">Image ' . basename($i) . ' Download Failed</h3>'; // } } //Alternative Image Saving Using cURL seeing as allow_url_fopen is disabled - bummer function save_image($img,$fullpath='basename'){ if($fullpath=='basename'){ $fullpath = basename($img); } $ch = curl_init ($img); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_BINARYTRANSFER,1); $rawdata=curl_exec($ch); curl_close ($ch); if(file_exists($fullpath)){ unlink($fullpath); } $fp = fopen($fullpath,'x'); fwrite($fp, $rawdata); fclose($fp); } ?> I have this code header("Content-type: text/xml"); $database = "rprice"; $linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); mysql_select_db($database, $linkID) or die("Could not find database."); $query = "SELECT * FROM plist ORDER BY date DESC"; $resultID = mysql_query($query, $linkID) or die("Data not found."); $xml_output = "<?xml version=\"1.0\"?>\n"; $xml_output .= "<graph>\n"; for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){ $row = mysql_fetch_assoc($resultID); $xml_output .= "\t<set date =\"" . $row['date'] . "\" value =\"" . $row['sprice'] . "\">\n"; $xml_output .= "\t</set>\n"; } $xml_output .= "</graph>"; echo $xml_output; I want to save this xml file into the folder name Data what is the code of that please help I have html form and verify post data via pgp how can I save someone data if some one fill incorrect information Hi I have a javascript image cropping script which is working well, I then have some php to save the new cropped image. But I can't seem to get it working 100%. When the form is posted the cropped image is not created and I get a "The connection was reset" error. If I comment out the line Code: [Select] $source=imagecreatefromjpeg($image); then I dont get the The connection was reset" error but the image is obviously still not created. Can anyone help? Code: [Select] <?php function resizeThumbnailImage($thumb_image_name, $image, $width, $height, $start_width, $start_height, $scale){ list($imagewidth, $imageheight, $imageType) = getimagesize($image); $imageType = 'image/jpeg'; $newImageWidth = ceil($width * $scale); $newImageHeight = ceil($height * $scale); $newImage = imagecreatetruecolor($newImageWidth,$newImageHeight); switch($imageType) { case "image/jpeg": case "image/jpg": $source=imagecreatefromjpeg($image); break; } imagecopyresampled($newImage,$source,0,0,$start_width,$start_height,$newImageWidth,$newImageHeight,$width,$height); switch($imageType) { case "image/jpeg": case "image/jpg": imagejpeg($newImage,$thumb_image_name,90); break; } chmod($thumb_image_name, 0777); return $thumb_image_name; } function getHeight($image) { $size = getimagesize($image); $height = $size[1]; return $height; } function getWidth($image) { $size = getimagesize($image); $width = $size[0]; return $width; } $large_image_location = $upload_path.$large_image_name.'.jpg'; $thumb_image_location = $upload_path.$thumb_image_name.'.jpg'; if (isset($_POST["upload_thumbnail"])) { $x1 = $_POST["x1"]; $y1 = $_POST["y1"]; $x2 = $_POST["x2"]; $y2 = $_POST["y2"]; $w = $_POST["w"]; $h = $_POST["h"]; $scale = $thumb_width/$w; $cropped = resizeThumbnailImage($thumb_image_location, $large_image_location,$w,$h,$x1,$y1,$scale); header("location:index.php"); exit(); } ?> |