|
RuuDie (m)
|
Ruddie: Its R.u.u.d.i.e madamoiselle Sooo, I have decided to take a flight and view it from a 30,000-foot perspective and I think (I stand corrected) I have a better understanding of what you are looking for. If you will, please hold my hand while we take a walk along the beach  Thanx for all the effort. . . . but are there really beaches in Potiskum  Based on your original question, I assume a situation where I click "browse", search for my image and then the path gets displayed in the appropriate textbox. However, when it comes time for insertion, nothing is stored. If this is the case, then you need to do the following:
Very correct. . . . 1) You need to create, via php (with necessary checking like: does directory exist? If yes, insert image else create it, setting the necessary permissions, etc), the directory where the file will go. Then you need to add the file to that directory.
what directory might this be  2) You will then need to do something like so: and then insert this path, via mySQL INSERT, along with other values, into the appropriate columns of your table. Then to display the image, you will need to do a SELECT, retrieve/print out the file path and the image should show. Make sense?
makes a world of sense. . . . So how do you go about doing this? I would google (sorry but I am at work and we don't use PHP so I don't have my code with me) for the necessary scripts. I did a few googles and found some stuff so you shouldn't have any problems.
Let us know how it goes. As always, good luck!
Sure will, thank you so very much. . . you work in a software devt firm 
|
|
|
|
|
|
yawa-ti-de (f)
|
Jokes aside, I am happy that I now have a better understanding of what you are looking for and that my suggestions have helped. No, I don't work in a software development firm per se (I mean, let's face it, don't let anyone tell you that as a web developer you aren't developing software cos u r, albeit for the web  ). I work on a corporate website and we use JSP. So rather than wear many hats at the same time, I would rather wear the hat that fits the occasion if you know what I mean.
|
|
|
|
|
|
RuuDie (m)
|
@ yawa-ti-de,
sorry i haven't yet tried anything cuz work is just closing now for me. . . . 6am - 6pm, e no easy oh!
|
|
|
|
|
|
|
|
RuuDie (m)
|
here is the codes i used - pls help check for whatever it is am doing wrong:
this is the script that inserts the values into the database
<?php
$user_name = "root"; $password = ""; $database = "onlinedating"; $server = "127.0.0.1"; $db_handle = mysqli_connect($server, $user_name, $password, $database) or die ("Error connecting to database");
if($_SERVER['REQUEST_METHOD'] == 'POST') { $name = $_POST['txtName']; $sex = $_POST['sltSex']; $email = $_POST['txtemail']; $phone = $_POST['txtphone']; $location = $_POST['txtlocation']; $description = $_POST['txtDesc']; $photo = $_FILES['filePic']['name']; $username = $_POST['txtUsername']; $pword = $_POST['txtPass1'];
here's all the database field names //(us_Name, us_Sex, us_Email, us_Phone, us_Loc, us_Desc, us_Photo, username, password, reg_Date, reg_Time) }
$query = "INSERT INTO reg_users VALUES ('$name','$sex', '$email', '$phone', '$location', '$description', '$photo', '$username', '$pword', NOW(), NOW())";
$result = mysqli_query ($db_handle, $query);
mysqli_close ($db_handle);
?>
html code for the form - which calls the script above
<table width="777" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#333333"> <tr> <td bgcolor="#FFCC66"><h1 align="center"><br>
<span class="style7">New User Sign Up</span> <br> <br> </h1></td> </tr> <tr> <td><form action="confirmation.php" method="post" enctype="multipart/form-data" name="form1"> <table width="100%" border="0"> <caption> </caption> <tr> <th width="46%" scope="row"><div align="right" class="style4">Name</div></th> <td width="54%"><input name="txtName" type="text" id="txtName"></td> </tr> <tr> <th scope="row"><div align="right" class="style4">Sex</div></th> <td><select name="sltSex" size="1" id="sltSex"> <option>Male</option> <option>Female</option> </select> </td> </tr> <tr> <th scope="row"><div align="right" class="style4">Email</div></th> <td><input name="txtemail" type="text" id="txtemail"></td> </tr> <tr> <th scope="row"><div align="right" class="style4">Phone Number </div></th> <td><input name="txtphone" type="text" id="txtphone"></td> </tr> <tr> <th scope="row"><div align="right" class="style4">Current Location</div></th> <td><input name="txtlocation" type="text" id="txtlocation" size="20"> / <select name="sltLoc" size="1" id="sltLoc"> <option>Anambra</option> <option>Abia</option> <option>Adamawa</option> <option selected>Lagos</option> <option>Rivers</option> <option>Abuja</option> <option>Cross River</option> </select> </td> </tr> <tr> <th scope="row"><div align="right"><span class="style4">Describe Yourself </span></div></th> <td><textarea name="txtDesc" cols="45" rows="5" id="txtDesc"></textarea></td> </tr> <tr> <th scope="row"><div align="right"><span class="style4">Upload Photo </span></div></th> <td><input name="filePic" type="file" id="filePic" size="30" accept = "image/jpeg"></td> </tr> <tr> <th scope="row"><div align="right"><span class="style1"><span class="style5"><span class="style1"><span class="style5"></span></span></span></span></div></th> <td> </td> </tr> <tr> <th scope="row"><div align="right" class="style4">Username</div></th> <td><input name="txtUsername" type="text" id="txtUsername"></td> </tr> <tr> <th scope="row"><div align="right" class="style4">Password</div></th> <td><input name="txtPass1" type="password" id="txtPass1"></td> </tr> <tr> <th scope="row"><div align="right" class="style4">Confirm </div></th> <td><input name="txtPass2" type="password" id="txtPass2"></td> </tr> <tr> <th scope="row"> </th> <td> </td> </tr> <tr> <th scope="row"><div align="right" class="style4"> <input name="btnSubmit" type="submit" id="btnSubmit" value="Submit"> </div></th> <td><input name="btnReset" type="reset" id="btnReset" value="Cancel"></td> </tr> </table> </form> </td> </tr> <tr> <td bgcolor="#666666"><div align="center" style="font-size: 12px; color: #CCCCCC;">HOME | ABOUT | NEWS </div></td> </tr> </table>
in the database, i've tried both VARCHAR and BLOB data types for the photo field with the same result - no error messages are generated but form input values are not entered into the database.
appreciate all the help i can get.
|
|
|
|
|
|
yawa-ti-de (f)
|
The problem is filePic - you are not capturing it in your script. If you are, then I missed it.
Again, you need to write the code that creates the directory where the images will be stored. This you will do by getting the value of filePic, creating a directory and then storing filePic's value (the uploaded image) into that directory.
Make sense?
|
|
|
|
|
|
RuuDie (m)
|
The problem is filePic - you are not capturing it in your script. If you are, then I missed it.
Again, you need to write the code that creates the directory where the images will be stored. This you will do by getting the value of filePic, creating a directory and then storing filePic's value (the uploaded image) into that directory.
Make sense?
makes a bit of sense, thanx a bunch. . . . but then, if i do this, how does the script or any other script reconcile the two different directories - the 1 specified in the input field and then this 1 to be created? my sincere apologies if i'm wearing u out with the questions; its just so confusing right now!
|
|
|
|
|
|
yawa-ti-de (f)
|
he he, you aren't wearing me out. If you were, I wouldn't even respond  The directory in the "browse" textfield is a "dummy" directory. The only thing that is "extracted" from that textfield is the last item - whatever it is that you are uploading. The PHP script then creates a directory and adds what you are downloading to that directory. The directory in the "browse" textfield is just for the script to know where to go to copy the image. e nu go? 
|
|
|
|
|
|
RuuDie (m)
|
he he, you aren't wearing me out. If you were, I wouldn't even respond  really not my intention pls. . . . am just a plain, dumb fcuk with dis php thingy. The directory in the "browse" textfield is a "dummy" directory. The only thing that is "extracted" from that textfield is the last item - whatever it is that you are uploading. The PHP script then creates a directory and adds what you are downloading to that directory. The directory in the "browse" textfield is just for the script to know where to go to copy the image.
hmmmmm. . . . makes a world of sense; you are pretty good, you know! e nu go?  yeah i dig!
|
|
|
|
|
|
quadrillio (m)
|
I believe enough people are learning here wit dis. please bring more.
@yawa, everyone thanks
@ruudie, u almost there.
|
|
|
|
|
|
yawa-ti-de (f)
|
eally not my intention pls. . . . am just a plain, dumb fcuk with dis php thingy. Come on! Assuming this isn't a joke, don't say that. Everyone has to start from somewhere. I was where you are 4 yrs ago and guess what? There are things that I still don't know  The important thing is that you finally get it, you make sure it sticks, while constantly learning new things. This way, you always have marketable skills. Good luck!
|
|
|
|
|
|
RuuDie (m)
|
tried and failed again. . . this getting depressing! hey. . . . could it be because the form is pointing to a script on another page  i mean its not a self-referencing form. . . . .
|
|
|
|
|
|
yawa-ti-de (f)
|
Based on your code above, most likely. I see the php on the same form page. I like to separate my form from my "processing page (in your case, confirmation.php)" so try moving your php code into the confirmation page and let us know how it goes. Don't get depressed just yet. Remember, you aren't alone in this battle. Others have tried and prevailed. Don't be the odd ball 
|
|
|
|
|
|
quadrillio (m)
|
tried and failed again. . . this getting depressing!
dont get depressed, like yawaytide said "Coding is serious business, " jus try out d other steps, there's no victory in trying and failing, victory comes when u succeed. so far, yawatide's steps are dbest for you so don't loose focus. Don't get depressed just yet. Remember, you aren't alone in this battle.
yes, we solidly behind u.
|
|
|
|
|
|
quadrillio (m)
|
I decided to dedicate like 30min of my time to search around and put up dis tutorial. cos I think many are watching and learning. this a script dat upload an image to a dir, and also show u ow to retrieve it for display. LET'S START first, your form to choose d image to upload <form action="./upload.php" method="post" enctype="multipart/form-data"> <p> <label for="file">Select a file:</label> <input type="file" name="userfile" id="file"> <br /> <button>Upload File</button> <p> </form>dis is to create a form and link to a file named:"upload.php" to process it. Secondly, write d script to process d image. This will check that the file upload is safe by setting a list of allowed filetypes and disallowing all other file uploads. This will prevent people from uploading malicious files. Then we will check the filesize to prevent large files from being uploaded. <?php // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation. $max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB). $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); // Upload the file to your specified path. if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed . ?>there u go, suitable upload script please NOTE that by default PHP will not handle file uploads larger than 2MB, if you require PHP to handle larger files then you must first set upload_max_filesize and post_max_size in your php.ini file to be larger than 2MB. I hope dis helps. SAFE.
|
|
|
|
|
|
RuuDie (m)
|
Thanks Quadrillo, even my untrained eye can see its a darn good script. . . but my computer must have massive issues with finding "paths." I used your code - exactly as it is but guess what  I get a frigging parse error right here $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory). I just don't get it. . . . i created the folder "files" folder inside the folder where all the other pages are!? Can you think of anything i might have gotten wrong?
|
|
|
|
|
|
latbabs
|
i asked for generating number and i will like it if u can give me the two, but i need the one for pin. so make it fast,
|
|
|
|
|
|
RuuDie (m)
|
@ quadrillo,
hey man, plenty thanx. the script worked - found the error i'd made that stopped it from working right.
but i still have cannot input those values into my database - please help me review the codes i posted earlier abeg!
|
|
|
|
|
|
|
|
maranro (m)
|
thanks quadri 4 d class. Pls i want 2 learn web design and development. Lets discuss my mail is abey232000@hotmail.com
|
|
|
|
|
|
quadrillio (m)
|
i asked for generating number and i will like it if u can give me the two, but i need the one for pin. so make it fast,
Is this an ORDER or a REQUEST? @ quadrillo, hey man, plenty thanx. the script worked - found the error i'd made that stopped it from working right. but i still have cannot input those values into my database - please help me review the codes i posted earlier abeg!
am takin my time to review your code. will post back back d edited version later. thanks quadri 4 d class. Pls i want 2 learn web design and development. Lets discuss my mail is abey232000@hotmail.comlater. D class will continues, SAFE.
|
|
|
|
|
|
*dhtml (m)
|
just strolling by. . .
|
|
|
|
|
|
quadrillio (m)
|
just strolling by. . .
we're together
|
|
|
|
|
|
RuuDie (m)
|
just strolling by. . .
we're together
guys, abeg una no stroll me pass oh 
|
|
|
|
|
|
quadrillio (m)
|
@ruudie, can I continue d class now? hope u ve find your way round it?
d class starts now,
|
|
|
|
|
|
quadrillio (m)
|
next in d class,we'll be introducing ourselves to OOP in PHP
OOP meaning, Object Oriented Programming
where we'll also learn about d different types of Design patterns and others.
- Safe
|
|
|
|
|
|
RuuDie (m)
|
next in d class,we'll be introducing ourselves to OOP in PHP
OOP meaning, Object Oriented Programming
where we'll also learn about d different types of Design patterns and others.
- Safe
Carry go bro. . . . nothing do u!
|
|
|
|
|
|
quadrillio (m)
|
Object-Oriented PHP PHP can, if you want, be written in an object-oriented (OO) fashion. In PHP5 & 6, the OO functionality of the language has been enhanced considerably.
If you are familiar with other OO languages, such as C++ or Java, you may prefer the OO approach to programming PHP, whereas if you are used to other procedural languages, you may not want to use objects at all. There are, after all, many ways to solve the same problem.
If you are new to programming as well as to PHP, you probably have no strong feelings either way just yet. It's certainly true that OO concepts are easier to grasp.
The aim of this lesson is to introduce how a class is created and referenced in PHP so that if you have a preference for using objects, you can begin to develop scripts by using OO methods. Most importantly, however, you will be able to pick up and use some of the many freely available third-party class libraries that are available for PHP from resources such as those at phpclasses
What Is a Class? A class is the template structure that defines an object. It can contain functionsalso known as class methodsand variablesalso known as class properties or attributes.
Each class consists of a set of PHP statements that define how to perform a task or set of tasks that you want to repeat frequently. The class can contain private methods, which are only used internally to perform the class's functions, and public methods, which you can use to interface with the class.
A good class hides its inner workings and includes only the public methods that are required to provide a simple interface to its functionality. If you bundle complex blocks of programming into a class, any script that uses that class does not need to worry about exactly how a particular operation is performed. All that is required is knowledge of the class's public methods.
Because there are many freely available third-party classes for PHP, in many situations, you need not waste time implementing a feature in PHP that is already freely available.
When to Use Classes At first, there may not appear to be any real advantage in using a class over using functions that have been modularized into an include file. OO is not necessarily a better approach to programming; rather, it is a different way of thinking. Whether you choose to develop your own classes is a matter of preference.
One of the advantages of OO programming is that it can allow your code to scale into very large projects easily. In OO programming, a class can inherit the properties of another and extend it; this means that functionality that has already been developed can be reused and adapted to fit a particular situation. This is called inheritance, and it is a key feature of OO development.
When you have completed this book, if you are interested in learning more about OO programming, take a look at Sams Teach Yourself Object-Oriented Programming in 21 Days by Anthony Sintes.
What a Class Looks Like A class is a grouping of various functions and variablesand that is exactly how it looks when written in PHP. A class definition looks very similar to a function definition; it begins with the keyword class and an identifier, followed by the class definition, contained in a pair of curly brackets ({}).
The following is a trivial example of a class to show how a class looks. This example contains just one property, myValue, and one method, myMethod (which does nothing):
class myClass { var $myValue;
function myMethod() { return 0; } }
|
|
|
|
|
|