Jump to content

a0101

New Members
  • Posts

    9
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

a0101's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I want to retrieve the input from the textarea from another page. Similar to the purpose of e.g <input type="text" name="subject" value="My text here"> where I can retrieve it from another page by $subject=$_POST['subject']; but I can't use <textarea name="subject">My text here</textarea> or even <textarea name="subject" value="My text here"></textarea>, so how do I do it through html?
  2. Hi, I want to allow users to upload images onto my website. When the image file is uploaded to the website, I would store the file location in an array and then display it by using its directory. It seems that I have a problem with the code as the file doesn't get uploaded when I ran the code. <p align="left"><label for="file">Upload image:</label> <input type="file" name="file" id="file" /></p> <?php if(isset($file)){ $file = $_POST['file']; 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 "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; move_uploaded_file($_FILES["file"]["tmp_name"], images); // image folder is in root directory echo "Stored in: " . "images/" . $_FILES["file"]["name"]; } } } ?> Also, I'm not sure if the array part of my code is correct but here it is: <?php //fileone.php $array = ("images/". . $_FILES["file"]["name"]); $session_start(); $_SESSION['array'] = $array; ?> <?php //filetwo.php $session_start(); echo '<img src="'.$_SESSION['array'][0].'" />'; ?> Note that I want to display the image in filetwo.php.
  3. I didn't use shuffle as I want my array to store values from the 100th position. So basically, array[0] -> array[99] are empty. I have a problem which is I am unable to capture the random number upon validation of the form. When I generate a random number say: $rand = rand(100,999); I want to be able to echo the same random number, instead when I submit the form, my code generates another random number. I can't use another variable to store the random number as again $storage = $rand; when I submit the form, $storage will also be the new random number instead of the old one. Is there any way to capture the random number?
  4. Hi, I need to generate a random array that stores various values. For example, <form action="testscript.php" method="POST"> Value1:<input type = "text" name="value1"> Value2:<input type = "text" name="value2"> <?php $valueone = $_POST['value1']; $valuetwo = $_POST['value2']; $number = random(1,10); //random value for array $array[$number] = array($valueone,$valuetwo); //each array number is unique ?> <input type="submit" name="submit"> </form> However, I need to make it such that if an array already has values stored in it, it moves on to another random array until it finds an empty one. Also, since I would need to validate the form, I will require the random array number to remain the same upon submission of the form. I've tried using a for loop: for($i=0; $i<1000; $i++){ if(isset($array[$number])){ //if the array is set, since $number is unique, generate new array by randoming another number $number = random(1,10); //random another value for array } $i++; } but it doesn't seem to work the way I want it to.
  5. Works perfectly fine now, thanks!
  6. Thanks! Didn't know about the sessions function before. However, I would like to echo a value of an array, through its position within the array. So what I've done is basically: Webpage A session_start(); $_SESSION['fruits'] = $fruits; $fruits = array('apple', 'banana', 'pear'); Webpage B session_start(); echo $_SESSION['fruits'][3]; It doesn't give me the value of pear but a string offset error, so how should I go about doing this?
  7. Hi, so for example I created a variable in webpage A, $x = array(A,B,C) . And I want use the values of the array in webpage B, is there any way to make the variable 'global' so that when I print_r $x in webpage B, it will read the values that I stored in webpage A?
  8. Thanks for such a fast reply! Is it possible to insert a large amount of numbers (say 10000) into the array or would it take up too much memory? Really appreciate your help
  9. Hello, I want to generate random numbers and insert them into an array. Here is my code: <p class="input">Speech ID: <input type="text" readonly value=" <?php $arra = array(); for($i = 0; $i < 99999; $i++){ $arra($i) = rand(100000, 999999); } $speechidarr = array_unique($arra); foreach ($speechidarr as $speechID) { echo $speechID; ?> /> My code gets a fatal error apparently: Fatal error: Can't use function return value in write context
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.