Hi all,
I am developing phone book app using php mysql, there is a form called "add contact"(add.php), it has many field like: f_name, l_name, add, country, email, phone, mobile, dob, thumbnail. Now everything works well with mysql and the DB accepts everything like f_name, _name, etc but not the image. I don't know how to add image upload functionality to this form. Any idea please?
How to upload image in "add contact" form.
Moderator: General Moderators
-
moinshaikh
- Forum Commoner
- Posts: 27
- Joined: Tue Jan 18, 2011 3:40 am
- Location: India
Re: How to upload image in "add contact" form.
There are 10 types of people in this world, those who understand binary and those who don't
-
moinshaikh
- Forum Commoner
- Posts: 27
- Joined: Tue Jan 18, 2011 3:40 am
- Location: India
Re: How to upload image in "add contact" form.
thanx VladSun,
but i want to upload image in a already designed form, dont want to design a new form for image upload only. i mean just want to image upload functionality field in that form. Here's the code :
<html>
<head>
<title>PhoneBook</title>
<link rel="stylesheet" type="text/css" href="my.css">
<style>
td,h2{
font:High Tower Text,Tahoma;
color: maroon;
}
h1{
font-family: Goodbye Cruel World,Tahoma;
color: red;
}
</style>
</head>
<body>
<table align="center" cellspacing="0" cellpadding="0" width="50%" border="0">
<tr>
<td align="center"><a href="index.php"><img src="image/phone.png" height="50" width="50" border=0 alt="Go to home page"></a></td>
<td align="center"><a href="contacts.php"><img src="image/contact.png" height="50" width="50" border=0 alt="View all Contatcs"></a></td>
<td align="center"><a href="add.php"><img src="image/add.png" height="50" width="50" border=0 alt="Add new contact"></a></td>
<td align="center"><a href="edit.php"><img src="image/edit.png" height="50" width="50" border=0 alt="Edit Contact"></a></td>
<td align="center"><a href="delete.php"><img src="image/delete.png" height="50" width="50" border=0 alt="Delete a contact"></a></td>
<td align="center"><a href="search.php"><img src="image/Search.png" height="50" width="50" border=0 alt="Search contatcs"></a></td>
</tr>
</table>
<center><h1>Add Contacts</h1><img src="image/add.png" width="200" height="200"></center>
<form name="form1" method="post" action="add.php">
<table noborder align="center" cellspacing="15">
<tr><td> <input type="hidden" name="hidden" value="TRUE" ></td></tr>
<tr><td>First Name</td><td colspan="2"><input type="text" name="f_name" size="20"></td></tr>
<tr><td>Last Name</td><td colspan="2"><input type="text" name="l_name" size="20"></td></tr>
<tr><td>Mobile</td><td colspan="2"><input type="text" name="mobile" size="20"></td></tr>
<tr><td>Phone (O)</td><td colspan="2"><input type="text" name="phno_o" size="20"></td></tr>
<tr><td>Phone (R)</td><td colspan="2"><input type="text" name="phno_r" size="20"></td></tr>
<tr><td>Email Id</td><td colspan="2"><input type="text" name="email" size="20"></td></tr>
<tr><td>Website</td><td colspan="2"><input type="text" name="website" size="20"></td></tr>
<tr><td>Image</td><td colspan="2"><input type="file" name="image" size="20"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Save Contact" size="20"></td>
<td align="center"><input type="reset" name="reset" value="Clear Form" size="20"></td></tr>
</table>
</form>
<?php
if(isset($_POST['hidden']))
{
if(is_string($_POST['f_name']))
{
$f_name = "{$_POST['f_name']}";
$f_name=ucwords($f_name);
}
else
{
die("<center><h2>First Name missing!</h2></center>");
}
if($_POST['l_name']=="")
{
die("<center><h2>Last Name missing!</h2></center>");
}
else
$l_name="{$_POST['l_name']}";
$l_name=ucwords($l_name);
$mobile="{$_POST['mobile']}";
$phno_o="{$_POST['phno_o']}";
$phno_r="{$_POST['phno_r']}";
$email="{$_POST['email']}";
$website="{$_POST['website']}";
mysql_connect('localhost','admin','admin') or die("could not connect to the database");
mysql_select_db('phonebook') or die("could not find appropriate database");
$sql="insert into phone(f_name,l_name,mobile,phno_o,phno_r,email,website) values('$f_name','$l_name','$mobile','$phno_o','phno_r','$email','$website')";
mysql_query($sql) or die("<center><h2>Some Error Occured...!!!</h2></center>");
echo"<center><h2>Record added successfully!</h2></center>";
}
?>
<table width="50%" border="1" cellspacing="5" align="center" cellpadding="3">
<tr>
<td width="22%" align="center"><img src="image/book.png" alt="Online Contact Manager" width="85" height="80" border="0" /></td>
<td width="78%" align="center" ><strong>Online Contact Manager <br />
</strong>
<h2>Personal Contact Card </h2>
</tr>
<tr>
<td colspan="2"><table width="100%" class="cust-card-border" cellspacing="5 cellpadding="0">
<tr>
<td>Name: <strong><?php echo"$f_name" ." ". "$l_name"; ?></strong></td>
</tr>
<tr>
<td>Mobile: <strong><?php echo"$mobile"; ?></strong></td>
</tr>
<tr>
<td>Phone (O): <strong><?php echo"$phno_o"; ?></strong></td>
</tr>
<tr>
<td>Phone (R): <strong><?php echo"$phno_r"; ?></strong></td>
</tr>
<tr>
<td>Email ID: <?php echo"$email"; ?> </td>
</tr>
<tr>
<td>Website: <?php echo"$website"; ?> </td>
</tr>
<tr>
<td>Contact Added/updated on: <?php echo date("d-F-Y"); ?> </td>
</tr>
</table></td>
</tr>
<tr></tr>
</table>
</body>
</html>
but i want to upload image in a already designed form, dont want to design a new form for image upload only. i mean just want to image upload functionality field in that form. Here's the code :
<html>
<head>
<title>PhoneBook</title>
<link rel="stylesheet" type="text/css" href="my.css">
<style>
td,h2{
font:High Tower Text,Tahoma;
color: maroon;
}
h1{
font-family: Goodbye Cruel World,Tahoma;
color: red;
}
</style>
</head>
<body>
<table align="center" cellspacing="0" cellpadding="0" width="50%" border="0">
<tr>
<td align="center"><a href="index.php"><img src="image/phone.png" height="50" width="50" border=0 alt="Go to home page"></a></td>
<td align="center"><a href="contacts.php"><img src="image/contact.png" height="50" width="50" border=0 alt="View all Contatcs"></a></td>
<td align="center"><a href="add.php"><img src="image/add.png" height="50" width="50" border=0 alt="Add new contact"></a></td>
<td align="center"><a href="edit.php"><img src="image/edit.png" height="50" width="50" border=0 alt="Edit Contact"></a></td>
<td align="center"><a href="delete.php"><img src="image/delete.png" height="50" width="50" border=0 alt="Delete a contact"></a></td>
<td align="center"><a href="search.php"><img src="image/Search.png" height="50" width="50" border=0 alt="Search contatcs"></a></td>
</tr>
</table>
<center><h1>Add Contacts</h1><img src="image/add.png" width="200" height="200"></center>
<form name="form1" method="post" action="add.php">
<table noborder align="center" cellspacing="15">
<tr><td> <input type="hidden" name="hidden" value="TRUE" ></td></tr>
<tr><td>First Name</td><td colspan="2"><input type="text" name="f_name" size="20"></td></tr>
<tr><td>Last Name</td><td colspan="2"><input type="text" name="l_name" size="20"></td></tr>
<tr><td>Mobile</td><td colspan="2"><input type="text" name="mobile" size="20"></td></tr>
<tr><td>Phone (O)</td><td colspan="2"><input type="text" name="phno_o" size="20"></td></tr>
<tr><td>Phone (R)</td><td colspan="2"><input type="text" name="phno_r" size="20"></td></tr>
<tr><td>Email Id</td><td colspan="2"><input type="text" name="email" size="20"></td></tr>
<tr><td>Website</td><td colspan="2"><input type="text" name="website" size="20"></td></tr>
<tr><td>Image</td><td colspan="2"><input type="file" name="image" size="20"></td></tr>
<tr><td colspan="2" align="center"><input type="submit" name="submit" value="Save Contact" size="20"></td>
<td align="center"><input type="reset" name="reset" value="Clear Form" size="20"></td></tr>
</table>
</form>
<?php
if(isset($_POST['hidden']))
{
if(is_string($_POST['f_name']))
{
$f_name = "{$_POST['f_name']}";
$f_name=ucwords($f_name);
}
else
{
die("<center><h2>First Name missing!</h2></center>");
}
if($_POST['l_name']=="")
{
die("<center><h2>Last Name missing!</h2></center>");
}
else
$l_name="{$_POST['l_name']}";
$l_name=ucwords($l_name);
$mobile="{$_POST['mobile']}";
$phno_o="{$_POST['phno_o']}";
$phno_r="{$_POST['phno_r']}";
$email="{$_POST['email']}";
$website="{$_POST['website']}";
mysql_connect('localhost','admin','admin') or die("could not connect to the database");
mysql_select_db('phonebook') or die("could not find appropriate database");
$sql="insert into phone(f_name,l_name,mobile,phno_o,phno_r,email,website) values('$f_name','$l_name','$mobile','$phno_o','phno_r','$email','$website')";
mysql_query($sql) or die("<center><h2>Some Error Occured...!!!</h2></center>");
echo"<center><h2>Record added successfully!</h2></center>";
}
?>
<table width="50%" border="1" cellspacing="5" align="center" cellpadding="3">
<tr>
<td width="22%" align="center"><img src="image/book.png" alt="Online Contact Manager" width="85" height="80" border="0" /></td>
<td width="78%" align="center" ><strong>Online Contact Manager <br />
</strong>
<h2>Personal Contact Card </h2>
</tr>
<tr>
<td colspan="2"><table width="100%" class="cust-card-border" cellspacing="5 cellpadding="0">
<tr>
<td>Name: <strong><?php echo"$f_name" ." ". "$l_name"; ?></strong></td>
</tr>
<tr>
<td>Mobile: <strong><?php echo"$mobile"; ?></strong></td>
</tr>
<tr>
<td>Phone (O): <strong><?php echo"$phno_o"; ?></strong></td>
</tr>
<tr>
<td>Phone (R): <strong><?php echo"$phno_r"; ?></strong></td>
</tr>
<tr>
<td>Email ID: <?php echo"$email"; ?> </td>
</tr>
<tr>
<td>Website: <?php echo"$website"; ?> </td>
</tr>
<tr>
<td>Contact Added/updated on: <?php echo date("d-F-Y"); ?> </td>
</tr>
</table></td>
</tr>
<tr></tr>
</table>
</body>
</html>
Re: How to upload image in "add contact" form.
I am not telling you to create a new form, but to modify the one you've already written.
Not going to write it for you, though.
Try to write it and when you face some problems come back here for help.
Also, please use BBCode <syntax=php> your code here</syntax> when posting code.
Not going to write it for you, though.
Try to write it and when you face some problems come back here for help.
Also, please use BBCode <syntax=php> your code here</syntax> when posting code.
There are 10 types of people in this world, those who understand binary and those who don't
-
moinshaikh
- Forum Commoner
- Posts: 27
- Joined: Tue Jan 18, 2011 3:40 am
- Location: India
Re: How to upload image in "add contact" form.
ok thanx for support. i m glad to have supporter like u. thanx again
- greyhoundcode
- Forum Regular
- Posts: 613
- Joined: Mon Feb 11, 2008 4:22 am
Re: How to upload image in "add contact" form.
Perhaps look at your opening <form> tag and research the enctype attribute.