Jump to content

sabadell

New Members
  • Posts

    7
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sabadell's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. "SELECT Date, IP, COUNT(*) AS datecount FROM UserRecords WHERE Date='$dte' GROUP BY Date"); This is how it works......... SELECT DISTINCT "column_name" FROM "table_name" The column name in your case to shown only unique records would be IP i.e. SELECT DISTINCT (from your table) .`the column you want to be distinctive about` and then the rest of the SQL. Below is an example $query_Recordset1 = "SELECT DISTINCT mytable.`mydistinctcolumn`, mytable.Anothercolumn, mytable.AnotherColumn2  FROM mytable ";
  2. HI thanks for your help but I don't think I can use it I need to keep the database structure as it is and so it doesn't really solve the problem. Once again it is merely a question of taking out the values as are displayed with this code....... [code] <?php foreach($_FILES as $file_name => $file_array) {     echo $file_array['name']."<br>\n"; } ?> When I have tried to print out separate parts of the array such as the second (out of a possible four) it will just print out a letter of the name of the last file uploaded. (This is explained in the earlier posted details.) So what i would like to do is split the array and allocate them to variables or any suggestion that allows me to input each file name which has been uploaded in a column in the mysql database. eg. $Var1 into photo1 , $var2 into photo2 etc. Hope someone can help!  [/code]
  3. sabadell

    PHP Session

    Hi,Although I haven't done this with PHP I believe my experience of ASP will help in terms of the thought process. As such, I think you would need a cookie for this type of activity i.e. a cookie has longer time limits potential than a session and then an if else structure to redirect visitorsif the cookie has expired. I am sure others will offer more script advice though but I hope it will help.
  4. Hi I am working on a PHP script to upload files to the server and write the names in a mysql dbase. The upload script always works and when using a single file upload I get it to write the file name into the dbase. With multiple uploads I have been reading the manual and can't work out how to split the array values as  want to then allocated them to variable names to then insert into individual columns in the dbase. If I try : [code] <?php foreach($_FILES as $file_name => $file_array) {     echo $file_array['name']."<br>\n"; } ?> [/code] It prints out the whole list of file names stored in the array and if I try the following: [code] <?php foreach($_FILES as $file_name => $file_array) {     echo $file_array['name']."<br>\n"; }     echo $file_array['name'][2]."<br>\n"; ?> [/code] It will print out the list of file names held in the $file_array['name'] array and then the corresponding letter in the last file name uploaded which is held in the array. Iin this case the third one. As such want I need is to split the arrays and then give then variable names such as the following: $var1 = the first uploaded file name from the $var2 = the second uploaded file name etc etc. Any help would be appreciated. Full script below: regards [code] <html> <?php require_once('../../Connections/Punks_conn.php'); ?> <head> <title>form variable insert</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $name = $_POST[Firstname]; $surname =$_POST[Surname]; $group = $_POST[Group]; //folder creation using chmod change in permissions to 777 $file_dir = "../test7/uploads/"; if( !file_exists( $file_dir ) ) {   mkdir( $file_dir );   chmod( $file_dir, 0777 );                           } ?> <?php foreach($_FILES as $file_name => $file_array) {     echo "path: ".$file_array['tmp_name']."<br>\n";     echo "name: ".$file_array['name']."<br>\n";     echo "type: ".$file_array['type']."<br>\n";     echo "size: ".$file_array['size']."<br>\n";     if (is_uploaded_file($file_array['tmp_name'])) {         move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy");         echo "file was uploaded!<br><br>";     } } ?> <?php /* This prints out a list of the uploaded file names but I need to separate the names and give them variable names*/ foreach($_FILES as $file_name => $file_array) {     echo $file_array['name']."<br>\n"; }     echo $file_array['name'][2]."<br>\n"; ?> <?php // upload the form details mysql_select_db($database_Punks_conn, $Punks_conn); $sql = "INSERT INTO punks (FirstName, Surname, `Group`, Photo1, Photo2,Photo3,Photo4 ) VALUES ('$name','$surname','$group', '$photo1', '$photo2','$photo3','$photo4')"; //execute the SQL Statement if (mysql_query($sql, $Punks_conn)) { echo "new listing created"; } else { echo "This one never made it"; } //error identifier ?> </body> </html> [/code]
  5. [!--quoteo(post=387176:date=Jun 23 2006, 04:39 PM:name=Wildbug)--][div class=\'quotetop\']QUOTE(Wildbug @ Jun 23 2006, 04:39 PM) [snapback]387176[/snapback][/div][div class=\'quotemain\'][!--quotec--] It's in the PHP manual: [a href=\"http://www.php.net/manual/en/features.file-upload.php\" target=\"_blank\"]File uploads[/a]. Basically the $_FILES superglobal will contain the name(s) of the files being uploaded as well as the mimetype (image/gif or image/jpeg, etc). If you don't trust the reported mimetype or file extention, you can also check the file itself for the existence of the appropriate file header for that particular file format. I think jpegs start with "EXIF" and gifs start with "GIF8..." something. I can't recall off the top of my head; try Google if that interests you. [/quote] Thanks for your advice but as someone who is very new to php and mysql saying read the manual is a little bit throw away frankly as I assure you that I am slowly doing so albeit it is never an easy thing to read, digest and then use. Even when you began I am that you had the same experience after these forums wouldn't exist if this wasn't the case. So I would really appreciate a little bit of advice that is far more basic and explicit if you can. Thanks once again and I know that my issue is not a major one to most on this forum.
  6. Hi, I need a bit of help with a small project which is using PHP and MYSQL. Basically, I need to upload images to the server which I have done and also add an entry to a mysql database which I have also done. My problem is I don't know how to write the image name eg. MyPhoto.jpg to the dbase field photo1 that I have create in a table and also I need to be able to limit the types of uploaded files to jpg and gif extension. I hope it is quite straight forward and would appreciate any help from outthere! Thescripts I am using are as follows: Thanks in advance. Upload form............. <html> <head> <title>insert form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <p>Insert form for Rock Stars</p> <form action="formfileinsert.php" method="post" enctype="multipart/form-data" name="form1"> <table width="386" border="0" cellspacing="1" cellpadding="0"> <tr> <td width="73">Name</td> <td width="310"><input name="Firstname" type="text" id="Firstname"></td> </tr> <tr> <td>Surname</td> <td><input name="Surname" type="text" id="Surname"></td> </tr> <tr> <td>Group</td> <td><input name="Group" type="text" id="Group"> </td> </tr> <tr> <td>Photo</td> <td><input name="photo" type="file" id="photo"> <input type="submit" name="Submit" value="Submit"></td> </tr> </table> </form> <p>&nbsp; </p> </body> </html> ::::::::::::::::::The upload script:::::::::::::::::::::::::::::::::::::: <html> <?php require_once('../../Connections/Punks_conn.php'); ?> <head> <title>form variable insert</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $name = $_POST[Firstname]; $surname =$_POST[Surname]; $group = $_POST[Group]; $photo = $_POST[photo]; //folder creation - change in permissions to 777 Chmod $file_dir = "../test6/uploads/"; if( !file_exists( $file_dir ) ) { mkdir( $file_dir ); chmod( $file_dir, 0777 ); } ?> <?php foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array['tmp_name']."<br>\n"; echo "name: ".$file_array['name']."<br>\n"; echo "type: ".$file_array['type']."<br>\n"; echo "size: ".$file_array['size']."<br>\n"; if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy"); echo "file was uploaded!<br><br>"; } } ?> <?php // upload the form details mysql_select_db($database_Punks_conn, $Punks_conn); $sql = "INSERT INTO punks (FirstName, Surname, `Group`, Photo1) VALUES ('$name','$surname','$group', '$photo')"; //execute the SQL Statement if (mysql_query($sql, $Punks_conn)) { echo "new punk created"; } else { echo "This Punk never made it"; } //error identifier ?> </body> </html> Thanks for any help received
  7. Hi, I am new to PHP and am working on a very simple mysql driven site using PHP4 with apache2. So far I have managed to get the script to upload images into a individual session named folders due to the fact that the real site will have a high potential for images of the same name being uploaded The session name is actually the next available ID number from the dbase. As I have said this all works correctly. My problem is two fold:- 1. I have not been place the image name in the database nor any other info about it. 2. I have not been able to view the uploaded images at all and Dreamweaver is very little help. I believe that if I could get the photo name atleast into the database and then bring it down as a local level variable this may help me. And secondly the actually <img scr> path is not shown anything other than the dreaded small red cross! It should be something like: <img src="../test3/uploads/<?php $ID ?>/ I hope someone can help as it has frustrated me now for a few days so any help would be appreciated. I enclose scripts so far...... create.php...............upload.php........upload1.php ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: create.php ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: <?php session_start(); ?> <?php require_once('../../Connections/Punks_conn.php'); ?> <?php function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue; switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } $editFormAction = $HTTP_SERVER_VARS['PHP_SELF']; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING']; } if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) { $insertSQL = sprintf("INSERT INTO punks (FirstName, Surname, `Group`) VALUES (%s, %s, %s)", GetSQLValueString($HTTP_POST_VARS['FirstName'], "text"), GetSQLValueString($HTTP_POST_VARS['Surname'], "text"), GetSQLValueString($HTTP_POST_VARS['Group'], "text")); mysql_select_db($database_Punks_conn, $Punks_conn); $Result1 = mysql_query($insertSQL, $Punks_conn) or die(mysql_error()); $insertGoTo = "upload.php"; if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_Punks_conn, $Punks_conn); $query_Recordset1 = "SELECT Max(PropID)+1 FROM punks "; $Recordset1 = mysql_query($query_Recordset1, $Punks_conn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <body> <?php $_SESSION[mySession] = $row_Recordset1['Max(PropID)+1']; echo $_SESSION[mySession]; ?> <form method="post" name="form1" action="<?php echo $editFormAction; ?>"> <table align="center"> <tr valign="baseline"> <td nowrap align="right">First Name:</td> <td><input type="text" name="FirstName" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Surname:</td> <td><input type="text" name="Surname" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right">Group:</td> <td><input type="text" name="Group" value="" size="32"></td> </tr> <tr valign="baseline"> <td nowrap align="right"> </td> <td><input type="submit" value="Insert Record"></td> </tr> </table> <input type="hidden" name="MM_insert" value="form1"> </form> <p> </p> <p> </p> <p><br> </p> </body> </html> <?php mysql_free_result($Recordset1); ?> :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Upload.php :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: <?php session_start(); ?> <?php require_once('../../Connections/Punks_conn.php'); ?> <?php mysql_select_db($database_Punks_conn, $Punks_conn); $query_Recordset1 = "SELECT Max(PropID)-1 FROM punks "; $Recordset1 = mysql_query($query_Recordset1, $Punks_conn) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1);?> <html> <head> <title>upload.php</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php echo $_SESSION[mySession]-1; $ID = $_SESSION[mySession]-1; ?> <FORM ENCTYPE="multipart/form-data" ACTION="upload1.php" METHOD=POST> <p> Session No:<?php echo $_SESSION[mySession]-1;?> </p> <p>Upload this file: <INPUT NAME="file" TYPE="file" id="file"> <INPUT TYPE="submit" VALUE="Send File"> <input name="IDno" type="hidden" id="IDno" value="<?php echo $ID ?> "> </p> </FORM> <?php // if(!is_dir("../test3/uploads/".$ID)){//this line tests for the existance of a same named directory // mkdir("../test3/uploads/".$ID,0777); //global writing properties & trying to add on session ID value & $ID // return; // } ?> </body> </html> <?php mysql_free_result($Recordset1); ?> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: upload1.php :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: <?php session_start()?> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $ID = trim($_SESSION[mySession]-1); ?> <p><a href="create.php">Punk creator </a> <p>This is session number: <?php echo $_SESSION[mySession]-1;?> <p> <?php /* $file_dir = "../test3/uploads/$ID"; */ /* This upload works if the $ID is removed */ // this is the new line as suggested in codewalkers. //$file_dir = "../test3/uploads/$ID"; //if( !file_exists( $file_dir ) ) // mkdir( $file_dir ); //folder creation using chmod advice from codewalkers - change in permissions to 775 $file_dir = "../test3/uploads/$ID"; if( !file_exists( $file_dir ) ) { mkdir( $file_dir ); chmod( $file_dir, 0777 ); // 775 should be enough, I think. You can try 775 // and even 777 if this doesn't work. } ?> <?php foreach($_FILES as $file_name => $file_array) { echo "path: ".$file_array['tmp_name']."<br>\n"; echo "name: ".$file_array['name']."<br>\n"; echo "type: ".$file_array['type']."<br>\n"; echo "size: ".$file_array['size']."<br>\n"; if (is_uploaded_file($file_array['tmp_name'])) { move_uploaded_file($file_array['tmp_name'], "$file_dir/$file_array[name]") or die ("Couldn't copy"); echo "file was uploaded!<br><br>"; } } ?> <p> <p> </body> </html> ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: Displaying the image :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: I created $ID in the display as a local variable via... $ID = $row_Recordset1['PropID'] //PropID is ID number of dbase and individual upload folder name. The path to the pictures should I believe be something like.... <img src="../test3/uploads/<?php $ID ?>/ with $ID being the session named folder but this doesn't bring up an image. Thanks in advance for any help.
×
×
  • 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.