Jump to content


Photo

Help - won't insert data in to the row.


  • Please log in to reply
1 reply to this topic

#1 Nothadoth

Nothadoth
  • Members
  • PipPipPip
  • Advanced Member
  • 119 posts

Posted 24 June 2006 - 11:04 AM

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>
  <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>";

}

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 {

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."; }

}


#2 fenway

fenway
  • Staff Alumni
  • MySQL Si-Fu / PHP Resident Alien
  • 16,199 posts
  • LocationToronto, ON

Posted 24 June 2006 - 04:11 PM

Echo the output of:

("INSERT INTO news (title,category,smalltext,text,date_day,date_month,date_year) VALUES ('$title','$category','$smalltext','$text','$date_day','$date_month','$date_year')"

And I'll bet you'll see blank values... mainly because of:

$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'] : '');

I don't see you setting any variable other than title... looks like a cut and paste error.

Also, I have no idea why you're storing the date in 3 parts -- it'll make date math almost impossible, and gives you no way to verify the date itself easily.
Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users