inserting a text from a HTML text field to a particular database file using PHP

Discussion in 'PHP' started by Faisal Shah, Feb 25, 2008.

  1. #1
    Hi,

    Well. As title says it self.

    I have got one xdb.txt file as database
    x.php as php processor.

    NOW i will write a small code to make you understand what i want;

    PHP Code:
    <?php
    
    $dbname="xdb.txt"
    
    ?>
    
    <html>
    <head>
    <title>X FILE,</title>
    </head>
    <body>
    <form method="post" action="x.php">
    <input name="text" type="text" size="15">
    <input name="submit" type="submit" value="SUBMIT!">
    </form>
    </body>
    </html> 
    PHP:

    NOW, what i want here is in text field "text", If some one put a text,message and submit using Submit button.
    After when the submit process that php script code it writes the value of "text" to our txt database that is xdb.txt.

    Hope it clears Wink

    Thanks in advance!

    FAISAL!
     
    Faisal Shah, Feb 25, 2008 IP
  2. livewirerules

    livewirerules Active Member

    Messages:
    276
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #2
    im not sure using text files...

    but using php and mysql ,
    <?php
    if ($_POST[submit]){
    	$textvalue=$_POST[textfiled];
    	$sql="insert into <table name> set
    			<your field>='$textvalue'	";
    	$query=mysql_query($sql) or die(mysql_error());
    	echo"inserted";
    	
    }
    
    
    ?>
    PHP:
    its the basic code ,not complete
     
    livewirerules, Feb 25, 2008 IP
  3. rafiqasad

    rafiqasad Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    <?php
    if ($_POST[submit]){
    $textvalue=$_POST[textfiled];
    $myFile = "testFile.txt";
    $fh = fopen($myFile, 'w') or die("can't open file");
    fwrite($fh, $textvalue);
    fclose($fh);
    }

    ?>
     
    rafiqasad, Feb 25, 2008 IP
  4. rafiqasad

    rafiqasad Member

    Messages:
    30
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #4
    
    <?php
    if ($_POST[submit]){
    $textvalue=$_POST[textfiled];
    $dbname="xdb.txt"
    $fh = fopen($dbname, 'w') or die("can't open file");
    fwrite($fh, $textvalue);
    fclose($fh);
    }
    
    ?>
    
    PHP:
     
    rafiqasad, Feb 25, 2008 IP