by shnkrsv » Mon Oct 31, 2011 2:45 am
Ya, i have tried but still have the same issue... Wil ter be any problem in uploading the image?
I'll send the image insert code now..
Code :
//insert.php
<?php
$hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
$db_user = "root"; // change to your database password
$db_password = ""; // change to your database password
$database = "demo"; // provide your database name
$db_table = "first"; // leave this as is
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
?>
<html>
<head>
</head>
<body>
<h2>Insert Operation</h2>
<ul style="list-style-type:none;">
<li><a href="main.php">Home</a></li>
<li><a href="insert.php">Insert</a></li>
<li><a href="update.php">Update</a></li>
<li><a href="delete.php">Delete</a></li>
</ul>
<?php
if (isset($_REQUEST['submit']))
{
$name2=$_POST['name1'];
$url2=$_POST['url1'];
$sprice2=$_POST['sprice1'];
$eprice2=$_POST['sprice1'];
$des=$_POST['desc1'];
$img = $_POST['img1'];
$image_name = stripslashes($img);
if(!$img)
echo "This Not an Image";
else
{
$sql="INSERT INTO first VALUES('', '$name2','$url2','$sprice2', '$eprice2', '$des', '$img', '$image_name')";
if(!$result = mysql_query($sql ,$db))
echo "Problem Uploading Image File";
else
{
$lastid=mysql_insert_id();
echo "Image Uploaded Successfully.<p />Your Image :<p /><img src=get.php?id=$lastid>";
}
}
}
?>
<form action="" method="post" enctype="maltipart/form-data">
<table>
<tr>
<td>Name : </td><td><input type="text" name="name1"></td>
</tr>
<tr>
<td>URL : </td><td><input type="text" name="url1"></td>
</tr>
<tr>
<td>Starting Price : </td><td><input type="text" name="sprice1"></td>
</tr>
<tr>
<td>Ending Price : </td><td><input type="text" name="eprice1"></td>
</tr>
<tr>
<td>Description : </td><td><textarea rows="6" cols="40" name="desc1"></textarea></td>
</tr>
<tr><td>Upload An Image:</td><td><input type="file" name="img1" size="20"></td></tr>
<tr>
<td><input type="submit" value="Submit" name="submit"></td>
<td><input type="reset" value="Reset" name="clear"></td>
</table>
</form>
<br />
</body>
</html>
//get.php
<?php
$hostname = "localhost"; // usually is localhost, but if not sure, check with your hosting company, if you are with webune leave as localhost
$db_user = "root"; // change to your database password
$db_password = ""; // change to your database password
$database = "demo"; // provide your database name
$db_table = "first"; // leave this as is
$db = mysql_connect($hostname, $db_user, $db_password);
mysql_select_db($database,$db);
//$id=addslashes($_REQUEST['id']);
$id = intval($_GET['id']); // convert string to int
$row=mysql_query("SELECT * FROM $db_table WHERE id=$id");
$image=mysql_fetch_assoc($row);
$img=$image['img'];
//header("Content-type : image/png");
echo $img;
mysql_free_result($row);
?>
This is what i needed, after inserting the data the images should retrive in the same page, but am not getting so for, so first am tried to get my image viewed by simple code. but am not getting..
Is ter any issues in insert code of my insert.php file.?