FPS Camera Control rotation limits

I am kind of new to Unity and don’t have a lot of code experience. I’ve been working on an FPS game and have written the following code:

using UnityEngine;
using System.Collections;

public class fps_control : MonoBehaviour {
	public Rigidbody otherRb;
	public float speed;
	public float turn;
	public float limit_up;
	public float limit_down;
	public GameObject parentObj;

	private float rot;

	void Awake () {
		Cursor.lockState = CursorLockMode.Locked;
		otherRb = parentObj.GetComponent <Rigidbody> ();
		float xstart = Input.mousePosition.x;
		float ystart = Input.mousePosition.y;
	}
	void FixedUpdate () {
		float xturn = Input.GetAxis("Mouse X");
		float yturn = Input.GetAxis ("Mouse Y");
		parentObj.transform.Rotate (0f, xturn * turn, 0f);
		if (transform.rotation.x <= limit_up) {
			if (transform.rotation.x >=limit_down) {
				transform.Rotate (-yturn * turn, 0f, 0f);
			}
			else {
				rot = limit_down;
				transform.rotation = Quaternion.Euler (rot,0f,0f);
			}
		}
		else {
			rot = limit_up;
			transform.rotation = Quaternion.Euler (rot,0f,0f);
		}
	}
}

The problem is that the rotation limits I tried to set for the camera aren’t working (resulting in the character doing some crazy somersaults). What am I doing wrong? Please help, and thank you to anyone who answers (even if your answer is crap… I still appreciate your effort).

For anyone wanting to see the answer to this question, look in the comments. I’m only posting this to close the question, because maccabbe’s answer was posted in the comments instead of here.