This is what I do in a system of news add program, can upload pictures, also can enter absolute greater than 4K content (in textarea), ...

Source: Internet
Author: User
Tags date include insert key require reset return unique id
program | upload | upload picture <?php
The table structure used by the/******* ********
DROP TABLE IF EXISTS index_news;
CREATE TABLE Index_news (
news_id bigint not NULL auto_increment,
News_date date DEFAULT ' 0000-00-00 ' not NULL,
News_title varchar (m) not NULL,
News_content text,
News_link varchar (100),
Is_new char (1) DEFAULT ' 1 ',
picture_id Int (11),
Picture_side char (1) DEFAULT ' 1 ',
News_show char (1) DEFAULT ' 1 ',
PRIMARY KEY (news_id),
KEY ID (news_id)
);
DROP TABLE IF EXISTS picture;
CREATE TABLE Picture (
ID Int (one) not NULL auto_increment,
The picture blob is not NULL,
Picture_type varchar (m) not NULL,
PRIMARY KEY (ID),
UNIQUE ID (ID)
);
**********************/
Require (".. /include/date.inc.php3 ");
Require (".. /include/config.inc.php3 ");
?>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 transitional//en" >

<title> Modify Home News information </title>
<script language= "JavaScript" >
<!--
function Mm_findobj (n, D) {//v3.0
var p,i,x; if (!d) d=document; if ((P=n.indexof ("?")) >0&&parent.frames.length) {
D=parent.frames[n.substring (p+1)].document; N=n.substring (0,p);}
if (!) ( X=d[n]) &&d.all) x=d.all[n]; for (i=0;! x&&i<d.forms.length;i++) X=d.forms[i][n];
for (i=0;! x&&d.layers&&i<d.layers.length;i++) X=mm_findobj (n,d.layers[i].document); return x;
}

function Mm_validateform () {//v3.0
var i,p,q,nm,test,num,min,max,errors= ', args=mm_validateform.arguments;
For (i=0 i< (args.length-2); i+=3) {test=args[i+2]; obj_name=args[i+1]; Val=mm_findobj (args[i));
if (val) {nm=val.name; if (val=val.value)!= "") {
if (Test.indexof (' Isemail ')!=-1) {p=val.indexof (' @ ');
if (p<1 | | p== (VAL.LENGTH-1)) errors+= '-' +obj_name+ ' must be an e-mail address. \ n ';
else if (test!= ' R ') {num = parsefloat (val);
if (val!= ' +num) errors+= '-' +obj_name+ ' must be a number. \ n ';
if (Test.indexof (' InRange ')!=-1) {P=test.indexof (': ');
Min=test.substring (8,P); Max=test.substring (p+1);
if (Num<min | | max<num) errors+= '-' +obj_name+ ' must be a number between ' +min+ ' and ' +max+ '. \ n ';
}} else if (Test.charat (0) = = ' R ') errors + = '-' +obj_name+ ' must be entered. \ n '; }
} if (Errors) alert (' Input data error: \ n ' +errors ');
Document. Mm_returnvalue = (Errors = = ");
}
-->
</script>

<body>
<?php
if ($add) {
$date =input2date ($news _date);
Echo $picture. "  ". FileSize ($picture);
if ($is _new!= "0") $is _new= "1";
if ($news _show!= "0") $news _show= "1";
if ($picture _side!= "2") $picture _side= "1";
if ($picture!= "None") {
$pic _data = addslashes (Fread ($fp =fopen ($picture, "R"), FileSize ($picture));
$i _str= "INSERT into the picture (Picture,picture_type) VALUES (' $pic _data ', ' $picture _type ')";
$rs->open ($i _str);
$result =mysql_query ($i _str, $dbconnect);
$picture _id=mysql_insert_id ();
Fclose ($FP);
Unlink ($picture);
}
else{
$picture _id=0;
}
$i _str= "INSERT INTO Index_news (News_date,news_title,news_content,news_link,picture_id,is_new,picture_side,news_ Show) values ";
$i _str.= "(' $date ', ' $news _title ', ' $news _content ', ' $news _link ', ' $picture _id ', ' $is _new ', ' $picture _side ', ' $news- Show ') ";

if (mysql_query ($i _str, $dbconnect)) echo has been added! ";

}

<form name= "F" enctype= "Multipart/form-data" method= "post" action= "<?php echo $PATH _info;?>" >
<table width= "border=" 0 "cellspacing=" 0 "cellpadding=" 0 "align=" center ">
<tr>
&LT;TD colspan= "2" >
<div align= "center" ><font size= "4" > Add news </font></div>
</td>
</tr>
<tr>
&LT;TD colspan= "2" > </td>
</tr>
<tr>
&LT;TD width= > news title: </td>
<td>
<input type= "text" name= "News_title" size= ">"
</td>
</tr>
<tr>
<td> News content:</td>
<td>
<textarea name= "news_content" cols= "rows=" "5" ></textarea>
</td>
</tr>
<tr>
<td> News Date:</td>
<td>
<input type= "text" name= "News_date" >
(date is entered in 2000-01-02 format) </td>
</tr>
<tr>
<td> News Link:</td>
<td>
<input type= "text" name= "News_link" size= ">"
</td>
</tr>
<tr>
<td> whether the latest:</td>
<td>
<select name= "Is_new" >
<option value= "1" selected> is the latest </option>
<option value= "0" > Not up to date </option>
</select>
</td>
</tr>
<tr>
<td> News Photo:</td>
<td>
<input type= "file" name= "Picture" size= ">"
</td>
</tr>
<tr>
<td> Picture Location:</td>
<td>
<select name= "Picture_side" >
<option value= "1" selected> left </option>
<option value= "2" > Right </option>
</select>
</td>
</tr>
<tr>
<td> whether to display:</td>
<td>
<select name= "News_show" >
<option value= "1" selected> display </option>
<option value= "0" > Do not show </option>
</select>
</td>
</tr>
<tr>
&LT;TD colspan= "2" >
<div align= "center" >
<input type= "Submit" name= "Add" value= "Add" onclick= "Mm_validateform (' news_title ', ', ', ' R ', ' News_date ', ', ', ', ' R ', ', ', ' News_content ', ', ' R ', return document. Mm_returnvalue ">
<input type= "button" Name= "return" value= "Back" >
<input type= "reset" name= "reset" value= "re-enter" >
</div>
</td>
</tr>
</table>
</form>
</body>


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.