POST text, image, integers to MySQL Database via PHP -



POST text, image, integers to MySQL Database via PHP -

i developing website users can upload community listings. implementing via php , mysql.

currently, except photo , description working, , scheme error, "you not registered due scheme error. apologize inconvenience." showing on page load.

the database follows:

id int(10) name (varchar(140) email (varchar(100) neighborhood (text) method (text) title (text) description varchar(1000) price float condit text photo varchar(30) data date

the form code:

<form action="newpost.php" method="post" enctype="multipart/form-data"> <p>first name: <input type="text" name="postername" size="40" maxlength="40" required/></p> <p>email: <input type="email" name="email" size="40" maxlength="40" required/></p> <p><label>neighborhood: <select name="neighborhood"> <optgroup label="uptown"> <option value="inwood">inwood</option> <option value="fort george">fort george</option> <option value="washington heights">washington heights</option> <option value="hamilton heights">hamilton heights</option> <option value="harlem">harlem</option> <option value="east harlem">east harlem</option> <option value="morningside heights">morningside heights</option> <option value="upper west side">upper west side</option> <option value="lincon square">lincoln square</option> <option value="upper east side">upper east side</option> <option value="yorkville">yorkville</option> <option value="lenox hill">lenox hill</option> </optgroup> <optgroup label="midtown"> <option value="clinton">clinton</option> <option value="hells kitchen">hells kitchen</option> <option value="theater district">theater district</option> <option value="midtown">midtown</option> <option value="turtle bay">turtle bay</option> <option value="sutton">sutton</option> <option value="beekman">beekman</option> <option value="murray hill">murray hill</option> <option value="tudor">tudor</option> <option value="garment district">garment district</option> <option value="chelsea">chelsea</option> <option value="midtown south">midtown south</option> <option value="kips bay">kips bay</option> <option value="medical city">medical city</option> <option value="gramercy park">gramercy park</option> <option value="stuyvesant">stuyvesant</option> </optgroup> <optgroup label="downtown"> <option value="meat packing">meat packing</option> <option value="west village">west village</option> <option value="greenwich village">greenwich village</option> <option value="noho">noho</option> <option value="east village">east village</option> <option value="alphabet city">alphabet city</option> <option value="soho">soho</option> <option value="little italy">little italy</option> <option value="bowery">bowery</option> <option value="lower east side">lower east side</option> <option value="tribecca">tribecca</option> <option value="chinatown">chinatown</option> <option value="civic center">civic center</option> <option value="two bridges">two bridges</option> <option value="white hall">white hall</option> <option value="wall street">wall street</option> </optgroup> <option value="brooklyn">brooklyn</option> <option value="queens">queens</option> <option value="bronx">bronx</option> <option value="staten island">staten island</option> </select> </label></p> <p><label>what do: <select name="method"> <option value="buy">buy</option> <option value="sell">sell</option> <option value="swap">swap</option> <option value="rent">rent</option> </select> </label></p> <p>title: <input type="text" name="title" size="140" maxlength="140" required/></p> <p><label>description: <br> <textarea name="description" rows="10" cols="50" maxlength="1000" required>please provide details</textarea></label></p> <p>price: <input type="number" name="price" min="0" max="999999"/></p> <p><label>condition: <select name="condition"> <option value="new">new</option> <option value="used">used</option> </select> </label></p> <p><input type="hidden" name="max_file_size" value="102400"> photo: <input type="file" name="photo" accept="image/jpeg"/></p> <p><input type="submit" name="post" value="post" /></p>

the php:

<?php // script performs insert query add together record listings table. //this directory images saved $target = "image directory"; $target = $target . basename( $_files['photo']['name']); // info form $name = trim($_post['postername']); $email = trim($_post['email']); $neighborhood = ($_post['neighborhood']); $method = ($_post['method']); $title = trim($_post['title']); $descrption = trim($_post['description']); $price = ($_post['price']); $condition = ($_post['condition']); $photo = ($_files['photo']['name']); // connects database $con = mysql_connect('localhost', 'admin', 'password') or die(mysql_error()) ; mysql_select_db('listings', $con) or die(mysql_error()) ; // writes info database $q = mysql_query("insert listings (name, email, neighborhood, method, title, description, price, condit, photo, date) values ('$name', '$email', '$neighborhood', '$method', '$title', '$description', '$price', '$condition', '$photo', now() )") ; // write photo server if(move_uploaded_file($_files['photo']['tmp_name'], $target)) { // if ran ok. // print message: echo 'your listing has been posted.'; } else { // if did not run ok. // public message: echo '<h1>system error</h1> <p class="error">you not registered due scheme error. apologize inconvenience.</p>'; // debugging message: echo '<p>' . mysqli_error($con) . '<br /><br />query: ' . $q . '</p>'; } // end of if ($r) if. mysqli_close($con); // close database connection. ?>

upon submitting, posts database except photo , description.

it seems have typo on index name:

photo != photo

$target = $target . basename( $_files['photo']['name']); <input type="file" name="photo" accept="image/jpeg"/></p> $_files['photo'] // little letter p $descrption // typo (missing letter i)

obligatory note:

please, don't utilize mysql_* functions in new code. no longer maintained and officially deprecated. see red box? larn prepared statements instead, , utilize pdo or mysqli - this article help decide which. if take pdo, here tutorial.

php mysql database upload photo

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -