Dynadot .com transfer sale, only $10.12 with coupon code DYNA12, available while supplies last, ends October 31, 2026.

Goofy MySQL Insertion Issue

Namecheap AuctionsNamecheap Auctions
SpaceshipSpaceship
Spacemail by SpaceshipSpacemail by Spaceship
Watch

Whogister

Established Member
Impact
118
Ok, I am having this MySQL issue that is driving me insane. I never had this problem until after the 1st of the year so I have no idea!

My insertions work fine when I first create my database and do my coding. I wake up the next day and the insertions are broken. They just don't work anymore...

I am thinking it has something to do with my "about" field since I do a quick test by adding only one word in the text field and it works and then I can add more data as normal, everything works again until the next day and it breaks again. Very strange...

Do I need to structure my "about" field another way?
Here is what I have below:

Field:
about

Type:
text

Collation:
latin1_swedish_ci

Null:
no
 
0
Close
The views expressed on this page by users and staff are their own, not those of NamePros.
GoDaddyGoDaddy
It would be good if you could post code
 
0
Close
Which code?
 
0
Close
Are you inserting values programmatically or using an administration app (like phpMyAdmin, MySQL Administrator, etc)?
 
0
Close
It's this form right here
http://www.itsyourforum.com/addforum.php

If I put more than a sentence or two in the description field it does not insert the new row into the DB. But if I just put one word it works fine.

The strange thing is that it was all working fine last night and now all of a sudden it's all goofy like this...
 
0
Close
But what does the actual insertion code look like?
 
0
Close
The "about" is the the description field.

Code:
mysql_query("INSERT into forums
(name,about,main_link,keywords,email,password,verify,cid)
VALUES
('$name','$about','$main_link','$keywords','$email','$password','$verify','$cid')");
 
0
Close
You are not escaping the strings passed to the query. If you put a single quote in your string, the query will fail with an error. You should probably have:

Code:
mysql_query("INSERT into forums
(name,about,main_link,keywords,email,password,verify,cid)
VALUES
('".mysql_real_escape_string($name)."','".mysql_real_escape_string($about)."','".mysql_real_escape_string($main_link)."','".mysql_real_escape_string($keywords)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($password)."','".mysql_real_escape_string($verify)."','".mysql_real_escape_string($cid)."')");
 
0
Close
Also you have a field which reads :
veri fy (with spaces)
 
1
Close
Thanks, I used your code and it worked when I did a test this morning.
Hopefully this will KEEP it working...

qbert220 said:
You are not escaping the strings passed to the query. If you put a single quote in your string, the query will fail with an error. You should probably have:

Code:
mysql_query("INSERT into forums
(name,about,main_link,keywords,email,password,verify,cid)
VALUES
('".mysql_real_escape_string($name)."','".mysql_real_escape_string($about)."','".mysql_real_escape_string($main_link)."','".mysql_real_escape_string($keywords)."','".mysql_real_escape_string($email)."','".mysql_real_escape_string($password)."','".mysql_real_escape_string($verify)."','".mysql_real_escape_string($cid)."')");
 
0
Close
It will. But that code is pretty nasty looking.

I'd recommend pulling the mysql_real_escape_string functions out of the actual query and then keep the query as simple as possible.

Better yet, loop through the $_POST array with foreach and just type the function once and do it in about 2 lines of code:

PHP:
foreach ($_POST as &$var)
    $var = mysql_real_escape_string($var);
 
0
Close
You lost me there... :)
I can do basic coding but that's about it.

I'm the only one that will see it so I don't care about looks.
But if it affects performance than that's a different story.
 
0
Close
DomainEasy: flexible LTO options. Close more domain deals with financing.

We're social

Escrow.com
Spaceship
CryptoExchange.com
Domain Recover

NamePros updates

Quick replies: search, your most used replies, and more on every post
Quick replies are easier to find and use now. The quick reply menu has a search box. Type a few letters to find the reply you want. A...
AIVikings
Catchy
  • The sidebar remains visible by scrolling at a speed relative to the page’s height.
Back