Upload image and store path

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Upload image and store path

Post by VladSun »

StefanAlexandru wrote:can you be more explicit about sanitize ?
use
mysql_real_escape_string() for every string you want to insert into a MySQL DB:
http://php.net/manual/en/function.mysql ... string.php

StefanAlexandru wrote:i have tried inserting the line but is not working, to work it have to insert all other information?
How do you put the other info into the DB? Code?
There are 10 types of people in this world, those who understand binary and those who don't
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

to be honest i use a code generator PHP Maker! and from that generated code i can't upload files, so that's why i wanted to make a upload script

here is an archive with the generated code, it is so messy ! http://www.storage.to/get/WdfyWnsm/generated%20code.rar

can you give me an example on how can i make my own code for editing the table?
and i will duplicate for the other fields!
the only thing that i want is to be in a editable table

When i started this project i didn't know that will be so hard!

LATER EDIT

is this a good code to edit the fields , this is an example that i found searching google :

Code: Select all

<?php
 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="eurolevel"; // Database name 
$tbl_name="test_mysql"; // Table name 
 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
// Get values from form 
$name=$_POST['name'];
$lastname=$_POST['lastname'];
$email=$_POST['email'];
$
 
// Insert data into mysql 
$sql="INSERT INTO $tbl_name(name, lastname, email)VALUES('$name', '$lastname', '$email')";
$result=mysql_query($sql);
 
// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='insert.php'>Back to main page</a>";
}
 
else {
echo "ERROR";
}
 
// close connection 
mysql_close();
?>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Upload image and store path

Post by VladSun »

StefanAlexandru wrote:to be honest i use a code generator PHP Maker!
Oh!
StefanAlexandru wrote:the generated code, it is so messy ! http://www.storage.to/get/WdfyWnsm/generated%20code.rar
Yes, it's VERY messy.
Frankly, I think you'll need to read some manuals and examples before you are able to finish your project.

Or you can post into the viewforum.php?f=26 section of this forum.
There are 10 types of people in this world, those who understand binary and those who don't
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

what do you think about the code i posted early ?

is good to start with it ?

i hope that you will still help me in "small" problems :)!


hey, is there any possibility that you be part of that section of the forum ? : :) :roll:
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Upload image and store path

Post by VladSun »

StefanAlexandru wrote:what do you think about the code i posted early ?
It's too irrelevant to your code.
StefanAlexandru wrote:i hope that you will still help me in "small" problems :)!
If you show that you are really trying to solve the problem (copy-paste doesn't count) I WILL.

:)
There are 10 types of people in this world, those who understand binary and those who don't
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

please can you give an example with "mysql_real_escape_string() " a really short one!

And i forgot to tell you that we are "neigbhours" ( i am from romania-bucharest)

tomorrow i will try to make a script that edits the database fields, and be sure that i will ask you a lot of things :) !
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Upload image and store path

Post by VladSun »

StefanAlexandru wrote:please can you give an example with "mysql_real_escape_string() " a really short one!
I've already done it - it's all in the manual: http://php.net/manual/en/function.mysql ... string.php
StefanAlexandru wrote:And i forgot to tell you that we are "neigbhours" ( i am from romania-bucharest)
Yes, I know ;)
http://www.google.com/search?client=ope ... 8&oe=utf-8

=>

www . eurolevel . ro/ ;)

StefanAlexandru wrote:tomorrow i will try to make a script that edits the database fields, and be sure that i will ask you a lot of things :) !
Let me see it then :)
There are 10 types of people in this world, those who understand binary and those who don't
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

it seems that i finish a kind of code but is not working, is not introducing the data in the fields, i don't understand why ???

here is the code :

Code: Select all

<?php
$hostname = "localhost";  
$db_user = "root"; 
$db_password = "";
$database = "eurolevel"; 
$db_table = "apartamente"; 
 
