Jump to content

uploading data to database


Alfraganus

Recommended Posts

I am trying to upload my data in object orinted approach, but larger text are not being uplaoded while only smallers ones are being succesfully uploaded, why larger articles cant bu uplaoded, what is wrong with it? here is my sourse codes

 

upload.php--------------

 

 

<!DOCTYPE html>
<html>
<head>
<title>uploading a file</title>
</head>
<body bgcolor="blue">
<form accept="upload.php" method="post" enctype="multipart/form-data">
<table align="center" width="700" border="2" bgcolor="green">
<tr align="center">
<td align="center">
<td colspan="8"><h2>upload whatever you want mr Alfraganus</h2></td>
</td>
<tr>
<td colspan="8" align="center"><input type="text" name="title" size="60"><b>Title</b></td>
</tr>
<tr>
<td colspan="8"><textarea name="body" cols="80" rows="20"></textarea></td>
</tr>
<tr>
<td colspan="8"><center><input type="submit" name="upload" value="upload the text"> </center></td>
</tr>
</table>
</body>
</html>
<?php
include_once 'functions.php';
$con=new cms();
if(isset($_POST['upload'])) {
$title=$_POST['title'];
$body=$_POST['body'];
$con->insert($title,$body);
}
if($con) {
echo "<script>alert('success')</script>";
}
?>
functions.php------
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','testdb');
class cms {
function __construct()
{
$con=mysql_connect(DB_SERVER, DB_USER,DB_PASS) or die('localhost problemm'.mysql_error());
mysql_select_db(DB_NAME,$con);
}
public function insert($title,$body) {
$res=mysql_connect("INSERT INTO CMS (title, body) values ('$title','$body')");
return $res;
}
}
Edited by Alfraganus
Link to comment
Share on other sites

i suppose you are typing html in the the text fileds :

$title=$_POST['title'];
$body=$_POST['body'];
use this instead to avoid errors even thoe you didnt mention an error !
$title=addslashes($_POST['title']);
$body=addslashes($_POST['body']);
as for the large size post problem try one of these 2 solutions

1) go to php.ini

post_max_size=20M
upload_max_filesize=20M

 

2) use an .htaccess / httpd.conf / virtualhost include

php_value post_max_size 20M
php_value upload_max_filesize 20M
  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...