Jump to content


Will not insert info into db table

  • Please log in to reply
2 replies to this topic

#1 Nothadoth

  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 24 June 2006 - 02:25 PM

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):
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>
  <select size='1' name='category'>
  <option selected value='fff'>Site News</option>
  <option value='finalfantasy'>Final Fantasy News</option>
  <center><font size='1'>Date:</font>
    <center><table border='0' cellpadding='0' cellspacing='0' style='border-collapse: collapse' bordercolor='#111111' width='201' id='AutoNumber1'>

      <td height='23'>
      <p align='center'><select size='1' name='date_day'>
      <option selected>01</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>
  <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>
  <textarea rows='10' name='text' cols='40'></textarea><br>
&nbsp;<input type='submit' value='Submit' name='submit'>&nbsp;&nbsp;&nbsp; <input type='reset' value='Clear all' name='Reset'>


createnews.php (Acesses the db and adds the row - i've changed the pass for security):
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 {

// login into the mysql database server 
// 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."; }


#2 AndyB

  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 24 June 2006 - 02:38 PM

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.
Legend has it that reading the manual never killed anyone.
My site

#3 Nothadoth

  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 24 June 2006 - 03:08 PM

Sorry. The other one.

*shrug* Sorry about that. My apologise.

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users