Solved

Strange MySQL behavior

Posted on 2014-01-11
4
403 Views
Last Modified: 2014-01-12
I have a table called BridgeResponse for poll-type answers of questions.


Table BridgeResponse
 
Field              Type         Null    Key
ResponseID int(10)      NO    PRI   auto_increment
QuestionID tinyint(4)   YES   MUL
Ordered tinyint(4)        YES
AnswerText varchar(256) YES
AnswerCount tinyint(4)  YES



Suddenly, my INSERTs of new answers are going to the wrong question id.

The table data looked like this when the problem started.


452  126  1  Very Good  0
453  126  2  Good  0
454  126  3  Fair  0
455  126  4  Poor  0
456  127  1  Very Good  0

Now suddenly every insert insists on using QuestionID 127.


INSERT INTO BridgeResponse Values('',128,1,'Test',0)
Result: Success

gives me

467  127  1  Test  0

and another try

INSERT INTO BridgeResponse Values('',128,2,'Test2',0)
Result: Success

468  127  2  Test2  0

This is happening exactly the same in my phpmyadmin program and in the php script that is supposed to add these new answers.  I echoed out the $questionid from the php script and it was correct before and after the mysql_query insert, so it has to be the database itself, not the code.

Any idea what might be happening here?
0
Comment
Question by:Cornelia Yoder
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 35

Accepted Solution

by:
Dan Craciun earned 500 total points
ID: 39774361
That's exactly how it should behave.

You declared QuestionID as TINYINT, which goes from -128 to 127, so everything bigger than 127 will be stored as 127.

HTH,
Dan
0
 
LVL 35

Expert Comment

by:Dan Craciun
ID: 39774363
For the sake of completeness, the m in TINYINT(m) is used only for display purposes, does not affect the range.

So your code (tinyint(4)) asked the applications to display that value using 4 characters and left padding with spaces as needed.

https://dev.mysql.com/doc/refman/5.0/en/numeric-type-attributes.html
0
 
LVL 83

Expert Comment

by:Dave Baldwin
ID: 39774410
Yep ^^^ what Dan said.
0
 
LVL 27

Author Comment

by:Cornelia Yoder
ID: 39774776
Doh.  

Thanks so much to both of you.  Sometimes fresh eyes see better ....
0

Featured Post

Upcoming Webinar: Securing your MySQL/MariaDB data

Join Percona’s Chief Evangelist, Colin Charles as he presents Securing your MySQL®/MariaDB® data on Tuesday, July 11, 2017 at 7:00 am PDT / 10:00 am EDT (UTC-7).

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question