Aureole Posted July 22, 2007 Share Posted July 22, 2007 'Cause when I submit my form I get a white screen and nothing is getting added to the database. <?php if (isset($_POST['submitted'])) { include("http://www.veraci7y.net/connectme.php"); if (empty($_POST['title'])) { echo 'You did not enter a title.'; } else { $t = $_POST['title']; } $c = $_POST['category']; if (empty($_POST['shortstory'])) { echo 'You did not enter a short story.'; } else { $s = $_POST['shortstory']; } if (empty($_POST['fullstory'])) { echo 'You did not enter a full story.'; } else { $f = $_POST['fullstory']; } $a = $_POST['author']; $m = $_POST['memberid']; if ($t && $s && $f) { $query = "INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('$t', '$c', '$s', '$f', '$a', '$m')"; $result = @mysql_query($query); if ($result) { echo 'News posted successfully.'; } else { echo 'News could not be added.'; } } else { echo ' All fields are required.'; } } ?> Quote Link to comment Share on other sites More sharing options...
keeB Posted July 22, 2007 Share Posted July 22, 2007 Then, there's something wrong with your code include("http://www.veraci7y.net/connectme.php"); That's it. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 I don't see how there's anything wrong with that. ??? Enlighten me? Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 If it's just the include() that is wrong then can't someone tell me what's up with it...I'm guessing it'd take 20 seconds to explain and I'm new to coding in PHP so I have no idea why you're saying that there's something wrong with the include() It all looks good to me... ??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2007 Share Posted July 22, 2007 post the code for the script named connectme.php put xxxx in place of your username and password in that script when you post it here Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 <?php DEFINE ('DB_USER', 'Teh Username'); DEFINE ('DB_PASSWORD', 'Teh Password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'veraci7y_website'); $connectme = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error()); @mysql_select_db (DB_NAME) OR die('Could not select the database: ' . mysql_error() ); ?> Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2007 Share Posted July 22, 2007 Start by removing the @ symbols. I assume that Teh Username and Teh Password are your substitues for the real values Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Yes they are, I'll try removing the @'s. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 I did as you said and I still get a white screen when I submit the form and nothing is added to the database. ??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2007 Share Posted July 22, 2007 <?php if (isset($_POST['submitted'])) { include("http://www.veraci7y.net/connectme.php"); if (empty($_POST['title'])) { echo 'You did not enter a title.'; } else { $t = $_POST['title']; } $c = $_POST['category']; if (empty($_POST['shortstory'])) { echo 'You did not enter a short story.'; } else { $s = $_POST['shortstory']; } if (empty($_POST['fullstory'])) { echo 'You did not enter a full story.'; } else { $f = $_POST['fullstory']; } $a = $_POST['author']; $m = $_POST['memberid']; if ($t && $s && $f) { $query = "INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('$t', '$c', '$s', '$f', '$a', '$m')"; $result = @mysql_query($query); if ($result) { echo 'News posted successfully.'; } else { echo 'News could not be added.'; } } else { echo ' All fields are required.'; } } ?> That's your code with some indentation of loops to make the code easier to follow. Unless your form has a variable NAMEd submitted and uses the POST method, nothing would be executed at all. Does your form have variables NAMEd correctly? Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 <form id="addnews" action="news/submit.php" method="post"> <label for="title">Title:</label><br /> <input size="10" type="text" name="title" id="title" /><br /> <label for="category">Category:</label><br /> <select name="category" id="category"> <option value="veraci7y" selected="selected">Veraci7y.net</option> <option value="teamveraci7y">Team x Veraci7y</option> <option value="misc">Misc.</option> </select><br /> <label for="shortstory">Short Story:</label><br /> <textarea rows="4" cols="25" name="shortstory" id="shortstory">Enter a short summary here.</textarea><br /> <label for="fullstory">Full Story:</label><br /> <textarea rows="4" cols="25" name="fullstory" id="fullstory">Enter the full story here.</textarea><br /> <input type="submit" name="Submit" value="Submit" /> <input type="hidden" name="author" value="<?php echo $member['members_display_name']; ?>" /> <input type="hidden" name="memberid" value="<?php echo $member['id']; ?>" /> </form> Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Looks like I somehow misplaced my hidden input field for submitted. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 I added the submitted input field and still it doesn't work, but instead of a white screen I get "News could not be added." ??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2007 Share Posted July 22, 2007 Change $result = @mysql_query($query); to $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); Tell us what you see now. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Warning: mysql_query() [function.mysql-query]: Access denied for user 'veraci7y'@'localhost' (using password: NO) in /home/veraci7y/public_html/news/submit.php on line 33 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/veraci7y/public_html/news/submit.php on line 33 Error: Access denied for user 'veraci7y'@'localhost' (using password: NO) with query INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('Test', 'veraci7y', '1', '2', 'Aureole', '1') Quote Link to comment Share on other sites More sharing options...
wsantos Posted July 22, 2007 Share Posted July 22, 2007 Well you have to know your connection parameter first...you're not connecting to your db... Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2007 Share Posted July 22, 2007 There's a problem with the database connection variables. Check with your web host to see exactly what they should be. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 That's the thing though, it was working earlier and I haven't changed the variables at all...I've double and triple and quadruple checked them and they are correct... ??? Quote Link to comment Share on other sites More sharing options...
AndyB Posted July 22, 2007 Share Posted July 22, 2007 All that's left - drop the include: <?php DEFINE ('DB_USER', 'Teh Username'); DEFINE ('DB_PASSWORD', 'Teh Password'); DEFINE ('DB_HOST', 'localhost'); DEFINE ('DB_NAME', 'veraci7y_website'); $connectme = mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error()); mysql_select_db(DB_NAME) OR die('Could not select the database: ' . mysql_error() ); if (isset($_POST['submitted'])) { // include("http://www.veraci7y.net/connectme.php"); if (empty($_POST['title'])) { echo 'You did not enter a title.'; } else { $t = $_POST['title']; } $c = $_POST['category']; if (empty($_POST['shortstory'])) { echo 'You did not enter a short story.'; } else { $s = $_POST['shortstory']; } if (empty($_POST['fullstory'])) { echo 'You did not enter a full story.'; } else { $f = $_POST['fullstory']; } $a = $_POST['author']; $m = $_POST['memberid']; if ($t && $s && $f) { $query = "INSERT INTO news (title, category, shortstory, fullstory, author, memberid) VALUES ('$t', '$c', '$s', '$f', '$a', '$m')"; $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); if ($result) { echo 'News posted successfully.'; } else { echo 'News could not be added.'; } } else { echo ' All fields are required.'; } } ?> Quote Link to comment Share on other sites More sharing options...
wsantos Posted July 22, 2007 Share Posted July 22, 2007 just making sure...your db and application run on the same IP? Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 Yeah they are both on the same webserver if that's what you mean, I will try dropping the include and adding it to the file directly. Quote Link to comment Share on other sites More sharing options...
Aureole Posted July 22, 2007 Author Share Posted July 22, 2007 I did that and it now works... ??? Thanks for all the help, it's weird how it works now I removed the include...but oh well. Quote Link to comment Share on other sites More sharing options...
keeB Posted July 22, 2007 Share Posted July 22, 2007 Like i said, it was the include. You're including over HTTP, which would actually include nothing. It would be like you going to the link yourself. You need to include locally. Like include('connectdb.php') 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.