Jump to content

richiejones24

Members
  • Posts

    55
  • Joined

  • Last visited

Posts posted by richiejones24

  1. I am having problems displaying individual data I am using  $filename[0] to display the first data, any ideas where i am going wrong. 

     

    
    
    
    <?php
    
    $active_keys = array();
    foreach($_POST['img'] as $key => $filename)
    {
        if(!empty($filename))
        {
            $active_keys[] = $key;
        }
    
    echo "". $filename[1];
    }
    
    
    
    
    
    ?>
    

  2. I've tried changing my form to this, but its still not working  :(

     

    <!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>Untitled Document</title>

    </head>

     

    <body>

    <form id="form1" name="form1" method="post" action="testd.php">

      <p>

        <label>

    <input type="text" name="img[]"><br>

    <input type="text" name="img[]"><br>

    <input type="text" name="img[]"><br>

    <input type="text" name="img[]"><br>

    <input type="text" name="img[]"><br>

        <label>

          <input type="submit" name="Submit" id="Submit" value="Submit" />

        </label>

      </p>

    </form>

    </body>

    </html>

     

     

    but i still keep getting the following error:

     

    Warning: Invalid argument supplied for foreach() in /homepages/22/d378569747/htdocs/testd.php on line 4

     

  3. ye this is the form i am going to use

     

     

    <!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>Untitled Document</title>

    </head>

     

    <body>

    <form id="form1" name="form1" method="post" action="">

      <p>

        <label>

          <input type="text" name="img[]" id="img[]" />

        </label>

      </p>

      <p>

        <input type="text" name="img2[]" id="img2[]" />

      </p>

      <p>

        <input type="text" name="img3[]" id="img3[]  " />

        <label>

          <input type="submit" name="Submit" id="Submit" value="Submit" />

        </label>

      </p>

    </form>

    </body>

    </html>

     

     

     

     

  4. I am trying my hand at using an array i have never done it before, and I am having some problems getting it work work. if someone could point me in the right direction?

     

    Thanks

    
    
    <?php
    
    $active_keys = array();
    foreach($_GET['img'] as $key => $filename)
    {
        if(!empty($filename))
        {
            $active_keys[] = $key;
        }
    }
    
    
    
    ?>
    
    

  5. The script below used to work fine but the HTTP_REFERER was unreliable so i added a re-direct if the HTTP_REFERER was unavailable and now nothing is being added to the MySQL BD, the script runs ok ie it sends the user back to where they come from, any ideas what could be wrong? 

     

    
    <?php
    require("../include/mysqldb.php");
    $uinwish = $_GET['uinwish'];
    $wishrefer = $_SERVER['HTTP_REFERER'];
    $wishdate  = mktime(0, 0, 0, date("m"), date("d")+3, date("Y"));
    $rand_wish_cookie = $_COOKIE["wishtracking"];
    
    $con = mysql_connect("$dbhost","$dbuser","$dbpass");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("$dbame", $con);
    
    //DB Stuff start code below
    
    //check if the uin and cookie have already been stored together.
    $sql = "select * from Wish_list_guest where usercookie='$rand_wish_cookie' and uinwish='$uinwish'";
    $result = mysql_query($sql);
    
    
    $row = mysql_fetch_row($result);
    if (mysql_num_rows($result)!= 1) {
    
    $issetvar = "1";
    
    if (!isset ($wishrefer)){
    
    $host  = $_SERVER['HTTP_HOST'];
    $extra = 'profile.php?uin=';
    header("Location: http://$host/$extra$uinwish");
    exit;
    }
    
    if (isset ($wishrefer)){
    
    header("Location: $wishrefer");
    exit;
    }
    }
    
    if ($issetvar = 1) {
    
    mysql_query("INSERT INTO Wish_list_guest (usercookie, date_delete, uinwish, referwish)
    VALUES ('$rand_wish_cookie', '$wishdate', '$uinwish', '$wishrefer')");
    
    mysql_close($con);
    
    
    if (!isset ($wishrefer)){
    
    $host  = $_SERVER['HTTP_HOST'];
    $extra = 'profile.php?uin=';
    header("Location: http://$host/$extra$uinwish");
    exit;
    }
    
    if (isset ($wishrefer)){
    
    header("Location: $wishrefer");
    exit;
    }
    }
    
    
    ?>
    

  6. hello, might be a stupid question but can you put an if and else inside of if brackets like i have done in this script?

    
    <?php
    require("../include/mysqldb.php");
    $uinwish = $_GET['uinwish'];
    $wishrefer = $_SERVER["HTTP_referer"];
    $wishdate  = mktime(0, 0, 0, date("m"), date("d")+3, date("Y"));
    $rand_wish_cookie = $_COOKIE["wishtracking"];
    
    $con = mysql_connect("$dbhost","$dbuser","$dbpass");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("$dbame", $con);
    
    
    $sql = "select * from Wish_list_guest where usercookie='$rand_wish_cookie' and uinwish='$uinwish'";     //search db has the profile already been added to favorites
    $result = mysql_query($sql);
    
    
    $row = mysql_fetch_row($result);
    if (mysql_num_rows($result)!= 1) {    //if 1 of more results found profile already added redirect back!
    
    
    //Re-direct back script!!
    if (!isset ($wishrefer)){
    
    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'profile.php?uin=';
    header("Location: http://$host/$extra$uinwish");
    exit;
    
    }
    
    
    else { header("Location: $wishrefer");
    exit;
    }
    
    //end redirect script
    
    else {
    
    mysql_query("INSERT INTO Wish_list_guest (usercookie, date_delete, uinwish, referwish)
    VALUES ('$rand_wish_cookie', '$wishdate', '$uinwish', '$wishrefer')");
    
    
    mysql_close($con);
    
    }
    
    if (!isset ($wishrefer)){
    
    $host  = $_SERVER['HTTP_HOST'];
    $uri   = rtrim(dirname($_SERVER['PHP_SELF']), '/\\');
    $extra = 'profile.php?uin=';
    header("Location: http://$host/$extra$uinwish");
    exit;
    
    }
    
    
    else {
    header('Location: $wishrefer');
    exit;
    
    }
    
    
    ?>
    

  7. need a little help guys! I use the script below to display profile images, trouble is it shows 1 on top of the other, and i need it to double up 2 profile images on top of 2 profile images ect any ideas how i can do this. 

     

    
    require("./include/mysqldb.php");
    
    $con = mysql_connect("$dbhost","$dbuser","$dbpass");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("$dbame", $con);
    $result = mysql_query("SELECT * FROM Search_profiles_up WHERE upgrade_one ='1' ORDER BY RAND() LIMIT 40");
    
    
    print "<table width=\"293\" height=\"111\" border=\"0\">
      <tr>\n";
    
    while($row = mysql_fetch_array($result))
      {
    print "<td width=\"142\"><img src=" . $row['search_small_image'] . " width=\"144\" height=\"169\" /></td>\n";
    print "  </tr>\n";
    print "  <tr>  \n";
    print "<td>" . $row['star'] . "</td>\n";
    print "  </tr>\n";
    print "  <tr>\n";
    print "<td>" . $row['username_search'] . "</td>\n";
    print "  </tr>\n";
    print "  <tr>  \n";
    print "<td>" . $row['phone_search'] . "</td>\n";
    print "  </tr>   \n";
    
      }
    print "</table>";
    
    mysql_close($con);
    ?>
    
    
    

  8. Why would you make a 2nd table, when you could just add a status column to the users table to indicate whether they are "upgrade" users?

    Its complicated but i cant do that it has to run on its own table.

     

    What exactly is complicated?

     

    The User profiles are spread over 5 tables and i use  MySql Join and the username to pull all the information from the tables to make the profile. If i added the upgrade option to one of the tables all i would be able to to is get the information from that table which would be useless i need the username to get the rest of the profile from the different tables.

  9. Something like this?

     

    
    $query1 = mysql_query("SELECT key FROM db1 WHERE something = 'something'") or die(mysql_error());
    
    if( mysql_num_rows($query1) >= 1 ) {
    
       while( $row = mysql_fetch_array($query1) ) {
          $searchKey = $row['key'];
       }
    
       $query2 = mysql_query("SELECT key FROM db2 WHERE something = '$searchKey'") or die(mysql_error());
    
    } else { 
    
       echo "nothing found";
    
    }
    
    

     

    Thanks For the Reply!

    This is not exactly what i need as the original search will bring multiple results (user names) so the second search I need it to do something like this ("SELECT key FROM db2 WHERE something = '$searchKey' OR something = '$searchKey' OR something = '$searchKey' OR something = '$searchKey'  ")

     

    in some kind of array ive tried using "WHILE" and "FOREACH" but i cant figure out how to do it or whether it can be done.   

  10. Thanks for your reply's, let me clarify what i am trying to do, I have a dating site and i have added the option to upgrade your profile so it is displayed on the homepage so I have created a new MySql table with the users username and the upgrade options they have selected. so what i won't to do is search the upgrade table (SELECT * FROM upgrade WHERE upgrade_one = '1') which will give me all the user names of all the user who have upgraded, then i won't to search the user table with the username (i got from the first search) to pull there profiles of the upgraded users.       

  11. I am trying to get the code at the bottom of the script to print just once during the loop but it either doesn't print at all or repeats with the loop im am using if (!$i++) to print once and i works the first time i use it.

     

     
    foreach($uploadFilename as $key => $myvar)
    {
    if (!$i++) print "<!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>Upload Complete....</title>
    </head>
    
    <body>
    
    <body onload=\"document.forms.formname.submit);\">
    
    <form id=\"formname\" name=\"form1\" method=\"post\" action=\"reg5.php\">\n";
    
    
    echo "<input type=\"hidden\" name=\"image$key\" value=\"";
    echo end(explode('/',$myvar));
    echo "\">\n";
    
    if (!$i++) print "</form>
    </body>
    </html>\n";
    
    
    }
    

  12. I am trying to write a script to handle multiple image uploads however i cant get it to work i am a total novice in php so please be kind in your replys :-)

     

    <?php

     

    $allowed_filetypes = array('.jpg','.gif','.bmp','.png','.JPG','.PNG','.BMP','.GIF'); //These will be the types of file that will pass the validation.

    $upload_path = '../pic_upload/'; // The place the files will be uploaded to.

     

    foreach ($_FILES["pictures"]["error"] as $key => $error)

    {

    $filename = $_FILES['pictures']['name'][$key];

    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);

     

    if(!empty($filename))        //is it empty

    {

    if ($_FILES["pictures"]["size"][$key] >= 9000000)

    die ('Sorry the picture is too Big!');

    }

     

    if(!empty($filename))        //Is it empty

    {

    if(!in_array($ext,$allowed_filetypes))                                          //Is the file Allowed

          die('The file you attempted to upload is not allowed! Pictures only!.');

    }

     

    if ($error == UPLOAD_ERR_OK) {

            $tmp_name = $_FILES["pictures"]["tmp_name"][$key];

            $name = $_FILES["pictures"]["name"][$key];

            move_uploaded_file($tmp_name, "$upload_path/$ran$name");

     

    if (!$i++) print "<!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>Untitled Document</title>

    </head>

     

    <body>

    <div align=\"center\"><img src=\".../image/8-1.gif\" width=\"100\" height=\"100\" /></div>

    <form id=\"form1\" name=\"form1\" method=\"get\" action=\"reg.php\">

    <div align=\"center\">

            <input type=\"submit\" name=\"button\" id=\"button\" value=\"Submit\" />

            <input type=\"hidden\" name=\"reg\" value=\"6\">

      <p>\n";

     

    print "<input type=\"hidden\" name=\"pic$key\" value=\"$ran$name\">\n";

     

     

    if (!$i++) print "</p>

      <p>

        <label>

          </div>

        </label>

      </p>

    </form>

    <p> </p>

    </body>

    </html>\n";

     

    } }

    ?> 

    [code=php:0]

  13. The following is the basis for the code you are using (gotten from the php.net documentation.) You would put your application level validation logic inside the if(){...} statement, because you can only access and check the uploaded file information when the file was actually uploaded without any errors -

     

    <?php
    foreach ($_FILES["pictures"]["error"] as $key => $error) {
        if ($error == UPLOAD_ERR_OK) {
            $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
            $name = $_FILES["pictures"]["name"][$key];
            move_uploaded_file($tmp_name, "data/$name");
        }
    }
    ?>

     

    The code you have now makes no sense.

     

    Totally Confused now :-s

     

    The code works and uploads the files ok however, the script is for multiple file upload and if the user uploads a file to form field 3 for example and form field 1 is left empty the script dies and no files are uploaded i belive it is this part that is killing it

       if (empty($filename)) {                                                       //Is the field empty
        die ('one of the fields is empty but the rest have been upload');
    }
    

     

    any ideas how to get round this?

  14. Total Nood to PHP trying to write a multiple image upload script, however having problem as the image validation kills the script and it wont upload any ideas?

     

    $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); //These will be the types of file that will pass the validation.
    $upload_path = '../pic_upload/'; // The place the files will be uploaded to.
    
    foreach ($_FILES["pictures"]["error"] as $key => $error)
    
    {
    
    $filename = $_FILES['pictures']['name'][$key];
    $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1);
    
    if ($_FILES["pictures"]["size"][$key] >= 700000) {      //Check the Size
       die ('size to big');
    }
    
    if (empty($filename)) {                                                       //Is the field empty
        die ('one of the fields is empty but the rest have been upload');
    }
    
    if(!in_array($ext,$allowed_filetypes))                                           //Is the file Allowed
          die('The file you attempted to upload is not allowed.');
    
    if ($error == UPLOAD_ERR_OK) {                                                  //Upload File check for errors
           echo"$error_codes[$error]";
           move_uploaded_file($_FILES["pictures"]["tmp_name"][$key],$upload_path . $_FILES["pictures"]["name"][$key]) or die("Problems with upload");
       }
    
    

     

    MOD EDIT: code tags added.

×
×
  • 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.