Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

PHP Error

Fatal error: Uncaught exception 'mysqli_sql_exception' with message 'Incorrect integer value: '' I have receive this error message and can anyone tell me how to fix it? The column datatype is year(4) . Should I change the datatype to int instead?

2 Answers

Todd Anderson
Todd Anderson
4,260 Points

Can you share a snippet of the code?

html: <div> <label>Unit Number</label> <input type="text" id = "unitnum" name = "unitnum" maxlength = "11" value="" > <label> Make</label> <input type ="text" name ="vmake" id ="vmake" value =""/> <label> Model</label> <input type ="text" name ="vmodel" id ="vmodel" value =""/> </div> <div> <label> Year</label> <input type ="text" name ="vyear" id ="vyear" value ="" /> <label> License Plate#</label> <input type ="text" name ="vlic_num" id ="vlic_num" value ="" /> <label> License State</label> <input type ="text" name ="vlic_state" id ="vlic_state" value ="" /> </div> <div> <label>Vin#</label> <input type ="text" name ="vvin_num" id ="vvin_num" maxlength = "17" value =""> <label>Description</label> <select name = "vdescrip" id = "vdescrip" > <option> Select</option> <option value ="3.4 Ton"> 3.4 Ton</option> <option value ="Box Van"> Box Van</option> <option value ="Install Van"> Install Van</option> <option value ="E250 Cargo"> E250 Cargo</option> <option value ="1/2 Ton"> 1/2 Ton</option> </select> <label>Vehicle Use</label> <select name="vuse" id="vuse" value =""/> <option> Select</option> <option value = "Farm"> Farm</option> <option value = "Commercial"> Commercial</option> <option value = "Service"> Service</option> <option value = "Pleasure"> Pleasure</option> <option value = "Retail"> Retail</option> <option value = "For Hire"> For Hire</option> </select> </div> <div> <label>Inspection Due</label> <input type ="text" name ="vinsdue" id ="vinsdue" value ="" /> <label>Tag Due</label> <input type ="text" name ="vtagdue" id ="vtagdue" value ="" /> <label>Driver Name</label> <input type ="text" name ="vdname" id ="vdname" value ="" /> </div> <div> <label>Mileage</label> <input type ="text" name ="vmileage" id ="vmileage" maxlength = "6" value =""/> <label>Cost</label> <input type ="text" name ="vcost" id ="vcost" maxlength = "6" value ="" /> </div> <div> <label>Comments</label> <div style ="margin-top:-10px;margin-left:85px;"> <textarea name="vcomment" id ="vcomment" value ="" rows ="4" cols="100" maxlength="300"></textarea>
</div> </div>

insert code: if(isset($_POST['vinst_insert'])){ //query $insert_inv = "INSERT INTO veh_inventory(veh_make, veh_model, veh_year, veh_license, veh_licstate, veh_vin, veh_desrip, veh_use, veh_inspdue, veh_tagdue, veh_driver, veh_mileage, veh_cost, veh_comment) VALUES('$vmake','$vmodel','$vyear','$vlic_num','$vlic_state','$vvin_num' ,'$vdescrip','$vuse','$vinsdue','$vtagdue','$vdname','$vmileage','$vcost' ,'$vcomment')";

    $insert_result = mysqli_query($con,$insert_inv);
    $result = mysqli_fetch_assoc($insert_result);
    if(!$result){
     if(mysqli_affected_rows($con)>0){
       echo("data inserted successfully");
     }else{
       echo("data not inserted successfully");
     }
   }
}