Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Adding title to my image in database
Old 11-26-2009, 03:09 AM Adding title to my image in database
Novice Talker

Posts: 6
Name: Sarika Sakpal
Trades: 0
I'm new to php so this question might be really lame. I'm trying to upload images to my database and have been able to do that but I also want to add the title that I add on the first page and i have no clue how to go about that:

here's the code:
addform.php
<?php
$dbhost = 'localhost';
$dbuser = 'user';
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'imagegal';
mysql_select_db($dbname);
?>


<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>
<title>Multiple image upload script from plus2net.com</title>
<meta name="GENERATOR" content="Arachnophilia 4.0">
<meta name="FORMATTER" content="Arachnophilia 4.0">
</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?
$max_no_img=5; // Maximum number of images value to be set here
echo "<form method=post action=addimg.php enctype='multipart/form-data'>";
echo "<table border='0' width='550' cellspacing='0' cellpadding='0' align=center>";
for($i=1; $i<=$max_no_img; $i++){
echo "<tr><td>Images $i</td><td>
<input type=file name='images[]' class='bginput'></td>
<td>
<td><label>Image title</label></td><td>
<input type=text name='title[]' class='bginput'></td></tr>";
}
echo "<tr><td colspan=6 align=center><input type=submit value='Add Image'></td></tr>";

echo "</form> </table>";



?>

</body>

</html>


addimg.php
<?
//***************************************
// This is downloaded from www.plus2net.com //
/// You can distribute this code with the link to www.plus2net.com ///
// Please don't remove the link to www.plus2net.com ///
// This is for your learning only not for commercial use. ///////
//The author is not responsible for any type of loss or problem or damage on using this script.//
/// You can use it at your own risk. /////
//*****************************************
?>
<?php
$dbhost = 'localhost';
$dbuser = 'user;
$dbpass = 'password';

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');

$dbname = 'imagegal';
$table = 'gallery';
mysql_select_db($dbname);
?>

<!doctype html public "-//w3c//dtd html 3.2//en">

<html>

<head>

</head>

<body bgcolor="#ffffff" text="#000000" link="#0000ff" vlink="#800080" alink="#ff0000">
<?

while(list($key,$value) = each($_FILES['images']['name']))
{
if(!empty($value))
{
$filename = $value;
$image_name=time().$extension;
$filename=str_replace(" ","_",$filename);// Add _ inplace of blank space in file name, you can remove this line
$filename=$image_name.$filename;
$add = "upimg/$filename";
//echo $_FILES['images']['type'][$key];
// echo "<br>";
copy($_FILES['images']['tmp_name'][$key], $add);
chmod("$add",0777);
mysql_query("INSERT INTO {$table}
SET data='$add'");
}

}


?>

</body>

</html>


I'm adding the path as text and not longblob since i'll need the physical path of the file later. So any ideas how i can add the title with the image.

Thanks in advance for any help.
sarika.sakpal is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-26-2009, 05:33 AM Re: Adding title to my image in database
Super Talker

Posts: 139
Name: John Davis
Trades: 0
1. Where from $extension comes?
2. {} in strings is nwcessary only for array values. Like: "Hello {$names[$i]}!"

Can you provide SQL query which creates your table?
In any way you have to create column in your table to store title information (if not exist). then your query will like:
Code:
mysql_query("INSERT INTO $table SET data='$add', title='{$_POST['title'][$key]}'");
__________________
»
Please login or register to view this content. Registration is FREE
- Interactive maps for websites
»
Please login or register to view this content. Registration is FREE
for web developers
MapMaster is offline
Reply With Quote
View Public Profile Visit MapMaster's homepage!
 
Old 11-26-2009, 11:36 AM Re: Adding title to my image in database
Novice Talker

Posts: 6
Name: Sarika Sakpal
Trades: 0
Ok i had the title column but didnt know how to add data. This totally worked.
Thanks so much
sarika.sakpal is offline
Reply With Quote
View Public Profile
 
Old 11-26-2009, 05:07 PM Re: Adding title to my image in database
Novice Talker

Posts: 11
Trades: 0
you mean you want the query structure... it should be like this :
mysql_query("INSERT INTO $tablename (tablecolumn1, tablecolumn2) VALUES ('$valuefortablecolumn1', '$title'");

Hope that helps coz as far as i can see the syntax is wrong for inserting the record....
__________________
Wondering who Iam? Visit me and check my thoughts at
Please login or register to view this content. Registration is FREE

Want to earn cash? click the image below :
Please login or register to view this content. Registration is FREE

chieina is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Adding title to my image in database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.27135 seconds with 12 queries