Jump to content

php fwrite & fopen problem


DEVILofDARKNESS

Recommended Posts

I can't find what's wrong, it is always added to my database like it should,

but if I open the url it says

Parse error: syntax error, unexpected T_STRING in /www/uuuq.com/4/a/d/4ade/htdocs/gedichten/test/test2.php on line 16
,

 

if you submit the form well, it should create a file (fopen("$url.php",x) and then write into it the $purl content which is a new php document. fwrite($new,$purl)?

 

<html>
<head><title>Gedichten</title>
        <link href='../../standard.css' type='text/css' rel='stylesheet' />
<link href='natuur.css' type='text/css' rel="stylesheet" />
</head>
<body>
<table class='look' height='100%' width='100%' border='1'>
            <tbody>
                <tr>
                    <td width='10%' height='100%'><iframe class='frames' src='../../functieknoppen/functieknoppennatuur.htm' frameborder='0' width='100%' height='100%' scrolling='no'></iframe>
                    </td>
                    <td><center>
                    <?php
require_once 'config.php';                // our database settings
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
        or die('Error connecting to mysql');
mysql_select_db($dbname);

$query = sprintf("SELECT COUNT(DISTINCT URL) FROM gedichten WHERE category='TEST'");
$result = mysql_query($query);
list($url) = mysql_fetch_row($result);
$url = $url + 1;
print "<form action='' method='POST'>
		Jou Naam: <input type='text' maxlength='35' Name='UName'><br>
		Gedicht Naam: <input type='text' maxlength='35' Name='PName'><br>
		Auteur Naam: <input type='text' maxlength='35' Name='Auteur'><br>
		bundel: <input type='text' maxlength='35' Name='bundel'><br>
		Jaartal: <input type='text' maxlength='35' Name='jaartal'><br>
		Poem Text: <textarea COLS='60' ROWS='5' Name='PText'></textarea>
		<input type='hidden' name='URL' Value='{$url}'><br>
		<input type='submit' Value='Add!' name='submit'> <input type='reset'>
	</form>";
$query = sprintf("SELECT COUNT(DISTINCT id) FROM gedichten");
$result = mysql_query($query);
list($id) = mysql_fetch_row($result);
$id = $id + 1;
$pname = $_POST['PName'];
$uname = $_POST['UName'];
$ptext = $_POST['PText'];
$auteur = $_POST['Auteur'];
$bundel = $_POST['bundel'];
$jaartal = $_POST['jaartal'];
$str = "test";
$url = "{$str}" . "{$_POST['URL']}";
$purl = <<<te
<html dir='ltr'>
    <head>
        <title>{$pname}</title>
        <link href='../../standard.css' type='text/css' rel='stylesheet' />
<link href='natuur.css' type='text/css' rel='stylesheet' />
    </head>
    <body>
        <table class='look' height='100%' width='100%' border='1'>
            <tbody>
                <tr>
                    <td width='10%' height='100%'><iframe class='frames' src='../../functieknoppen/functieknoppengedicht.htm' frameborder='0' width='100%' height='100%' scrolling='no'></iframe>
                    </td>
                    <td><center>
                    <?php
		require_once 'config.php';                // our database settings
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
        or die('Error connecting to mysql');
mysql_select_db($dbname);

$query = sprintf("SELECT PText FROM gedichten WHERE id='{$id}'");
$result = mysql_query($query); ?>
                    </center></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>
te;

if($_POST['submit']) {
	if(empty($_POST['PName'])) {
		print "<script type='text/javascript'>alert('Je hebt geen gedichten naam geschreven!');</script>";
	} elseif(empty($_POST['UName'])) {
		print "<script type='text/javascript'>alert('Je hebt je naam niet geschreven!');</script>";	
	} elseif(empty($_POST['PText'])) {
		print "<script type='text/javascript'>alert('je hebt geen gedicht geschreven!');</script>";
	} elseif(empty($_POST['Auteur'])) {
		print "<script type='text/javascript'>alert('Je hebt geen Auteur ingevuld, als je het niet weet, schrijf dan Onbekend of UnKnown!');</script>";
	} else {
		$query = sprintf("INSERT INTO gedichten(id,PName,UName,PText,URL,category,Auteur,bundel,jaartal) VALUES ('$id','$pname','$uname','$ptext','$url','test','$auteur','$bundel','$jaartal')");
		$result = mysql_query($query);
		$new = fopen("$url.php","x");
		fwrite($new,$purl);
		print "<script type='text/javascript'>alert('Je gedicht is toegevoegd aan de 'Natuur' categorie);</script><a href='test.php'>Zie alle gedichten</a>";
}
}
?>
                    </center></td>
                </tr>
            </tbody>
        </table>
</body>
</html>

Link to comment
Share on other sites

I have looked over and over, but I can't figure out how I can fix it?

The php stops when it views the first ?> tag, and it should stop at the second.

how can I fix that problem?

 

                    <?php
require_once 'config.php';                // our database settings
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
        or die('Error connecting to mysql');
mysql_select_db($dbname);

$query = sprintf("SELECT COUNT(DISTINCT URL) FROM gedichten WHERE category='TEST'");
$result = mysql_query($query);
list($url) = mysql_fetch_row($result);
$url = $url + 1;
print "<form action='' method='POST'>
         Jou Naam: <input type='text' maxlength='35' Name='UName'><br>
         Gedicht Naam: <input type='text' maxlength='35' Name='PName'><br>
         Auteur Naam: <input type='text' maxlength='35' Name='Auteur'><br>
         bundel: <input type='text' maxlength='35' Name='bundel'><br>
         Jaartal: <input type='text' maxlength='35' Name='jaartal'><br>
         Poem Text: <textarea COLS='60' ROWS='5' Name='PText'></textarea>
         <input type='hidden' name='URL' Value='{$url}'><br>
         <input type='submit' Value='Add!' name='submit'> <input type='reset'>
      </form>";
$query = sprintf("SELECT COUNT(DISTINCT id) FROM gedichten");
$result = mysql_query($query);
list($id) = mysql_fetch_row($result);
$id = $id + 1;
$pname = $_POST['PName'];
$uname = $_POST['UName'];
$ptext = $_POST['PText'];
$auteur = $_POST['Auteur'];
$bundel = $_POST['bundel'];
$jaartal = $_POST['jaartal'];
$str = "test";
$url = "{$str}" . "{$_POST['URL']}";
$purl = <<<te
<html dir='ltr'>
    <head>
        <title>{$pname}</title>
        <link href='../../standard.css' type='text/css' rel='stylesheet' />
   <link href='natuur.css' type='text/css' rel='stylesheet' />
    </head>
    <body>
        <table class='look' height='100%' width='100%' border='1'>
            <tbody>
                <tr>
                    <td width='10%' height='100%'><iframe class='frames' src='../../functieknoppen/functieknoppengedicht.htm' frameborder='0' width='100%' height='100%' scrolling='no'></iframe>
                    </td>
                    <td><center>
                    <?php
         require_once 'config.php';                // our database settings
$conn = mysql_connect($dbhost,$dbuser,$dbpass)
        or die('Error connecting to mysql');
mysql_select_db($dbname);

$query = sprintf("SELECT PText FROM gedichten WHERE id='{$id}'");
$result = mysql_query($query); ?>
                    </center></td>
                </tr>
            </tbody>
        </table>
    </body>
</html>
te;

if($_POST['submit']) {
      if(empty($_POST['PName'])) {
         print "<script type='text/javascript'>alert('Je hebt geen gedichten naam geschreven!');</script>";
      } elseif(empty($_POST['UName'])) {
         print "<script type='text/javascript'>alert('Je hebt je naam niet geschreven!');</script>";   
      } elseif(empty($_POST['PText'])) {
         print "<script type='text/javascript'>alert('je hebt geen gedicht geschreven!');</script>";
      } elseif(empty($_POST['Auteur'])) {
         print "<script type='text/javascript'>alert('Je hebt geen Auteur ingevuld, als je het niet weet, schrijf dan Onbekend of UnKnown!');</script>";
      } else {
         $query = sprintf("INSERT INTO gedichten(id,PName,UName,PText,URL,category,Auteur,bundel,jaartal) VALUES ('$id','$pname','$uname','$ptext','$url','test','$auteur','$bundel','$jaartal')");
         $result = mysql_query($query);
         $new = fopen("$url.php","x");
         fwrite($new,$purl);
         print "<script type='text/javascript'>alert('Je gedicht is toegevoegd aan de 'Natuur' categorie);</script><a href='test.php'>Zie alle gedichten</a>";
   }
}
?>

Link to comment
Share on other sites

I will explain,

The meaning is that, users can give their name, the name of the text and the text. if they submit the form, it should autocreate a new page with that text on it, the text now is just created in plain html, but I want to let it come from the database, so that I can change the text, just from there.

 

Can you follow a bit?

Link to comment
Share on other sites

Like the others said you're missing the point from what I see you are trying to achieve the following(correct me if I am wrong)

 

You want to build a form where random people can submit their poems.

If form is filled in correctly and without empty fields you want the poem to be stored into the database.

If there was something left out that the user left out you want the form to be shown again butttttttt! with the values that where previously filled in already in the fields.

 

So  what you are probably looking for is form validation.

And it's a lot easier if you just show the list of already stored poems in a separate page. From there you can just put a link "edit" to go the edit page.

 

Link to comment
Share on other sites

Naah, I want that if a user (or visitor) submits the form without any field left blank,

that the 'php script' autogenerate a new page, whit a query to the database to get the submitted text?

 

Or otherwise, how can I use one url to show more than one poem.

if you click on <link>first link</link> or <link>second</link> you go to the same page,

but it shows an other content.

 

A bit difficult explained, but I do my best

Link to comment
Share on other sites

And can anybody give me an explaination,?

example:

<a href="link.php">link1</a>

<a href="link.php">link2</a>

if you click on link 1 you goto /link.php, this shows you the text from a database that's from link1

if you click on link 2 you goto the same page but this time it need to show the text from link2

is this possible?

Link to comment
Share on other sites

<a href="link.php?item=1">link1</a>
<a href="link.php?item=2">link2</a>

 

link.php code

<?php
if (isset($_GET['item'])) {
   $item = (int)$_GET['item'];
}else {
   $item = 1;
}

switch ($item) {
    default:
    case 1:
          // item 1 coding here.
   break;
   case 2:
          // item 2 coding here
   break;
}
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.