-3

im trying to store some data in mysql using php,

$description="Hi, My Name is Nilesh C. Narvekar, I am a Dog Trainer since last 12 years experience in this field. also I am participate my trained dogs in DOG SHOWS (in Obedience class as well as Breed Shows) So Please Contact me on My Cell no. 9920 338835 I teach HEEL (walk), STAY, SIT, SHAKE HAND (Right / Left), DOWN, RECALL, Retrieve (Ball / Any Article) SALUTE, REST, SLEEP, ROLL, SPEAK, ATTACK, SEARCHING, PERSONAL PROTECTION, GUARD AND Much & More I use Positive Reinforcement training System i.e. (first I give more Exercise for reducing Dogs energy level then doing more practice with dogs and then after I use some treats for giving Dogs attention and concentration to me in training session)";

$sql = "INSERT INTO pet_trainer(name, description, address, city, area, contact, email, timing, latitude, longitude)
                            VALUES 
                            (
                            '"$name"',
                            '"$description"',
                            '"$address"',
                            '"$city"',                       
                            '"$area"',
                            '"$contact"',
                            '"$email"',
                            '"$timing"',
                            '$lat',
                            '$long'
                            )";

when i am trying to execute this the $sql variable does not take all details it shows like this because of large description.

INSERT INTO pet_trainer(image, name, description, address, city, area, contact, email, timing, latitude, longitude)
                            VALUES 
                            ('',
                            'Nilesh C. Narvekar',
                            '\'Hi, My Name is Nilesh C. Narvekar, I am a Dog Trainer since last 12 years experience in this field. also I am participate my trained dogs in DOG SHOWS (in Obedience class as well as Breed Shows) So Please Contact me on My Cell no. 9920 338835 I teach HEEL (walk), STAY, SIT, SHAKE HAND (Right / Left), DOWN, RECALL, Retrieve (Ball / Any Article) SALUTE, REST, SLEEP, ROLL, SPEAK, ATTACK, SEARCHING, PERSONAL PROTECTION, GUARD AND Much & More I use Positive Reinforcement training System i.e. (first I give more Exercise for reducing Dogs energy level then doing more practice with dogs and then after I use some treats for giving Dogs attention and concentration to me in training session)\'',
                            'Andheri  Mumbai',
                            'Mumbai',

and when i decrease size of $description then $sql take all data. is php variable have some limit to store string character? so what can i do? please help me. thank you.

Rahul Patel
  • 5,248
  • 2
  • 14
  • 26
Pratik
  • 23
  • 1
  • 7
  • 3
    what is the type of description column in database? – F.E.A Aug 17 '16 at 13:32
  • 2
    what field type and length is `description` in your db? – Professor Abronsius Aug 17 '16 at 13:32
  • @RahulPatel don't use mysql_*-functions anymore. For your example, it's better if he uses `mysqli_real_escape_string()`, but not mysql. – UeliDeSchwert Aug 17 '16 at 13:33
  • 2
    @ManuToMatic Don't use that function manually. Do use prepared statements with placeholder values. – tadman Aug 17 '16 at 14:07
  • 1
    You should have a look at an ORM like [Doctrine](http://www.doctrine-project.org/) or [Propel](http://propelorm.org/) because these will make inserting data a lot more convenient. The way you're composing the query here with string interpolation is extremely problematic, it creates a [SQL injection bug](http://bobby-tables.com/) because you haven't [escaped your values](http://bobby-tables.com/php). – tadman Aug 17 '16 at 14:09
  • i used varchar(10000) @ Enes Apaydın , RamRaide – Pratik Aug 18 '16 at 05:00

2 Answers2

2
  1. Go to phpMyAdmin, go to your table pet_trainer and look at the description column settings (click on the tablename in phpMyAdmin, then click structure)

    SQL dB Structure setting

    You have a couple of choices:

    • text
    • varchar(max length of content)

    If you simply want to store raw text or html text, then I suggest you use text as the type setting of the column pet_trainer.

  2. Secondly, check the first variable's value that isn't shown anymore (in your example : $contact ) if this variable has something wrong in its value (i.e. special character or something like that) it might block the further sotrage of the SQL query)

  3. And Finally, since this whole question has basically nothing to do with the SQL system, but simply a php variable that will not store the full length of a simple string maybe repose you question. Stop looking for SQL query fixes, since you are not having an SQL problem.

    The way you are showing / explaining it, you have an error concatenating variables in a long string, which shouldn't be a problem for PHP.. (The above only counts if you are printing the variable in PHP and not on the SQL server)

    If you want me to help you or anyone else for that matter, then (in the case of my last description) show us how you declare the variables and what their values are...

    You update your question and I continue to update my answer :)

EDIT : reacting to your comment saying you used varchar(10000), don't do that if you want a long content string, use text, that's what it's for :)

Rafael Lambelin
  • 286
  • 2
  • 10
0

yeahh.

i write all parameter/value in single line and its working properly now.

$sql = "INSERT INTO pet_trainer(name, description, address, city, area, contact, email, timing, latitude, longitude) VALUES('"$name"','"$description"','"$address"','"$city"','"$area"','"$contact"','"$email"', '"$timing"','$lat','$long')";

Pratik
  • 23
  • 1
  • 7