twilitegxa Posted June 22, 2009 Share Posted June 22, 2009 This is what my page displays upon entering data into my form: The $topic_title topic has been created. "; ?> New Topic Added Here is the php code: <?php //check for required fields from the form if ((!$_POST[post_owner]) || (!$_POST[topic_title]) || (!$_POST[topic_owner])) { header("Location: addtopic.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); //create and issue the first query $add_topic = "insert into forum_topics values ('', '$_POST[topic_title]', now(), '$_POST[topic_owner]')"; mysql_query($add_topic,$conn) or die(mysql_error()); //get the id of the last query $topic_id = mysql_insert_id(); //create and issue the second query $add_post = "insert into forum_posts values ('', '$topic_id', '$_POST[post_text]', now(), '$_POST[topic_owner]')"; mysql_query($add_post,$conn) or die(mysql_error()); //create nice message for user $msg = "<p>The <strong>$topic_title</strong> topic has been created.</p>"; ?> <html> <head> <title>New Topic Added</title> </head> <body> <h1>New Topic Added</h1> <?php print $msg; ?> </body> </html> And here is the html code for the form: <html> <head> <title>Add A Topic</title> </head> <body> <h1>Add A Topic</h1> <form method=post action="do_addtopic.php"> <p><strong>Your E-Mail Address:</strong><br /> <input type="text" name="topic_owner" size=40 maxlength=150 /></p> <p><strong>Topic Title:</strong><br /> <input type="text" name="topic_title" siz=40 maxlength=150 /></p> <p><strong>Post Text:</strong><br /> <textarea name="post_text" rows=8 cols=40 wrap=virtual></textarea></p> <p><input type="submit" name="submit" value="Add Topic" /></p> </form> </body> </html> What have I done wrong? Quote Link to comment Share on other sites More sharing options...
YourNameHere Posted June 22, 2009 Share Posted June 22, 2009 "... method=post ..." needs to be: "... method="post" ..." Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 23, 2009 Author Share Posted June 23, 2009 I tried that, but nothing changed. :-( Quote Link to comment Share on other sites More sharing options...
YourNameHere Posted June 23, 2009 Share Posted June 23, 2009 This line: $msg = "<p>The <strong>$topic_title</strong> topic has been created.</p>"; ---------------------------------------- replace with... $msg = "<p>The <strong>" . $topic_title . "</strong> topic has been created.</p>"; and the "/" chars may need to be escaped ( ex. <//strong> and <//p> ) , not sure about that, try it and see Edit: In most cases it is not nessesary to escape foreward slashes. But I use that as a debug failsafe and it sometimes works. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 25, 2009 Author Share Posted June 25, 2009 What makes my php page not show sometimes? When I open and submit my form, instead of running the php page, it is now displaying the code instead. What makes that happen and how can I fix it?? Quote Link to comment Share on other sites More sharing options...
947740 Posted June 25, 2009 Share Posted June 25, 2009 Edit: In most cases it is not nessesary to escape foreward slashes. But I use that as a debug failsafe and it sometimes works. It depends on whether it is a special entity with the slash. I.E. \t, \n. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 25, 2009 Author Share Posted June 25, 2009 Well, I didn't use the escape slashes yet, but the page is not runnign the php page now, and I tried changing to the recommended code and also going back to the original code and neither is allowing my php code to run now. What could be the problem? What causes this to happen? Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 25, 2009 Share Posted June 25, 2009 $msg = "<p>The <strong>$topic_title</strong> topic has been created.</p>"; is perfect don't do the dots thing. try using echo instead of print. <?php print $msg; ?> to <?php echo $msg; ?> Quote Link to comment Share on other sites More sharing options...
947740 Posted June 25, 2009 Share Posted June 25, 2009 if ((!$_POST['post_owner']) || (!$_POST['topic_title']) || (!$_POST['topic_owner'])) { header("Location: addtopic.html"); exit; } $add_topic = "insert into forum_topics values ('', '".$_POST['topic_title']."', now(), '".$_POST['topic_owner']."')"; $add_post = "insert into forum_posts values ('', '$topic_id', '".$_POST['post_text']."', now(), '".$_POST['topic_owner']."')"; The post names need ' around them, unless they are constants, which I seriously doubt. Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 25, 2009 Share Posted June 25, 2009 yes 947740 is correct u need quotes on those I missed that. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 25, 2009 Author Share Posted June 25, 2009 I added the single quotes around those. I am using WAMPServer on my local computer rather than a host server, also, by the way. I am still not able to run the php page. The form, unpon submission, displays the php code instead of running the code. Quote Link to comment Share on other sites More sharing options...
947740 Posted June 25, 2009 Share Posted June 25, 2009 This sounds like a server problem...but can we see the code with all the changes you've made? Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 Was WAMP working before these changes? Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 25, 2009 Share Posted June 25, 2009 install nginx No install needed actually when you download it its already done.. you just need to run php in command line. I put PHP folder into nginx folder so my command line is. c:\nginx\php\php-cgi.exe -b 127.0.0.1:9000 -c c:\nginx\php\php.ini you have to save that in a batch file I'd save it in a txt document then rename it to a batch file.. mines is start php.bat. I use batch file because i dont want to make it into a service since this is only for testing.. but if you want you can make it a service on your hosting computer. It's made by russian and im russian myself so I feel pride. its smaller then apache which is what WAMP is and around 200x-250x faster at loading php pages due to it's proxy support thingy it runs php on a proxy on port 9000 or w\e instead of calling PHP.exe everytime a page is about to show. Only thing I don't like in nginx it doesn't support htaccess files which are for rewrites.. but it does support rewrites only thing u gotta restart server everytime you add or test a new rewrite as it loads it once not always Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 25, 2009 Author Share Posted June 25, 2009 Sure. Here is the code with the changes. And, I didn't check that WAMP was working before I changed anything, but even when I changed the code back to the original code (before changes), it still was not working. :-( <?php //check for required fields from the form if ((!$_POST['post_owner']) || (!$_POST['topic_title']) || (!$_POST['topic_owner'])) { header("Location: addtopic.html"); exit; } //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); //create and issue the first query $add_topic = "insert into forum_topics values ('', '"$_POST['topic_title']"', now(), '"$_POST['topic_owner']"')"; mysql_query($add_topic,$conn) or die(mysql_error()); //get the id of the last query $topic_id = mysql_insert_id(); //create and issue the second query $add_post = "insert into forum_posts values ('', '$topic_id', '"$_POST['post_text']"', now(), '"$_POST['topic_owner']"')"; mysql_query($add_post,$conn) or die(mysql_error()); //create nice message for user $msg = "<p>The <strong>$topic_title</strong> topic has been created.</p>"; ?> <html> <head> <title>New Topic Added</title> </head> <body> <h1>New Topic Added</h1> <?php echo $msg; ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 I think your server install is at fault, Double check or reinstall. Also make sure that you are typing in the server's correct address and you should make sure it is on your knownhosts file. If you are running vista you have to copy over the file with admin rights or else it will not allow a change to the knownhosts file. One more thing, there are lots of other servers available out there, try out a miny, so that no install is necessary and you just have to start up appache. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 25, 2009 Author Share Posted June 25, 2009 I am running XP. I have a host, but it is suspended until I pay the monthly fee. What is a miny? It is strange because my server was working installation, just doesn't work some days for some reason. Quote Link to comment Share on other sites More sharing options...
pkedpker Posted June 25, 2009 Share Posted June 25, 2009 y dont u try nginx..... I also run windows XP. Well there shouldn't be any reason why it works sometimes and sometimes it doesn't unless you keep moving your php.ini or php folder Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 25, 2009 Share Posted June 25, 2009 A mini is just a barebones server that can be run even off of a flash drive. Also your WAMP install sounds really quirky. You say it was a working install how do you know that? Did you load a .php file and have it work? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 25, 2009 Author Share Posted June 25, 2009 Yes, this file I am talking about has displayed, with some errors, obviously, but another page I have been working on also displayed and now only the code displays. Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 26, 2009 Share Posted June 26, 2009 Well then obviously your server configuration is broken. This is the wrong forum for such an issue. But the likely cause is that appache has not started the php engine, if it is throwing it directly. You are going to have to either troubleshoot or reinstall. Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted June 26, 2009 Author Share Posted June 26, 2009 Okay, I found out how to view the files. I thought I could view this from the folder, but I have to type in the address: localhost/filename, but now when I submit the form, I receive this error: Parse error: parse error in C:\wamp\www\do_addtopic.php on line 15 Can someone tell me what a parse error is and how to fix it as well? Quote Link to comment Share on other sites More sharing options...
WolfRage Posted June 29, 2009 Share Posted June 29, 2009 What is the code for line 15 of that file? Also what are at a minimum the lines above and below that line? Quote Link to comment Share on other sites More sharing options...
twilitegxa Posted July 1, 2009 Author Share Posted July 1, 2009 Here are lines 9-17: //connect to server and select database $conn = mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("smrpg",$conn) or die(mysql_error()); //create and issue the first query $add_topic = "insert into forum_topics values ('', '"$_POST['topic_title']"', now(), '"$_POST['topic_owner']"')"; mysql_query($add_topic,$conn) or die(mysql_error()); Does that help any? Quote Link to comment Share on other sites More sharing options...
947740 Posted July 1, 2009 Share Posted July 1, 2009 The first thing I notice is your $add_topic variable: $add_topic = "INSERT INTO forum_topics VALUES ('', '".$_POST['topic_title']."', now(), '".$_POST['topic_owner']."')"; You just forgot periods to do string concatenation. I don't know if that will make a difference, though. Quote Link to comment 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.