legohalflife2man Posted September 12, 2008 Share Posted September 12, 2008 I created a PHP script, in cooperation with MySQL, which allows registered users on my phpBB3 forum to submit news articles about video games and have them displayed on the website. Now, this script worked perfectly when I first created it. Then, I tried adding an AJAX image uploader to it so that people could upload images to go with their news articles, but the AJAX image uploader wasn't doing what I thought it would do, so I removed it. All of a sudden, the PHP news submittion script I made has stopped working. It will not submit the information entered in each form field to the specified database, or any database for that matter. I made sure that I removed every line of code from the AJAX image uploader, and the news submittion script still isn't submitting data to the database. I really need an expert's help on this. Here is the code for my news submittion PHP script. Keep in mind that it contains the phpBB3 configuration header, so it is connected to the proper MySQL database. <?php include("header.php"); switch($_GET["p"]){ case "addnews_sql": if($user->data['is_registered']) { $news_title = $_POST['news_title']; $news_date = $_POST['news_date']; $news_author = $_POST['news_author']; $news_content = $_POST['news_content']; $news_approved = $_POST['news_approved']; $news_image = $_POST['news_image']; $news_spc = $_POST['news_spc']; $news_sxbox = $_POST['news_sxbox']; $news_splaystation = $_POST['news_splaystation']; $news_snintendo = $_POST['news_snintendo']; $news_sggp = $_POST['news_sggp']; $news_smain = $_POST['news_smain']; $news_games = $_POST['news_games']; $sql = "INSERT INTO news (news_title, news_date, news_author, news_content, news_approved, news_image, news_spc, news_sxbox, news_splaystation, news_snintendo, news_sggp, news_smain, news_games) VALUES ('$news_title', '$news_date', '$news_author', '$news_content', '$news_approved', '$news_image', '$news_spc', '$news_sxbox', '$news_splaystation', '$news_snintendo', '$news_sggp', '$news_smain', '$news_games')"; mysql_query($sql); header('Location: ?p=addnews_confirm'); } else { header('Location: /news'); } break; case "addnews_confirm": ?> <div style="float:left;"> <div class="content_grad siteTitle" style="width:<?php echo $content_full_grad_width; ?>px;"> <div class="content_ctl"></div> <div class="content_ctr"></div> <div class="toptitle"> News Article Submitted </div> </div> <div class="content_bg" style="width:<?php echo $content_full_width; ?>px;"> <div class="contenttext"> Your news article has been submitted successfully. It is currently awaiting approval. To edit your news article or to see if it has been approved yet, go to the Community page and view your Awaiting Approvals. <br /><br /> <a href="/community/approvals.php" class="site">Click here to view your awaiting approvals.</a> </div> </div> <div class="content_bot" style="width:<?php echo $content_full_corners_bot_width; ?>px;"> <div class="content_cbl"></div> <div class="content_cbr"></div> </div> </div> <?php break; case "addnews": if($user->data['is_registered']) { ?> <div style="float:left;"> <div class="content_grad siteTitle" style="width:<?php echo $content_full_grad_width; ?>px;"> <div class="content_ctl"></div> <div class="content_ctr"></div> <div class="toptitle"> Write News Article </div> </div> <div class="content_bg" style="width:<?php echo $content_full_width; ?>px;"> <div class="contenttext"> <form action="?p=addnews_sql" method="post"> <table align="center"> <tr> <td style="width:400px;"> <b>News Article Title</b><br /> <span class="siteTextMed">The title of this news article.</span> </td> <td> <b>|</b> <input type="text" name="news_title" class="inputbox" style="width:300px;" value="" /><br /> </td> </tr> <tr> <td colspan="2"> <center>__________________________________________________________________________________________________</center><br /> </td> </tr> <tr> <td style="width:400px;"> <b>Associated Image</b><br /> <span class="siteTextMed">Enter the URL of a small image that you would like to be associated with this news article. <a href="/internal/php/news_image_uploader.php" class="site" style="font-weight:bold;" target="_blank">Click Here to Upload the Image!!!</a> Once you obtain the URL using our uploader, place it in the box to the right.</span> </td> <td> <b>|</b> <input type="text" name="news_image" class="inputbox" style="width:300px;" value="" /><br /> </td> </tr> <tr> <td colspan="2"> <center>__________________________________________________________________________________________________</center><br /> </td> </tr> <tr> <tr> <td style="width:400px;"> <b>Associated Game</b><br /> <span class="siteTextMed">If this news article is about or associated with any game, enter the name of that game here. If it doesn't have to do with any game, leave this blank.</span> </td> <td> <b>|</b> <input type="text" name="news_games" class="inputbox" style="width:300px;" value="" /><br /> </td> </tr> <tr> <td colspan="2"> <center>__________________________________________________________________________________________________</center><br /> </td> </tr> <tr> <tr> <td style="vertical-align:top;width:400px;"> <b>Associated Sections</b><br /> <span class="siteTextMed">Place a check next to each section here that you wish this article to appear in.</span> </td> <td> <b>|</b> <input type="checkbox" name="news_spc" value="1"> PC<br /> <b>|</b> <input type="checkbox" name="news_sxbox" value="1"> Xbox<br /> <b>|</b> <input type="checkbox" name="news_splaystation" value="1"> PlayStation<br /> <b>|</b> <input type="checkbox" name="news_snintendo" value="1"> Nintendo<br /> <?php if($user->data['user_type'] == "3") { ?> <b>|</b> <input type="checkbox" name="news_sggp" value="1"> GGP<br /> <?php } ?> </td> </tr> <tr> <td colspan="2"> <center>__________________________________________________________________________________________________</center><br /> </td> </tr> <tr> <tr> <td style="vertical-align:top;width:400px;"> <b>Main Section</b><br /> <span class="siteTextMed">Of the sections that you chose above, pick one section here that is the main section that this news article should be placed under. (If you only checked one section above, then choose that section here.)</span> </td> <td> <b>|</b> <input type="radio" name="news_smain" value="pc"> PC<br /> <b>|</b> <input type="radio" name="news_smain" value="sbox"> Xbox<br /> <b>|</b> <input type="radio" name="news_smain" value="playstation"> PlayStation<br /> <b>|</b> <input type="radio" name="news_smain" value="nintendo"> Nintendo<br /> <?php if($user->data['user_type'] == "3") { ?> <b>|</b> <input type="radio" name="news_smain" value="ggp"> GGP<br /> <?php } ?> </td> </tr> <tr> <td colspan="2"> <center>__________________________________________________________________________________________________</center><br /> </td> </tr> <tr> <tr> <td colspan="2"> <input type="hidden" name="news_date" class="inputbox" value="<?php echo date("F j, Y"); ?>" /> <input type="hidden" name="news_author" class="inputbox" value="<?php echo $user->data['user_id']; ?>" /> <input type="hidden" name="news_approved" class="inputbox" value="0" /> <b>News Article Content</b><br /> <span class="siteTextMed">Type the content of your news entry below.</span><br /><br /> </td> </tr> <tr> <td colspan="2" style="background:#CCCCCC;padding:0px;width:840px;"> <script language="JavaScript" type="text/javascript"> <!-- function submitForm() { //make sure hidden and iframe values are in sync for all rtes before submitting form updateRTEs(); //change the following line to true to submit form alert("news_content = " + (document.RTEDemo.news_content.value)); return false; } //Usage: initRTE(imagesPath, includesPath, cssFile, genXHTML, encHTML) initRTE("../../images/rt/", "../../internal/rt/", "../../internal/rt/", false); //--> </script> <noscript><p><b>Javascript must be enabled to use this form.</b></p></noscript> <script language="JavaScript" type="text/javascript"> <!-- //build new richTextEditor var news_content = new richTextEditor('news_content'); news_content.html = ''; news_content.width = 840; news_content.cmdFormatBlock = true; news_content.cmdFontName = false; news_content.cmdFontSize = true; news_content.cmdIncreaseFontSize = true; news_content.cmdDecreaseFontSize = true; news_content.cmdBold = true; news_content.cmdItalic = true; news_content.cmdUnderline = true; news_content.cmdStrikethrough = true; news_content.cmdSuperscript = true; news_content.cmdSubscript = true; news_content.cmdJustifyLeft = true; news_content.cmdJustifyCenter = true; news_content.cmdJustifyRight = true; news_content.cmdJustifyFull = true; news_content.cmdInsertHorizontalRule = true; news_content.cmdInsertOrderedList = true; news_content.cmdInsertUnorderedList = true; news_content.cmdOutdent = true; news_content.cmdIndent = true; news_content.cmdForeColor = true; news_content.cmdHiliteColor = true; news_content.cmdInsertLink = true; news_content.cmdInsertImage = true; news_content.cmdInsertSpecialChars = true; news_content.cmdInsertTable = true; news_content.cmdSpellcheck = false; news_content.cmdCut = false; news_content.cmdCopy = false; news_content.cmdPaste = false; news_content.cmdUndo = true; news_content.cmdRedo = true; news_content.cmdRemoveFormat = true; news_content.cmdUnlink = true; news_content.toggleSrc = false; news_content.build(); //--> </script> </td> </tr> <tr> <td colspan="2"> <br /> <center><input type="submit" name="submit" class="button1" value="Submit News Article" /></center> </td> </tr> </table> </form> </div> </div> <div class="content_bot" style="width:<?php echo $content_full_corners_bot_width; ?>px;"> <div class="content_cbl"></div> <div class="content_cbr"></div> </div> </div> <?php } else { ?> <div style="float:left;"> <div class="content_grad siteTitle" style="width:<?php echo $content_full_grad_width; ?>px;"> <div class="content_ctl"></div> <div class="content_ctr"></div> <div class="toptitle"> Please Login to Proceed </div> </div> <div class="content_bg" style="width:<?php echo $content_full_width; ?>px;"> <div class="contenttext"> <form action="/community/ucp.php?mode=login" method="post" id="login"> <table align="center"> <tr> <td> <label for="username"><b>Username:</b></label> </td> <td> <input type="text" tabindex="1" name="username" id="username" size="25" value="" style="width:150px;" class="inputbox" /> </td> </tr> <tr> <td> <label for="password"><b>Password:</b></label> </td> <td> <input type="password" tabindex="2" id="password" name="password" size="25" style="width:150px;" class="inputbox" /> </td> </tr> <tr> <td colspan="2"> <center><span class="siteTextMed"><a href="/community/ucp.php?mode=sendpassword" class="site">I forgot my password</a></span></center> <center><a href="/join" class="site"><b>Not registered? Join GGP today!</b></a><br /><br /></center> <label for="autologin"><input type="checkbox" name="autologin" id="autologin" tabindex="4" /> Log me on automatically each visit</label><br /> <label for="viewonline"><input type="checkbox" name="viewonline" id="viewonline" tabindex="5" /> Hide my online status this session</label><br /> </td> </tr> <tr> <td colspan="2"> <center> <input type="hidden" name="redirect" value="/news/?p=addnews" /> <input type="hidden" name="sid" value="f71b37fd0e11ed613c7552e1da192097" /> <input type="submit" name="login" tabindex="6" value="Login" class="button1" /> </center> </td> </tr> </table> </form> </div> </div> <div class="content_bot" style="width:<?php echo $content_full_corners_bot_width; ?>px;"> <div class="content_cbl"></div> <div class="content_cbr"></div> </div> </div> <?php } break; } ?> Can anyone tell me where the problem is with my script? I really need help getting it to submit data to the database again. Thank you in advance for any help, suggestions, or pointers. Quote Link to comment Share on other sites More sharing options...
mattal999 Posted September 12, 2008 Share Posted September 12, 2008 What error are you getting? Quote Link to comment Share on other sites More sharing options...
legohalflife2man Posted September 12, 2008 Author Share Posted September 12, 2008 I'm not getting any kind of PHP or MySQL error at all. That's the odd thing. It doesn't give an error. Also, it goes right to the confirmation page, which means that the HTML form properly completed its action. Yet, the script does not submit the information to the database. I'm not sure what the problem is, and at this point an error would be nice to see so I can find out what's going on. Should I just re-write the script from scratch and see if that works out? Quote Link to comment Share on other sites More sharing options...
mattal999 Posted September 12, 2008 Share Posted September 12, 2008 change: mysql_query($sql); to mysql_query($sql) or die(mysql_error()); Quote Link to comment Share on other sites More sharing options...
legohalflife2man Posted September 12, 2008 Author Share Posted September 12, 2008 Ah, thank you very much! I was able to see the error message and fix the problem easily. I'll be sure to include that code to show MySQL errors from now on. Thanks again! 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.