I am trying to upload few texts and the image using the code But its showing error have a look at the two codes...
<body>
<center>
<h2>Add News</h2>
<form name="news_registration" action="addnews_process.php" method="post" enctype="multipart/form-data">
<table width="600" border="0" align="center">
<tr>
<td width="49%" align="left">News Type</td>
<td width="3%"> </td>
<td width="48%" align="right"><select name="category" id="category">
<?php
include ('db_connect.php');
$sql="SELECT category FROM category";
$result=mysql_query($sql);
while($mem=mysql_fetch_array($result))
{
?>
<option value="<?php echo $mem['category'];?>"><?php echo $mem['category'];?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td align="left">Place</td>
<td> </td>
<td><input name="place" type="text" id="place" maxlength="100" /></td>
</tr>
<tr>
<td align="left">Headlines</td>
<td> </td>
<td><input name="headline" type="text" id="headline" size="50" maxlength="200" />
</textarea><br>
</td>
</tr>
<tr>
<tr>
<td align="left">News Abstract</td>
<td> </td>
<td><textarea name="bdesc" id="bdesc" rows='2' cols='50' >
</textarea>
</td>
</tr>
</tr>
<tr>
<td align="left">News in Detail</td>
<td> </td>
<td><textarea name="para1" id="para1" rows='10' cols='50'>
</textarea>
</td>
</tr>
<tr>
<td colspan="3" align="left"><font color="red" size="2"><p>
<?php
include ('db_connect.php');
$sql="SELECT nno FROM flag";
$result=mysql_query($sql);
$mem=mysql_fetch_array($result);
$mem_nno = $mem['nno'];
$z=$mem_nno+1;
echo "<i>* Its better if you rename your image as $z </i>";
?>
</p>
</font>
</td>
</tr>
<tr>
<td align="left">Add Image</td>
<td> </td>
<td><label for="file">Filename:</label><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td align="left"> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td align="right"><input name="submit" type="submit" id="button" value="Submit" /></td>
<td> </td>
<td> </td>
</tr>
</table>
</form>
</body>
This was the form
And the upload script is
<?php
include('db_connect.php');
if(empty($_POST['category']) or empty($_POST['place']) or empty($_POST['headline']) or empty($_POST['bdesc']) or empty($_POST['para1'])){
echo "<script language='javascript' type='text/javascript'> window.alert('Some of the fields are empty! Please fill it up.'); </script>";
echo "<script language='javascript' type='text/javascript'> location.href='addnews.php' </script>";
}
else{
$pno = "1";
$sql="SELECT * FROM flag where sno=$pno";
$result=mysql_query($sql);
$st=mysql_fetch_array($result);
$st_nno=$st["nno"];
$st_nno=$st_nno+1;
echo "$st_nno";
$sql = mysql_query("INSERT INTO news VALUES('$_POST[category]','$_POST[place]',now(),'$_POST[headline]','$_POST[bdesc]','$_POST[para1]',$st_nno)");
}
if ((($_FILES["file"]["type"] == "image/jpgf")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 2000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
$fname= $_FILES["file"]["name"];
if (file_exists("upload/".$_FILES["file"]["name"]))
{
echo "<script language='javascript' type='text/javascript'> window.alert('File already exists rename it to $st_nno'); </script>";
echo "<script language='javascript' type='text/javascript'> location.href='addnews.php' </script>";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
if($sql){
$sql = mysql_query("UPDATE flag SET nno=$st_nno WHERE sno=$pno");
$result = mysql_query("INSERT INTO pic VALUES ('$st_nno','$fname')");
echo "<script language='javascript' type='text/javascript'> window.alert('News has been added'); </script>";
echo "<script language='javascript' type='text/javascript'> location.href='addnews.php' </script>";
}
else{
echo "<script language='javascript' type='text/javascript'> window.alert('Error adding news'); </script>";
echo "<script language='javascript' type='text/javascript'> location.href='addnews.php' </script>";
}
?>
But while adding news If i amk writing the news in the textbox then its properly uploaded but if i am copying the text and pasting it then it shows error
someone please help me its urgent...