Problem when i add data to the database

hi iam using a local host and the programme is to add data to the database but when i go to the data base to check the data in the joke text i don’t find any thing and the data just blank any help.





<html>
<body>

<form action ="<?php echo $_SERVER['PHP_SELF'];?> "method ="POST">
<textarea name="joketext" rows="10 " cols="40">

</textarea>
<input type="submit" value="GO"/>



</form>



<?php
error_reporting(E_ALL ^ E_NOTICE); 

$dbcnx=mysql_connect('localhost','root','');
    if(!$dbcnx){
       exit  ( "unable to  connect to the the data base server");
       }
       
if (!@ mysql_select_db ('ijdb')){
    exit('unable to locate the joke database at this time');
} 



        
if (isset ($_POST['joketext'])){
    
    
    
    
     $joketext=$_POST['joketext '];
     echo "$joketext"; 
     }
      $sql ="INSERT INTO joke SET 
      joketext='$joketext',
      jokedate=CURDATE()";
       
  
 
    
    
    
    
    
    if (@mysql_query($sql )){
        echo 'your joke has been added';
        
    }
    else{
        
        echo "error adding submitted joke ";
    }


    

?>
</body>

</html>


on the local host

         id      joketext              jokedate
	13 	  	                2010-08-12
	14 	  	                  2010-08-12
 	15 	  	                  2010-08-12
 	16 	  	                  2010-08-12
	17 	  	                  2010-08-12
	18 	  	                  2010-08-12

as you see it is ablank(no data) under the joke text even if i add jusst the id and the joke text increase
thanks in advance


joketext='$joketext'

should be


joketext='" . mysql_real_escape_string($joketext) . "'

http://www.php.net/mysql_real_escape_string

Escapes special characters in a string for use in an SQL statement

it makes the string safe to place in a mysql_query

test’ becomes test\’ for example

let me just remind you again, please always filter user inputs :slight_smile:

$joketext=$_POST['joketext '];

Delete the space after ['joketext

And like RNEL said, sanitize the user input before using it in a query.

thank you very much it helped but i didn’t understand when i use this
joketext=‘" . mysql_real_escape_string($joketext) . "’
in the future

thank you also abeli for your eagerness to learn and trying out all our suggestions. I was once like you here when I was just starting, like 6 years ago. I always post a lot of “please help me” topics

On your own free will, maybe it would not take you that long to comeback and return the favor to the community :slight_smile:

thank you RNEL you r so intelligent and I am so shy :blush:because may be my questions are so easy to u but not to me .