DEVILofDARKNESS Posted January 31, 2009 Share Posted January 31, 2009 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> Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/ Share on other sites More sharing options...
premiso Posted January 31, 2009 Share Posted January 31, 2009 You are using PHP inside of the "te" HEREDOC tags. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751298 Share on other sites More sharing options...
DEVILofDARKNESS Posted January 31, 2009 Author Share Posted January 31, 2009 How can I else make a php page with the form? what do you sugest Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751326 Share on other sites More sharing options...
RichardRotterdam Posted January 31, 2009 Share Posted January 31, 2009 this </html> te; if($_POST['submit']) { makes no sence at all it needs a php tag in front of if() Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751330 Share on other sites More sharing options...
DEVILofDARKNESS Posted February 1, 2009 Author Share Posted February 1, 2009 nobody can help me? I need a php file created in an other php file? ==> 2 <?php ?> tags ? Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751880 Share on other sites More sharing options...
DEVILofDARKNESS Posted February 1, 2009 Author Share Posted February 1, 2009 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>"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751934 Share on other sites More sharing options...
Snart Posted February 1, 2009 Share Posted February 1, 2009 $purl = <<<te and te; Don't make sense, as stated before by Dj Kat. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751936 Share on other sites More sharing options...
trq Posted February 1, 2009 Share Posted February 1, 2009 Why exactly are you trying to generate php files dynamically in the first place? Seems your logic may need to be rethought. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751945 Share on other sites More sharing options...
DEVILofDARKNESS Posted February 1, 2009 Author Share Posted February 1, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751966 Share on other sites More sharing options...
trq Posted February 1, 2009 Share Posted February 1, 2009 Take a look at this thread and some of my replies in there. Your really going about this completely the wrong way. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-751970 Share on other sites More sharing options...
DEVILofDARKNESS Posted February 1, 2009 Author Share Posted February 1, 2009 I really don't get it, I'm just to stupid, I guess. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-752098 Share on other sites More sharing options...
RichardRotterdam Posted February 3, 2009 Share Posted February 3, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-753797 Share on other sites More sharing options...
DEVILofDARKNESS Posted February 4, 2009 Author Share Posted February 4, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-754517 Share on other sites More sharing options...
RichardRotterdam Posted February 5, 2009 Share Posted February 5, 2009 Do you got link of something that looks like what you are trying to do maybe? Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-755142 Share on other sites More sharing options...
Prismatic Posted February 5, 2009 Share Posted February 5, 2009 $purl = <<<te and te; Don't make sense, as stated before by Dj Kat. this </html> te; if($_POST['submit']) { makes no sence at all it needs a php tag in front of if() Heredoc syntax. http://us3.php.net/types.string Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-755147 Share on other sites More sharing options...
premiso Posted February 5, 2009 Share Posted February 5, 2009 Heredoc syntax. http://us3.php.net/types.string Funny how they do not bother to read every entry, they would have learned that a while ago. You are using PHP inside of the "te" HEREDOC tags. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-755213 Share on other sites More sharing options...
RichardRotterdam Posted February 5, 2009 Share Posted February 5, 2009 Funny how they do not bother to read every entry, they would have learned that a while ago. Did read all the entries and knew what it was, just didn't knew it was called heredoc and was too lazy too read all the code. Oh well lesson learned. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-755288 Share on other sites More sharing options...
DEVILofDARKNESS Posted February 5, 2009 Author Share Posted February 5, 2009 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? Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-755356 Share on other sites More sharing options...
premiso Posted February 5, 2009 Share Posted February 5, 2009 <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; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-755427 Share on other sites More sharing options...
trq Posted February 7, 2009 Share Posted February 7, 2009 And can anybody give me an explaination,? I posted a link to another thread in my second reply that explains this by example. Quote Link to comment https://forums.phpfreaks.com/topic/143245-php-fwrite-fopen-problem/#findComment-756578 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.