$db = mysql_connect($hostname, $db_user, $db_password); 
mysql_select_db($database,$db); 
?>  
<?php 
if (isset($_REQUEST['Submit'])) { 
 
$sql = "INSERT INTO $db_table(tip, nr_camere, zona) values ('".mysql_real_escape_string(stripslashes($_REQUEST['tip']))."','".mysql_real_escape_string(stripslashes($_REQUEST['nr_camere']))."', '".mysql_real_escape_string(stripslashez($_REQUEST['zona']))."')"; 
if($result = mysql_query($sql ,$db)) { 
echo '<h1>Thank you</h1>Your information has been entered into our database<br><br><img src="http://www.webune.com/images/headers/default_logo.jpg"'; 
} else { 
echo "ERROR: ".mysql_error(); 
} 
} else { 
?> 
<title>Adaugare Apartament</title>
<link rel="stylesheet" type="text/css" href="view.css" media="all">
<script type="text/javascript" src="view.js"></script>
 
</head>
<body id="main_body" >
    
    <img id="top" src="top.png" alt="">
    <div id="form_container">
    
        <h1><a>Adaugare Apartament</a></h1>
        <form id="form_71925" class="appnitro"  method="post" action="">
                    <div class="form_description">
            <h2>Adaugare Apartament</h2>
            <p>Completati Toate Campurile!!!</p>
        </div>                      
            <ul >
            
                    <li id="li_1" >
        <label class="description" for="tip">Tip </label>
        <div>
            <input id="Tip" name="Tip" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_2" >
        <label class="description" for="nrcamere">Nr. Camere </label>
        <div>
            <input id="nrcamere" name="nrcamere" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_3" >
        <label class="description" for="zona">Zona </label>
        <div>
            <input id="zona" name="zona" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_4" >
        <label class="description" for="adresa">Adresa </label>
        <div>
            <input id="adresa" name="adresa" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_5" >
        <label class="description" for="confort">Confort </label>
        <div>
            <input id="confort" name="confort" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_6" >
        <label class="description" for="etaj">Etaj </label>
        <div>
            <input id="etaj" name="etaj" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_7" >
        <label class="description" for="suprafatatotala">Suprafata Totala </label>
        <div>
            <input id="suprafatatotala" name="suprafatatotala" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_8" >
        <label class="description" for="suprafatautila">Suprafata Utila </label>
        <div>
            <input id="suprafatautila" name="suprafatautila" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_9" >
        <label class="description" for="anconstructie">An Constructie </label>
        <div>
            <input id="anconstructie" name="anconstructie" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_10" >
        <label class="description" for="vedere">Vedere </label>
        <div>
            <input id="vedere" name="vedere" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        
         
        
        </li>       <li id="li_12" >
        <label class="description" for="orientare">Orientare </label>
        <div>
            <input id="orientare" name="orientare" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_13" >
        <label class="description" for="nrgrsanitare">Nr Grupuri Sanitare </label>
        <div>
            <input id="nrgrsanitare" name="nrgrsanitare" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_14" >
        <label class="description" for="nrbalcoane">Nr Balcoane </label>
        <div>
            <input id="nrbalcoane" name="nrbalcoane" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_15" >
        <label class="description" for="bulina">Legea 112/Bulina </label>
        <div>
            <input id="bulina" name="bulina" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_16" >
        <label class="description" for="cadastruintabulare">Cadastru/ Intabulare </label>
        <div>
            <input id="cadastruintabulare" name="cadastruintabulare" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>       <li id="li_17" >
        <label class="description" for="descriere">Descriere </label>
        <div>
            <textarea id="descriere" name="descriere" class="element textarea medium"></textarea> 
        </div> 
        </li>       <li id="li_18" >
        <label class="description" for="pret">Pret </label>
        <div>
            <input id="pret" name="pret" class="element text medium" type="text" maxlength="255" value=""/> 
        </div> 
        </li>
            
                    <li class="buttons">
                <input type="hidden" name="anunt" value="71925" />
                
                <input id="saveForm" class="button_text" type="submit" name="submit" value="Adauga" action="bazadate.php" />
        </li>
            </ul>
        </form> 
        <div id="footer">
        
        </div>
    </div>
    <img id="bottom" src="bottom.png" alt="">
    </body>
<?php 
} 
?> 
</body> 
</html>


and i have this code to, but like the other, it;s not working nothing in the database :


Code: Select all

<?
 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="eurolevel"; // Database name 
$tbl_name="apartamente"; // Table name 
 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
// Get values from form 
$tip=$_POST['tip'];
$nrcamere=$_POST['nrcamere'];
$zona=$_POST['zona'];
$adresa=$_POST['adresa'];
$confort=$_POST['confort'];
$etaj=$_POST['etaj'];
$stot=$_POST['suprafatatotala'];
$sutila=$_POST['suprafatautila'];
$anconstr=$_POST['anconstructie'];
$vedere=$_POST['vedere'];
$orienteare=$_POST['orientare'];
$nrgrsan=$_POST['nrgrsanitare'];
$nrbalcoane=$_POST['nrbalcoane'];
$bulina=$_POST['bulina'];
$cadint=$_POST['cadastruintabulare'];
$descriere=$_POST['descriere'];
$pret=$_POST['pret'];
 
// Insert data into mysql 
$sql="INSERT INTO $tbl_name(tip, nr_camere, zona, adresa, confort, etaj, suprtotala, suprutila, an_constructie, vedere, orientare, nr_gr_sanitare, nr_balcoane, bulina, cadastru_intabulare, descriere, pret)VALUES('$tip', '$nrcamere', '$zona','$adresa','$confort','$etaj','$stot','$sutila','$anconstr','$vedere','$orienteare','$nrgrsan','$nrbalcoane','$bulina','$cadint','$descriere','$pret')";
$result=mysql_query($sql);
 
// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Anuntul a fost adaugat cu succes";
echo "<BR>";
echo "<a href='form.html'>Innapoi la adaugare anunt</a>";
}
 
