Jump to content

sandrine

Members
  • Posts

    15
  • Joined

  • Last visited

    Never

Everything posted by sandrine

  1. hi ok below is a php script which write some basic info to mysql which it gets from a html form users fill in which is also below. i have tried doing it myself with little effect basically i need to resize the image which the user uploads to 2 different sizes before saving them to the image folder and the mysql(to mysql just the name link not the actual image), 1 size about 400 x 200 and another size a thumbnail, also want to be able to resize and process any type of image extension i.e jpeg jpang gif etc........the form and php work fine at the moment when it comes to uploading and saving a image to my image folder and mysql. anyway hope some one can help oh yeah iam not being lazy i just cant fig this out iav tried high and low but not even the the great internet can help me on this one. The other thing i cant figure out is how to get a user to enter the password they entered when uploading/inserting a record, i know how to get the user to enter the password and i can get the password to be inserted into the mysql along with other user info but dont know how to get the user to enter the password when the user wants to edit/delete their record from the mysql. php script; <?php $password=$_POST['password']; $name=$_POST['name']; $date=$_POST['date']; define('DESTINATION_FOLDER','images/'); define('MAX_FILE_SIZE', 0); define('SUCCESS_URL',''); // Example: $exts = array('jpeg','mov','doc'); $exts = array(); define('RENAME_FILE', true); // sample strings: aaa, my, etc. define('APPEND_STRING', ''); define('DO_LOG', true); // MySql data (in case you want to save uploads log) define('DB_HOST',''); // host, usually localhost define('DB_DATABASE',''); // database name define('DB_USERNAME',''); // username define('DB_PASSWORD',''); // password @set_time_limit(172800); // ini_set("session.gc_maxlifetime","10800"); function showUploadForm($message='') { $max_file_size_tag = ''; if (MAX_FILE_SIZE > 0) { // convert to bytes $max_file_size_tag = "<input name='MAX_FILE_SIZE' value='".(MAX_FILE_SIZE*1024)."' type='hidden' >\n"; } // Load form template include ('file-upload.html'); } // errors list $errors = array(); $message = ''; // we should not exceed php.ini max file size $ini_maxsize = ini_get('upload_max_filesize'); if (!is_numeric($ini_maxsize)) { if (strpos($ini_maxsize, 'M') !== false) $ini_maxsize = intval($ini_maxsize)*1024*1024; elseif (strpos($ini_maxsize, 'K') !== false) $ini_maxsize = intval($ini_maxsize)*1024; elseif (strpos($ini_maxsize, 'G') !== false) $ini_maxsize = intval($ini_maxsize)*1024*1024*1024; } if ($ini_maxsize < MAX_FILE_SIZE*1024) { $errors[] = "Alert! Maximum upload file size in php.ini (upload_max_filesize) is less than script's MAX_FILE_SIZE"; } // show upload form if (!isset($_POST['submit'])) { showUploadForm(join('',$errors)); } // process file upload else { while(true) { // make sure destination folder exists if (!@file_exists(DESTINATION_FOLDER)) { $errors[] = "Destination folder does not exist or no permissions to see it."; break; } // check for upload errors $error_code = $_FILES['filename']['error']; if ($error_code != UPLOAD_ERR_OK) { switch($error_code) { case UPLOAD_ERR_INI_SIZE: // uploaded file exceeds the upload_max_filesize directive in php.ini $errors[] = "File is too big (1)."; break; case UPLOAD_ERR_FORM_SIZE: // uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form $errors[] = "File is too big (2)."; break; case UPLOAD_ERR_PARTIAL: // uploaded file was only partially uploaded. $errors[] = "Could not upload file (1)."; break; case UPLOAD_ERR_NO_FILE: // No file was uploaded $errors[] = "Could not upload file (2)."; break; case UPLOAD_ERR_NO_TMP_DIR: // Missing a temporary folder $errors[] = "Could not upload file (3)."; break; case UPLOAD_ERR_CANT_WRITE: // Failed to write file to disk $errors[] = "Could not upload file (4)."; break; case 8: // File upload stopped by extension $errors[] = "Could not upload file (5)."; break; } // switch // leave the while loop break; } // get file name (not including path) $filename = @basename($_FILES['filename']['name']); // filename of temp uploaded file $tmp_filename = $_FILES['filename']['tmp_name']; $file_ext = @strtolower(@strrchr($filename,".")); if (@strpos($file_ext,'.') === false) { // no dot? strange $errors[] = "Suspicious file name or could not determine file extension."; break; } $file_ext = @substr($file_ext, 1); // remove dot // check file type if needed if (count($exts)) { /// some day maybe check also $_FILES['user_file']['type'] if (!@in_array($file_ext, $exts)) { $errors[] = "Files of this type are not allowed for upload."; break; } } // destination filename, rename if set to $dest_filename = $filename; if (RENAME_FILE) { $dest_filename = md5(uniqid(rand(), true)) . '.' . $file_ext; } // append predefined string for safety $dest_filename = $dest_filename . APPEND_STRING; // get size $filesize = intval($_FILES["filename"]["size"]); // filesize($tmp_filename); // make sure file size is ok if (MAX_FILE_SIZE > 0 && MAX_FILE_SIZE*1024 < $filesize) { $errors[] = "File is too big (3)."; break; } if (!@move_uploaded_file($tmp_filename , DESTINATION_FOLDER . $dest_filename)) { $errors[] = "Could not upload file (6)."; break; } if (DO_LOG) { // Establish DB connection $link = @mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD); if (!$link) { $errors[] = "Could not connect to mysql."; break; } $res = @mysql_select_db(DB_DATABASE, $link); if (!$res) { $errors[] = "Could not select database."; break; } $m_ip = mysql_real_escape_string($_SERVER['REMOTE_ADDR']); $m_size = $filesize; $m_fname = mysql_real_escape_string($dest_filename); $sql = "insert into _uploads_log (password,date,name,log_filename,log_size,log_ip) values ('$password','$date','$name','$m_fname','$m_size','$m_ip')"; $res = @mysql_query($sql); if (!$res) { $errors[] = "Could not run query."; break; } @mysql_free_result($res); @mysql_close($link); } // if (DO_LOG) // redirect to upload success url header('Location: ' . SUCCESS_URL); die(); break; } // while(true) // Errors. Show upload form. $message = join('',$errors); showUploadForm($message); } ?> html upload form: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title></title> </head> <body> <table style="width: 100px; text-align: left; margin-left: auto; margin-right: auto;" border="4" cellpadding="2" cellspacing="2"> <tbody> <tr> <td style="text-align: center;"><?php // Variable for hours $hourdiff = "9"; // hours difference between server time and local time // Nothing needs to be changed below here unless you want to change // the format of the date (see above for URL of options) or your local // time is behind the server time $timeadjust = ($hourdiff * 3600); $melbdate = date("l, d F Y G:i a",time() + $timeadjust); print ("$melbdate"); ?></td> </tr> <tr> <td style="text-align: center;"> <form method="post" enctype="multipart/form-data" action="file-upload.php"> <div><?php echo $message; ?></div> <?php echo $max_file_size_tag; ?>Name: <input name="name" type="text"><br> Please select file to upload: <input size="20" name="filename" type="file"> <input name="date" value="<?php echo $melbdate; ?>" type="hidden"> <P>Password:<INPUT TYPE="password" NAME="password" VALUE="" SIZE="25"> <input value="Upload" name="submit" type="submit"> </form> </td> </tr> </tbody> </table> <br> </body> </html>
  2. ok i have tried doing that but can not figure out how i would include the date/time outputted by the php script into the hidden field before posting it along with the rest of form. xcuse my ignorance iam a newbie at this and yeah which forum should this be in anyway. thanx
  3. hi ok i know how to insert data into a mysql using forms and php scripts but i would like to insert date/time from a webpage on my site into mysql. The date/time are auto generated and displayed on my webpage via a php scipt that is running on the webpage. Is there a way to include the output of the date/time php script in the the rest of the form that follows it i.e so when users enter their name and a image and click upload the date/time will also be passed on to the php script that inserts the name/image into the mysql. just to recap i have a webpage with a form where users enter their name/image and click uplaod and the values get passed to a php script that inserts the values into mysql but i would like the date/time that is being displayed on the same page to be passed on to the insert php script aswell. i cant use the timestamp option in my mysql to auto generate the date/time as the server of mysql is in the usa and iam in the uk and so the date/time recorded is always wrong and as iam using a free host so i cant change the server time zone via .htaccess or php.ini or any other way till i upgrade and pay for hosting which i dnt want to do as iam just learning at the moment. below is the time.php script that generates and displays the date/time on my website and also below is the simple form script on the same page. hope some one can help. <?php $hourdiff = "14"; // hours difference between server time and local time $timeadjust = ($hourdiff * 3600); $melbdate = date("l, d F Y h:i a",time() + $timeadjust); print ("$melbdate"); ?> form script <form method="post" enctype="multipart/form-data" action="file-upload.php"> <div><?php echo $message; ?></div><?php echo $max_file_size_tag; ?> Name: <input name="name" type="text"><br> Please select file to upload: <input type="file" size="20" name="filename"> <input type="submit" value="Upload" name="submit"> </form>
  4. ok i figured it out you can change the time zone quite eqsily but i cant as iam on a free hosting so cant access .htaccess fully or php.ini at all. the server is in the usa and iam in the uk so i need to either upgrade and get paid hosting or find a free host based in the uk thanks for the help tho.
  5. when i insert some info into my mysql using a form on my website the date and time that are auto inserted into my database are wrong. the date is minus one day and the time is also many hours behind. iam using a form to get the info and a simlpe php script does the inserting into my database. can any one point me in the right direction thanks.
  6. prob solved i was not using uppercase for post
  7. hi everyone below are 3 scripts that i got of the internet. the purpose of the php scripts is to add data to mysql data base but it does not even when it says data added. i had the same prob with another php script so i got this new one thinking it was the script at fault but it seems not. can any one help pls. if i add data to the data base via mysql manually it all seems to be rosey but trying to insert data using the php scripts is not working even though the display script seems to work fine if there is data already in the data base. show data display script: <html> <head> <title>test php</title> <head> <body> <?php mysql_connect ("mysql6.000webhost.com", "a3848390_testuse", "sid503051") or die ('i cant conect to the database because: ' .mysql_error() ); mysql_select_db ("a3848390_test"); $query = mysql_query("SELECT * FROM testtable"); while ($row = mysql_fetch_array($query) ) { echo "<br /> id: " .$row['id']. "<br /> first name: " .$row['fname']. "<br /> lastname: " .$row['lname']."<br /> phone: " .$row['phone']. "<br />";} ?> </body> input form script: <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"> <title></title> </head> <body> <form method="post" action="update.php"> first name:<br /> <input type="text" name="fname" size"30" /><br /> last name:<br /> <input type="text" name="lname" size"30" /><br /> phone number:<br /> <input type="text" name="phon" size"12" /><br /> <input type="submit" name="update database" /> </form> <br> </body> </html> update.php the insert data script: <?php $fname = $_post['fname']; $lname = $_post['lname']; $phon = $_post['phon']; mysql_connect("mysql6.000webhost.com", "a3848390_testuse", "sid503051") or die ('error: ' . mysql_error()); mysql_select_db ("a3848390_test"); $query="INSERT INTO testtable (id, fname, lname, phon)VALUES('NULL' ,'".$fname."', '".$lname."','".$phon."')"; mysql_query($query) or die ('error'); echo "data updated with: " .$fname. " ".$lname. " ".$phon ; ?> one thing i have noticed is when you fill in some personal info on the input.php (input form script above) script and click "update database" i should be presented with a message saying for example "data updated with jo bloggs 0776958588" but i only get first part of the message i.e "data updated with" and not the other bit with the firstname last name phone num. hope sumone can help thanks. ???
  8. Thanks drak i checked the database table and guess What it had the records in it eg. record 1 record 2 etc.....but the data for the name and birthday is missing this despite the fact that when i run the following php code to generate a insert form where i insert a name and birthday ( sorry i know u said to use tags to make it easier to read i don't know what or how to do that) <html><head><title>Birthdays Insert Form</title> <style type="text/css"> td {font-family: tahoma, arial, verdana; font-size: 10pt } </style> </head> <body> <table width="300" cellpadding="5" cellspacing="0" border="2"> <tr align="center" valign="top"> <td align="left" colspan="1" rowspan="1" bgcolor="64b1ff"> <h3>Insert Record</h3> <form method="POST" action="birthdays_insert_record.php"> <? print "Enter name: <input type=text name=name size=20><br>\n"; print "Enter Birthday: <input type=text name=birthday size=10><br>\n"; print "<br>\n"; print "<input type=submit value=Submit><input type=reset>\n"; ?> </form> </td></tr></table> </body> </html>[/color] .....i click on submit on the form generated from the php code above and then i am presented with a message "record added" but when i check the mysql database only an additional record is added but not the actual information i.e name and the birthdate. below is the php code which is executed after the one above. its the php code that is supposed to insert the information into the data base <html><head><title>Birthdays Insert Record</title></head> <body> <? /* Change next two lines */ $db=""; $link = mysql_connect('', '', ''); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Select Error: ".mysql_error()); $result=mysql_query("INSERT INTO birthdays (name, birthday) VALUES ('$name','$birthday')")or die("Insert Error: ".mysql_error()); mysql_close($link); print "Record added\n"; ?> <form method="POST" action="birthdays_insert_form.php"> <input type="submit" value="Insert Another Record"> </form> <br> <form method="POST" action="birthdays_dbase_interface.php"> <input type="submit" value="Dbase Interface"> </form> </body> </html> but u were right when u said the code for displaying the information from mysql works fine but for somereason the php code above for adding the records is not adding the information to the mysql database. i am sorry if it all sounds a bit silly but maybe you can help i don't know.....anyways thanks
  9. sorry just to clarify when i click on the "show records" on my website the php code is executed and returns a message saying "there are x number of records" instead of WhATS actually in the records.
  10. thanks for the reply drak no my data base is not empty its just when i click on display record from data base the php code executes and returns the answer "there are x number of records" instead of wats actually in the records like the names and the birthdays. anyway i will recheck the database and insert the error code at the top like you suggested once again many thanks for a quick reponse theonlydrak.
  11. sorry forgot to include it its updated now
  12. hi i am new to this or any forum. i am a complete novice and need some help i am trying to get my php code to display all the data from a mysql but everytime i run the php code on my website i get "the number of record is x number" instead of the data from the mysql can anyone help below is the full php code i am using. to clarify i want all the data from the mysql and not how many record there are in mysql many thanks. <?php $db="a3205133_test"; $link = mysql_connect('xxxxxxxxxx', 'xxxxxxx', 'xxxxxx'); if (! $link) die(mysql_error()); mysql_select_db($db , $link) or die("Couldn't open $db: ".mysql_error()); $result = mysql_query( "SELECT * FROM birthdays" ) or die("SELECT Error: ".mysql_error()); $num_rows = mysql_num_rows($result); print "There are $num_rows records.<P>"; print "<table width=200 border=1>\n"; while ($get_info = mysql_fetch_row($result)){ print "<tr>\n"; foreach ($get_info as $field) print "\t<td>$field</td>\n"; print "</tr>\n"; } print "</table>\n"; mysql_close($link); ?>
×
×
  • 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.