Re: I really need help...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



JoShQuNe \(TR\) wrote:
> My problem is i have .txt file size of 3-5 kb with long rows. I have a
> mysql table and a column
> type of longtext, name "html". What I have to do is: I have to open
> .txt and read inside and
> insert the content to "html". My purpose is this but the problem is: I
> easily upload .txt to
> server, and read inside, BUT i can not enter it's content to "html". I
> followed the program up to
> mysql query row its working correctly but when i write
> mysql_query("INSERT INTO abc
> (col1,col2,html) VALUES ('$col1','$col2','$file_contents')") or
> die("ERROR!"); it dies and give
> error.

You should use something more like

$query = "INSERT INTO abc (col1,col2,html) VALUES ('$col1', '$col2',
'$file_contents')";
mysql_query($query) or trigger_error(mysql_error() . " $query",
E_USER_ERROR);

This will give you details about the error and print the query you sent.

> My observations: I put $file_contents instead of ERROR! message
> i saw the content, i set
> the type of "html" column to longblob, nothing changed: ERROR!,

So now you sort of know what you sent to the database, but not exactly
what you sent, and not what the database didn't like.

You were headed in the right direction, but didn't go far enough down this
road.

> i made
> another .php file which
> uses a form, i copied .txt's content manually into <textarea>, it
> succesfully inserted.

There are so many ways this could have have "fixed" whatever was wrong
before...

It at least proves that you *can* get this to work eventually, if you can
figure out what was different about *this* query and *that* query.

> Then i
> made 3 steps program; i uploaded .txt in first step then in second step
> i inserted the content to
> a <textarea> as it's value and at the third step i tried to add to
> mysql, message was: ERROR!

Here you have another data point -- Something you are doing wrong here is
probably the same as the thing you are doing wrong in the first program.

But you need to get the error message from MySQL to find out what it is.

> again. I tought it may be because of touching the <textarea>'s content
> and i clicked <textarea>
> and pressed SPACE BAR :) really but of course nothing changed. One more
> thing i tried to insert by
> mysql_query("UPDATE abc SET html='$file_contents' WHERE col1='$col1'
> and col2='$col2'"); but still
> it answered "I can not enter this variable to "html"". When i delete
> the long rows it achieves but
> i need them and i need to this automatically by selecting the file and
> inserting to mysql.

> Please
> please help me if you can. Below i've added the codes of program. I
> will go insane if i can not
> solve it. I am thinking about learning Perl to do that. Thank you very
> much...

I can pretty much guarantee that you will have no more luck with Perl than
with PHP...  More likely the opposite. :-)

> <?php
> $html="<html>
> <head>
> 	<title>HTML document</title>
> <style>input,textarea,td {font-family:verdana;font-size:10px;border:1px
> #2D7BA2
> solid;background:#BECCE7} </style>
> </head>
> <body>
> <form action='admin.php' method='POST' ENCTYPE='multipart/form-data'>
> <table align='Center'>
> <tr>
> 	<td>Marka:</td>
> 	<td><input name='alan1' type='Text' size=30 value='$alan1'></td>
> </tr>
> <tr>
> 	<td>Ürün Grubu:</td>
> 	<td><input name='alan2' type='Text' size=30 value='$alan2'></td>
> </tr>
> <tr>
> 	<td>Alt Ürün Grubu:</td>
> 	<td><input name='alan3' type='Text' size=30 value='$alan3'></td>
> </tr>
> <tr>
> 	<td>Resmin türü:</td>
> 	<td><input name='tur' type='Radio' value='jpg' checked>JPG <input
> name='tur' type='Radio'
> value='gif'>GIF</td>
> </tr>
> <tr>
> 	<td>Dosya:</td>
> 	<td><input name='file' type='File'></td>
> </tr>
> <tr>
> 	<td colspan=2 align='Center'><input type='Submit' value='Yolla'></td>
> 	</tr>
> </table>
>
> </form>
> ";
> if(empty($HTTP_POST_VARS)){echo $html;}
> else {
> $absolute_path = "../beyazesya/Del";
> $size_limit = "var";
> $limit_size = "150000";
> $limit_ext = "var";
> $ext_count = "2";
> $extensions = array(".jpg", ".gif");
> $geri = "<br><br><a href='#'
> onclick='javascript:history.go(-1)'>Geri</a>";
> $endresult = 'DOSYA BAÞARIYLA GÖNDERÝLDÝ..';
> if ($file_name == "") {
> $endresult='DOSYA SEÇMEDÝNÝZ.. $geri';
> }else{
> if (($size_limit == "var") && ($limit_size < $file_size)) {
> $endresult = 'DOSYA ÇOK BÜYÜK, EN FAZLA 150KB OLABÝLÝR $geri';
> } else {
> $ext = strrchr($file_name,'.');
> if (($limit_ext == "var") && (!in_array($ext,$extensions))) {
> $endresult = 'DOSYA TÜRÜ YALNIZCA .ZIP VEYA .RAR OLABÝLÝR.. $geri';
> }else{
> $actt=@copy($file, "$absolute_path/file.txt") or die("DOSYA
> KOPYALANAMADI.. $geri");
> $dosyam="../beyazesya/Del/file.txt";
> $fp=fopen($dosyam,"r") or die("Cant open file");
> while(!feof($fp)){
> $buf = fgets($fp,8192);
> $buffer=$buffer.$buf;
> }
> $buffer=eregi_replace("\t","",$buffer);

As a matter of good practice, change this to http://php.net/str_replace
which is faster than eregi_replace, since you're not using any of the
powerful features of eregi_replace.

> $buffer=trim($buffer);
> $f_a=$file_name;
> $model=str_replace(".txt","",$f_a);
> $resim="$model.$tur";
> mysql_connect("xxx","yyy","zzz");
> mysql_select_db("aaa");
> $bb=mysql_query("SELECT * FROM beyaz WHERE alan1='$alan1' AND
> alan2='$alan2' AND alan3='$alan3'
> AND model='$model'");
> $say_bb=mysql_num_rows($bb);
> if($say_bb<1)
> {
> $b=mysql_query("INSERT INTO beyaz (alan1,alan2,alan3,resim,model,html)
> VALUES
> ('$alan1','$alan2','$alan3','$resim','$model','$buffer')") or
> die("ERROR!");
> if($b) {echo "$html";
> $yazili=mysql_query("SELECT * FROM beyaz WHERE alan1='$alan1' AND
> alan2='$alan2' AND
> alan3='$alan3'");
> echo "<table align=center><tr><td>";
> $top_yaz=mysql_num_rows($yazili);
> echo "Toplam: <b>$top_yaz</b><hr>";
> while($read=mysql_fetch_row($yazili))
> {
> echo "$read[4]<br>";
> }
> echo "</td></tr></table>";
> }}
> else echo "(this record is done before)";
> fclose ($fp);
> unlink("../beyazesya/Del/file.txt");
> $buffer=0;
>
> }}}}
> ?>

As a WILD GUESS, perhaps some of the non-ASCII characters in the file are
getting messed up when you try to go "direct" into MySQL, but passing them
in via the HTML FORM and then HTTP they get converted into values MySQL
can accept -- tough possibly not values you are willing to use in your
data.

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux