Jump to content

Recommended Posts

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 ****************//

Link to comment
https://forums.phpfreaks.com/topic/174727-_post-and-backslash-problemi-think/
Share on other sites

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.