php_beginner_83 Posted September 18, 2009 Share Posted September 18, 2009 Hi all I'm trying to create my own online photo album. Right now I'm working on the upload page that allows me to add records to my database. I have a form where I selected the photo and I use the value from this text box in the form to add to the database. It is stored as the 'Path', the location of the photo so I can later retrieve this and display the photo online. When I select a photo the text box will be populated with a value like.. C:\htdocs\images\photo1.jpg However, when I click the submit button to add my values to the database only 'photo1.jpg' is added to the database. I'm guessing this has something to do with the backslashes. Is that right? Can anyone offer any ideas or solution about how to solve this? Thank you. Code for my form is ... <div id="image"> <h3>Add New Image</h3></br> <form action="uploadPictures.php" method="post"> Image Description:<br/> <textarea cols="50" rows="4" name="imageDescription"> </textarea><br/> Path:<br/> <input type="file" name="path"/><br/> Select Album:<br/> <?php $sql = "SELECT ID, Title FROM albums"; $result = mysql_query($sql) or die(mysql_error()); echo '<select name="albumMenu">'; while($row = mysql_fetch_assoc($result)) { printf('<option value="%s">%s</option>', htmlspecialchars($row['ID']), htmlspecialchars($row['Title'])); } echo '</select>'; ?> <br/><br/> <input type="submit" value="Add New Image"/> </form> </div> any the uploadpicture.php... // ************** CODE FOR IMAGES TABLE ******************// // get last ID in 'pictures' table $result = mysql_query("SELECT * FROM pictures ORDER BY ID desc limit 1") or die('order images error'); $row = mysql_fetch_array($result); $newID = $row['ID'] + 1; // insert new image into 'pictues' table $insert = "INSERT INTO pictures (ID, Description, Path) VALUES ($newID, '{$_POST['imageDescription']}', '{$_POST['path']}')"; mysql_query($insert) or die(mysql_error()); // insert record into 'pics_in_albums' table $insert2 = "INSERT INTO pics_in_albums (PicID, AlbumID) " . "VALUES ($newID, '{$_POST['albumMenu']}')"; mysql_query($insert2) or die('insert into pics_in_album errors'); //***************** END CODE FOR IMAGES TABLE ****************// Quote Link to comment https://forums.phpfreaks.com/topic/174727-_post-and-backslash-problemi-think/ Share on other sites More sharing options...
mikesta707 Posted September 18, 2009 Share Posted September 18, 2009 I suggest you take a look at this tutorial. I'm not sure if you have began the actual uploading part of your script, but this should explain a lot of things. FileUpload on a side note, if you have your id which should be set to auto increment if its the primary key (it should be the primary key) then you don't need to get the value for id, or pass anything into that column, as it will automatically increment for you Quote Link to comment https://forums.phpfreaks.com/topic/174727-_post-and-backslash-problemi-think/#findComment-920829 Share on other sites More sharing options...
php_beginner_83 Posted September 18, 2009 Author Share Posted September 18, 2009 Thanks for the tutorial. ID is the primary key and I don't have it set to auto increment, that's why I have that code in there. Thanks for the suggestion Quote Link to comment https://forums.phpfreaks.com/topic/174727-_post-and-backslash-problemi-think/#findComment-920837 Share on other sites More sharing options...
mikesta707 Posted September 18, 2009 Share Posted September 18, 2009 why not lol? what you are doing could be automated with auto increment. Quote Link to comment https://forums.phpfreaks.com/topic/174727-_post-and-backslash-problemi-think/#findComment-920839 Share on other sites More sharing options...
php_beginner_83 Posted September 18, 2009 Author Share Posted September 18, 2009 Yes, I'm aware of that. Quote Link to comment https://forums.phpfreaks.com/topic/174727-_post-and-backslash-problemi-think/#findComment-920849 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.