Jump to content

rysio

Members
  • Posts

    14
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

rysio's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I really hope you didn't think the echo would... it just text to the screen. i try no to think too much when i do what you tell me to do. it did cross my mind that "echo" has little to do with inserting data into the db, but being so amateur in the subject as i am i try to refrain from judging, and since there has been very little progress with this little project of mine lately i just give anything you will say a go, and see what happens. and because my original question concerned inserting data into a mysql db i thought what you suggested might help. i really do not know a lot on the subject, even studying from the books on php i have at home is difficult. it seems to me i have done everything as instructed, but anyway it doesn't work. so you see: having followed the instructions from the php manual i have at home didn't give me the results i was hjoping. that is why i am here asking experts. please do understand that i am simply trying to complete this simple (one could think) task. i did start this as an attempt to learn php, but this seems so hard with finding myself in so many dead ends so often. still i do not give up. do you know the feeling? well that's it for whining over my insufficient skills. back to the question: how will it help me to see the text on the screen? (when echo does its job)
  2. what i'm saying is that this script doesn't insert data into the database. i don't know what that echo was supposed to do. anyway adding the echo where showed didn't change what the script does. it still doesn't write the data into the db.
  3. umm, well still nothing. any other thing that is wrong with it?
  4. if you say so, there must be only one. i take your word for it, but i do see it appear three times physically, and really am an amateur, snd do not know which place is the best to insert the echo. i have tried several versions adding echo to all the $query's i can see there, but no one worked.
  5. should i understand it? i am trully sorry, but i am a total amateur, that is why i came here. i really don't understand what to do with this reply. could you please be a little more specific? p.s. yes - i did try to put the echos before the $queries, and it didn't work... which $query did you mean? i really don't get it.
  6. hi, this is what i came up with trying to make a form which will insert data into the mysql db i'd created: <html> <head> <meta http-equiv="Content-Type" CONTENT="text/html: charset=iso-8859-2"> <title>czytanie z bazy</title> <link rel="stylesheet" type="text/css" href="styl.css"> </head> <body> <table cellpadding="20" cellspacing="0" class="szara"><tr><td> <? mysql_connect ("localhost", "root", "krasnal") or die ("nie mozna polaczyc sie z mysql"); mysql_select_db ("cwphp") or die ("nie mozna polaczyc sie z baza cwphp"); if ($_POST['co'] == 'dodaj') { if ($_POST['user'] && $_POST['ip'] && $_POST['comment'] && $_POST['data'] && $_POST['group_id']) { $query = "INSERT INTO comments (user, ip, comment, e-mail, strona_www, data, "; $query .= "group_id) VALUES ('".$_POST['user']."', '".$_POST['ip']."', '".$_POST['comment']."', '".$_POST['e-mail']."', '".$_POST['strona_www']."', '".$_POST['data']."', '".$_POST['group_id']."');"; $wynik = mysql_query ($query); } } $wynik = mysql_query ("SELECT * FROM comments;") or die ("blad w pytaniu"); print "<table class=\"szara\">"; print "<tr><td><b>guest book</b></td></tr>\n"; while ($rekord = mysql_fetch_assoc ($wynik)) { $user = $rekord['user']; $comment = $rekord['comment']; $data = $rekord['data']; $ip = $_SERVER['REMOTE_ADDR']; $group_id = $rekord['group_id']; $today = date("d.m.y H:i:s"); print "<tr><td>$user</td><td>$comment</td><td>$data</td></tr>\n"; } print "</table>"; ?> <div align="center"><br /> <form method="post"> <input type="hidden" name="co" value="dodaj"><br /> nick: <input name="user" type="text" class="wpisz" size="32"><br /><br /> e-mail: <input name="e-mail" type="text" class="wpisz" size="30"><br /><br /> strona: <input name="strona_www" type="text" class="wpisz" value="http://" size="30"><br /> twój komentarz:<br /> <textarea name="comment" cols="30" rows="5" class="prawa"></textarea><br /><br /> <input type="hidden" name="ip" value="<? $ip; ?>"> <input type="hidden" name="group_id" value="<? $group_id; ?>"> <input type="hidden" name="data" value="<? $today; ?>"> <input type="submit" class="zapisz" value="zapisz"><br /><br /> </form></div> </td></tr> </table> </body> </html> what it does is read from db fine, cause having added records manually i can see results all right, but the form doesn't insert the data to the db as i thought i had it all figured out can you see what might be a problem?
  7. [code]if(isset($comment)){   $number= 257;   $filename = 'comments.txt';   $handle = fopen($filename, "a");   $somecontent = "\n photo number: $number\n comment: $comment\n added by: $name\n posted on: ".date("d.m.y H:i:s")."\n";   fwrite($handle, $somecontent);   fclose($handle); } [/code] ok here it is: i've done some changes, and know already why it used to write the data three times. the thing is - every time the file was executed by a browser (refreshed, opened etc.) the string [sub]$somecontent = "$comment $number ".date("d.m.y H:i:s")."\n";[/sub] is written into the comments.txt file but i only wanted the script to write any content into the comments.txt file when the comment field in the form was filled. actually by this last sentence i've come to the sullution. as simple as the if function - by the way - just learned it because i so much wanted to make this work! and it does :) well - this one is finally solved! did it myself, but thanks phpfreaks for everything!
  8. [quote author=mjdamato link=topic=122719.msg508919#msg508919 date=1169252797] [quote author=rysio link=topic=122719.msg508193#msg508193 date=1169161500]...so please do treat me like a blonde bimbo - tell me what to put and where - please.[/quote] Most blonde bimbos don't need to be told what to put and where. They've usually had it put just about anywhere it can go. Thanks for that - it made my day. [/quote] well - you are absolutely right - it IS totally hilarious.. didn't notice it while writing though ;)
  9. ok, now seriously - first - my english is a second language, so i do not fully understand everything. secondly - all that programming jargon does make it more difficult. on top of that i am not that well acquainted with the php itself, so please do treat me like a blonde bimbo - tell me what to put and where - please.
  10. when i changed the script to what you suggested, the browser doesn't open it - gives me a white page - nothing. p.s. i am not sure what i should do with this last piece of advice :"Also you are going to come unstuck using $posted_var instead of $_POST['posted_var']" am a real noob, so, please - if you can - do explain just roughly, in short, what these commands do. i did try to read the turorials, but, well... i don't get them fully. in fact that is why i am asking my questions here.
  11. there - the whole lot: [code]<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <meta http-equiv="content-type" content="text/html; charset=iso-8859-2"> <title>257</title> <link rel="stylesheet" type="text/css" href="http://www.tkk.pl/~kupka27/styl.css"> </head> <body>             <?php foreach($_POST as $k=>$v) $$k = get_magic_quotes_gpc() ? $v : addslashes($v); $userIP = $_SERVER['REMOTE_ADDR']; $txt=fopen("test.gb","r");  // zapis informacj $gbfile=""; while($line=fgets($txt,3000)) $gbfile.=$line; //name if(isset($name)) if($name==""){ $errorfarbe_1 = "red"; $error = "error"; } else{ $errorfarbe_1 = "black"; } //comment if(isset($comment)) if($comment==""){ $errorfarbe_2 = "red"; $error = "error"; } else{ $errorfarbe_2 = "black"; } if(!$aktion){ $aktion = "aktion"; } if($error=="error"||$aktion=="aktion"){ ?>     </span>     <div align="center"><span class="style1"><span style="font-variant: small-caps">skargi i wnioski</span>       <?               echo "<p>$gbfile</p>"               ?>   </span>             </div>             <form action="<? echo $PHP_SELF;?>" method="post">               <div align="center"><br />             nick: <input name="name" type="text" class="wpisz" size="32"             <? if(isset($name)) echo "value='$name'";?>>                 <br />               <br />             e-mail: <input name="mail" type="text" class="wpisz" size="30">             <br />               <br />             strona: <input name="site" type="text" class="wpisz" value="http://" size="30">             <br />             <br>               twój komentarz:<br />             <textarea name="comment" cols="30" rows="5" class="prawa"><? if(isset($comment)) echo "$comment";?></textarea>             <br />             <br />             <input name="Button" type="submit" class="zapisz" value="zapisz"><br>     <input type="Hidden" name="aktion" value="senden" class="aktion">             <br>   <input type="hidden" name="userIP" class="aktion"           value="<? $userIP; ?>"><br>             </div>           </form>   <span class="style2">                 <?        }else{ if(isset($name)&&isset($comment)&&isset($mail)&&isset($site)&&isset($userIP)) { $name=stripslashes(strip_tags($name)); $comment=stripslashes(strip_tags($comment)); $mail=stripslashes(strip_tags($mail)); $site=stripslashes(strip_tags($site)); $userIP=stripslashes(strip_tags($userIP)); $gbfile="<div align=center><br>\n$comment<br><a href='mailto:$mail'><b>$name</b></a> (ip:$userIP)\n"."\n<text>/<a href='$site' target='blank'>#</a><text>/</text>\n "."\n ".date("d.m.y H:i:s")." "."</div>\n".$gbfile; fclose($txt); $txt=fopen("test.gb","w"); fputs($txt,$gbfile); } echo "<p align=center><a href='test.php'><b>powrót</b></a><br><br>" . $gbfile . "</p>"; fclose($txt); } ?> <?php $filename = 'comments.txt'; $handle = fopen($filename, "a"); $somecontent = "$comment\n257"; fwrite($handle, $somecontent); fclose($handle); ?>               </span>       </td> </tr>     </table> </td>   </tr> </table> </body> </html>[/code]
  12. i'm using the fwrite() function of the tutorial kind... looks like this: after some (nooby) modifications: [code]<?php $filename = 'comments.txt'; $handle = fopen($filename, "a"); $somecontent = "$comment\n257"; fwrite($handle, $somecontent); fclose($handle); ?> [/code] the $comment data comes from another script which is placed in the same file... this works fine, but the "257" fragment (being my way of marking which file the comments are from...)gives the bug - the script writes the number 3 times... what could be done about it?
  13. oh - would have forgotten this script is in one file with another script, which provides the value of $comment ... maybe this changes the thinking to it....
  14. i've tried to modify the file dso that it also writes some more data, like this here - three digits: 257 (the choice of signs=>digits is random) well, it does write it, but the number 257 is written into the comments.txt file three times: like this: 257text 257 257 what to do to make it write the data only once? <?php $filename = 'comments.txt'; $handle = fopen($filename, "a"); $somecontent = "$comment\n257"; fwrite($handle, $somecontent); fclose($handle); ?>
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.