Jump to content

Will not insert info into db table


Nothadoth

Recommended Posts

Hey. I'm kind of new to php but I do know a bit.

I'm writing a news script for my site - based on the tutorial found on here.

It was all working fine but then I edite the error message part myself, and now when I submit news from the newnews.php file, it goes to the createnews.php, says it was successful but when I check the database, it has only submitted a row with blank values in the columns. Can someone tell me why?

newnews.php (Where I fill in the form with the information):
[code]if( !$userdata['user_level'] == 1 ) {
  
  if( $userdata['username'] == "") { $username = "Guest"; } else { $username = $userdata['username']; }
  
  print "Sorry ".$username.", you are not authorised to view this page.";
  } else {

print "<form method='POST' action='http://www.finalfantasyfan.net/createnews.php'>
  <br><p align='center'>Title:<br>
  <input type='text' name='title' size='20' maxlength='20'><br>
  <br>
  Category:<br>
  <select size='1' name='category'>
  <option selected value='fff'>Site News</option>
  <option value='finalfantasy'>Final Fantasy News</option>
  </select>
  <br><br>
  <center><font size='1'>Date:</font>
    <center><table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='201' id='AutoNumber1'>
    <tr>

      <td height='23'>
      <p align='center'><select size='1' name='date_day'>
      <option selected>01</option>
      <option>02</option>
      <option>03</option>
      <option>04</option>
      <option>05</option>
      <option>06</option>
      <option>07</option>
      <option>08</option>
      <option>09</option>
      <option>10</option>
      <option>11</option>
      <option>12</option>
      <option>13</option>
      <option>14</option>
      <option>15</option>
      <option>16</option>
      <option>17</option>
      <option>18</option>
      <option>19</option>
      <option>20</option>
      <option>21</option>
      <option>22</option>
      <option>23</option>
      <option>24</option>
      <option>25</option>
      <option>26</option>
      <option>27</option>
      <option>28</option>
      <option>29</option>
      <option>30</option>
      <option>31</option>
      </select> <select size='1' name='date_month'>
      <option selected value='01'>Jan</option>
      <option value='02'>Feb</option>
      <option value='03'>Mar</option>
      <option value='04'>Apr</option>
      <option value='05'>May</option>
      <option value='06'>Jun</option>
      <option value='07'>Jul</option>
      <option value='08'>Aug</option>
      <option value='09'>Sep</option>
      <option value='10'>Oct</option>
      <option value='11'>Nov</option>
      <option value='12'>Dec</option>
      </select> <select size='1' name='date_year'>
      <option selected value='06'>2006</option>
      <option value='07'>2007</option></select></td>
    </tr>
    </table>
    </center>
  </div>
  <p align='center'>
  Small News:<br>
  <!--webbot bot='Validation' b-value-required='TRUE' i-maximum-length='65' --><textarea rows='3' name='smalltext' cols='40' maxlength='65'>Maximun 65 characters</textarea><br>
  <br>
  News:<br>
  <textarea rows='10' name='text' cols='40'></textarea><br>
  <br>
&nbsp;<input type='submit' value='Submit' name='submit'>&nbsp;&nbsp;&nbsp; <input type='reset' value='Clear all' name='Reset'>
</form>";

}[/code]

createnews.php (Acesses the db and adds the row - i've changed the pass for security):
[code]if( !$userdata['user_level'] == 1 ) {
  
  if( $userdata['username'] == "") { $username = "Guest"; } else { $username = $userdata['username']; }
  
  print "Sorry ".$username.", you are not authorised to view this page.";
  
  } else {

mysql_connect('localhost','noth','disc89');
// login into the mysql database server
mysql_select_db('noth_phpb1');
// select the site's database
// just use the same info you used on the retrieval script

// we're presuming here that you used 'title' and 'text' as the names for your form elements
$title = $title = ( isset($_POST['title']) ? $_POST['title'] : '');
$title = ( isset($_POST['title']) ? $_POST['title'] : '');
$title = ( isset($_POST['category']) ? $_POST['category'] : '');
$title = ( isset($_POST['smalltext']) ? $_POST['smalltext'] : '');
$title = ( isset($_POST['text']) ? $_POST['text'] : '');
$title = ( isset($_POST['news_day']) ? $_POST['news_day'] : '');
$title = ( isset($_POST['news_month']) ? $_POST['news_month'] : '');
$title = ( isset($_POST['news_year']) ? $_POST['news_year'] : '');

// add slashes to the sent info so no escape characters are around (they'll possibly bust the script)
$newsresult = mysql_query("INSERT INTO news (title,category,smalltext,text,date_day,date_month,date_year) VALUES ('$title','$category','$smalltext','$text','$date_day','$date_month','$date_year')");

if( $newsresult == true ) { print "<center><font size='2' color='".$fontc1."><b>'News submitted sucessfully</b></font><br>
Congratulations ".$userdata['username'].", your news was submitted without any problems.<br><br>
<a href='".$BASESIR."' style='text-decoration:none'>Return to the home page</a></center>"; } else { print "There was an error: Your news was not submitted."; }

}[/code]
Link to comment
Share on other sites

Please DO NOT post the same question twice.

[a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=96719&hl=\" target=\"_blank\"]http://www.phpfreaks.com/forums/index.php?...topic=96719&hl=[/a]

Which topic would you like deleted? That one or this?

Well, part of your problem is that your keep re-defining the value of $title and ignoring all the other posted data. Fix that and try again.
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.