Jump to content

PHP Form Help


Jetmatt777

Recommended Posts

Okay. I am not the greatest nor smartest at PHP, I'm a n00b at it basically. I threw this code together to write contents to a file:HTML page to input data:

<head><script language="javascript">function First() {document.getElementById("2").disableddocument.getElementById("2").checked=false }function Second() {document.getElementById("1").disableddocument.getElementById("1").checked=false }</script></head><form action='add_verse_compile.php' method="post">Book: <SELECT name='book'>		  <OPTION value=''>--Select--</OPTION>		  <OPTION value='Genesis'>Genesis</OPTION>	  </SELECT><br>Chapter: <input type='text' name='chapter' maxlength='3' size='2'><br>Verse: <input type='text' name='verse_num' maxlength='3' size='2'><br>Verse Contents: <br><textarea name='verse' rows='5' cols'45'></textarea><br>First Verse of Chapter <input type='checkbox' name='type' onclick='First()' id='1'>Last Verse of Chapter <input type='checkbox' name='type' id='2' onclick='Second()'><br><input type='submit' value='Add Verse'></form>

PHP Page to compile/write to the .txt file( I know I'm inserting HTMl into the txt file, but I use these files in a php include so it doesn't matter, the HTML goes through and is outputted as normal HTML)

<?php $book = $_POST['book'];   $chapter = $_POST['chapter'];  $verseid = $_POST['verse_num'];  $versecontents = $_POST['verse']  $beg = $_POST['beg'];   $end = $_POST['end'];  $txt = $book ."/". $chapter ."/". $verseid .".txt"  $file = fopen("$txt","w+");echo fwrite($file,"<h4>$beg</h4><br>$versecontents<br>$end<br><a href='#' onclick='Prev()'>Previous Verse</a>   <a href='#' onclick='Next()'>Next Verse</a>");fclose($file);?><?php echo $_POST['book']?> <?php echo $_POST['chapter']?>:<?php echo $_POST['verse_num']?> was successfully added to the database.

When I load the php script, all I get is a blank page, nothing, not a PHP error, just a blank page. Please Help me.-Matt

Link to comment
Share on other sites

There's nothing immediately wrong with your code, from what I see, although you may want to change your code a bit.

$book = $_POST['book'];  $chapter = $_POST['chapter'];  $verseid = $_POST['verse_num'];  $versecontents = $_POST['verse']  $beg = $_POST['beg'];  $end = $_POST['end'];  $txt = $book ."/". $chapter ."/". $verseid .".txt"  $file = fopen("$txt","w+");echo fwrite($file,"<h4>$beg</h4><br>$versecontents<br>$end<br><a href='#'onclick='Prev()'>Previous Verse</a>   <a href='#' onclick='Next()'>NextVerse</a>");fclose($file);php echo $_POST['book'].' ,'.$_POST['chapter'].":".$_POST['verse_num']?>

By the way, if you're using php 5.0 or greater, use file_get_contents() and file_put_contents(), it's much easier.oh and before the error_reporting, try this(becuase its entirely possible your host disabled this)

ini_set('display_errors','1');error_reporting(E_ALL)

Link to comment
Share on other sites

Basically after every function call put this after the ending parentheses, but before the semi colon:OR die('Error message for you to see here');

Link to comment
Share on other sites

Still get blank page, here's what I did:

<html><head></head><body><?php ini_set('display_errors','1');error_reporting(E_ALL);$book = $_POST['book'];  $chapter = $_POST['chapter'];  $verseid = $_POST['verse_num'];  $versecontents = $_POST['verse'];  $beg = $_POST['beg'];  $end = $_POST['end'];  $txt = "http://websiteurl.com/directory/". $book ."/". $chapter ."/". $verseid .".txt"  $file = fopen("$txt","w+") OR die("Couldn't open file");echo file_put_contents($file,"<h4>$beg</h4><br>$versecontents<br>$end<br><a href='#'onclick='Prev()'>Previous Verse</a>   <a href='#' onclick='Next()'>NextVerse</a>") OR die("Couldn't write to file");fclose($file) OR die("Couldn't close file");?></body></html>

Still getting blank page, no error messages

Link to comment
Share on other sites

Okay, just finally got a page full of error messages:Atleast it is something, I guess it took half a day for the server to update?It says on one of them that [function.fopen] is disabled in the webserver configuration. well, I need a new host then.-Matt

Link to comment
Share on other sites

Well the only thing i could think of would be if you started doing things one line at a time. you know, rebuild the page from the beginning, then, after every line echo out the result.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...