else {
echo "Eroare!!! Daca intampinati acest mesaj - sunati administratorul site-ului";
}
 
// close connection 
mysql_close();
?>
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

And i've worked on my upload script and i have tryed to sanitize the $path -- but of course is not working, maybe because it have to enter all the data, not only the picturese!

here is the code

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db('eurolevel');
$path1= "apartamente/".$_FILES['ufile']['name'][0];
$path2= "apartamente/".$_FILES['ufile']['name'][1];
$path3= "apartamente/".$_FILES['ufile']['name'][2];
 
 
move_uploaded_file($_FILES['ufile']['tmp_name'][0], $path1);
move_uploaded_file($_FILES['ufile']['tmp_name'][1], $path2);
move_uploaded_file($_FILES['ufile']['tmp_name'][2], $path3);
 
 
 
 
 
$filesize1=$_FILES['ufile']['size'][0];
$filesize2=$_FILES['ufile']['size'][1];
$filesize3=$_FILES['ufile']['size'][2];
mysql_query("INSERT INTO apartamente (poza1, poza2, poza3) VALUES('".mysql_real_escape_string($_REQUEST['$path1'])."', '".mysql_real_escape_string($_REQUEST['$path2'])."' , '".mysql_real_escape_string($_REQUEST['$path3'])."' ");
 
if($filesize1 && $filesize2 && $filesize3 != 0) 
{
echo "We have recieved your files";
}
 
else {
echo "ERROR.....";
}
 
?>
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Upload image and store path

Post by VladSun »

it seems that i finish a kind of code but is not working, is not introducing the data in the fields, i don't understand why ???
Error messages?
and i have this code to, but like the other, it;s not working nothing in the database :
Use mysql_error() and tell us what error messages are displayed.
but of course is not working, maybe because it have to enter all the data, not only the picturese!
You are right. You have to either put this script into your first one (from your previous post) or use UPDATE statement.
There are 10 types of people in this world, those who understand binary and those who don't
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

where should i put mysql_error() ! i have to use with mysql_errno() ?
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: Upload image and store path

Post by VladSun »

Code: Select all

// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Anuntul a fost adaugat cu succes";
echo "<BR>";
echo "<a href='form.html'>Innapoi la adaugare anunt</a>";
}
 
else {
echo "Eroare!!! Daca intampinati acest mesaj - sunati administratorul site-ului";
>>>> here
}
There are 10 types of people in this world, those who understand binary and those who don't
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

i have parse error on line 46

Code: Select all

<?
 
$host="localhost"; // Host name 
$username="root"; // Mysql username 
$password=""; // Mysql password 
$db_name="eurolevel"; // Database name 
$tbl_name="apartamente"; // Table name 
 
// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
 
// Get values from form 
$tip=$_POST['tip'];
$nrcamere=$_POST['nrcamere'];
$zona=$_POST['zona'];
$adresa=$_POST['adresa'];
$confort=$_POST['confort'];
$etaj=$_POST['etaj'];
$stot=$_POST['suprafatatotala'];
$sutila=$_POST['suprafatautila'];
$anconstr=$_POST['anconstructie'];
$vedere=$_POST['vedere'];
$orienteare=$_POST['orientare'];
$nrgrsan=$_POST['nrgrsanitare'];
$nrbalcoane=$_POST['nrbalcoane'];
$bulina=$_POST['bulina'];
$cadint=$_POST['cadastruintabulare'];
$descriere=$_POST['descriere'];
$pret=$_POST['pret'];
 
// Insert data into mysql 
$sql="INSERT INTO $tbl_name(tip, nr_camere, zona, adresa, confort, etaj, suprtotala, suprutila, an_constructie, vedere, orientare, nr_gr_sanitare, nr_balcoane, bulina, cadastru_intabulare, descriere, pret)VALUES('$tip', '$nrcamere', '$zona','$adresa','$confort','$etaj','$stot','$sutila','$anconstr','$vedere','$orienteare','$nrgrsan','$nrbalcoane','$bulina','$cadint','$descriere','$pret')";
$result=mysql_query($sql);
 
// if successfully insert data into database, displays message "Successful". 
if($result){
echo "Anuntul a fost adaugat cu succes";
echo "<BR>";
echo "<a href='form.html'>Innapoi la adaugare anunt</a>";
}
 
else {
echo "Eroare!!! Daca intampinati acest mesaj - sunati administratorul site-ului";
mysql_error()
}  //---->>>>> HERE
 
// close connection 
mysql_close();
?>
StefanAlexandru
Forum Newbie
Posts: 16
Joined: Thu Jul 09, 2009 9:54 am

Re: Upload image and store path

Post by StefanAlexandru »

i can't belive but i finish the script, i have read something on the internet and like magic i have done the script, but now i will give you an archive with the whole script, and i wish to tell me how too add the upload photo to my script!
here is the whole script admin.rar - 4.0 Kb

Thanks a lot for your help
Post Reply