Trouble Inserting New Records

Codes here !

Moderators: macek, egami, gesf

buckibooster
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Mar 07, 2014 10:43 am

Trouble Inserting New Records

Postby buckibooster » Fri Mar 07, 2014 10:50 am

I'm sure that I'm overlooking something simple but I'm having trouble inserting new data into my sql database. Here is the applicable code that I am using:

$cxn=mysqli_connect($host,$user,$password,$database)
or die ("Couldn't connect to the server.");
$result = mysqli_query($cxn, "SELECT * FROM input");
$num = mysqli_num_rows($result);
$num = $num + 1;
$sql_insert = "INSERT INTO input (Counter, Processed, InputDate, Manager, Email, Number, Division, Description, H001, H003, H005, H007, H009, H011, H013, H015, H017, H019, H021, H023, H025, H027, H029, H031, H033, H035, H037, H039, H041, 1401, 1403, 1501, 1503, 1601, 1603, 1701, 1703, 2301, 2303, 2305, 2307, 2309) VALUES ('$num', '$processed', '$inputdate', '$name', '$email', '$number', '$division', '$description', '$cbh002', '$cbh004', '$cbh006', '$cbh008', '$cbh010', '$cbh012', '$cbh014', '$cbh016', '$cbh018', '$cbh020', '$cbh022', '$cbh024', '$cbh026', '$cbh028', '$cbh030', '$cbh032', '$cbh034', '$cbh036', '$cbh038', '$cbh040', '$cbh042', '$cb1402', '$cb1404', '$cb1502', '$cb1504', '$cb1602', '$cb1604', '$cb1702', '$cb1704', '$cb2302', '$cb2304', '$cb2306', '$cb2308', '$cb2310')";
$result = mysqli_query($cxn,$sql_insert)
or die ("Couldn't insert data.");
mysqli_close($cxn);

This code makes the connection but sends me the error message for failed insertion (i.e., Couldn't insert data). I'm wondering if perhaps I've exceeded some limit on the number of fields or string length for the insert string. Any help you can offer will be very much appreciated.

buckibooster
New php-forum User
New php-forum User
Posts: 4
Joined: Fri Mar 07, 2014 10:43 am

Re: Trouble Inserting New Records

Postby buckibooster » Sun Mar 09, 2014 11:31 am

Problem solved! I'm not sure why but I had several fields in my SQL database that were named using numbers only (e.g., 1401, 1603 and 2305). It worked when I added letters to the front of all of these fields. In other words, my field names could not be numbers only. When I mixed letters and numbers in the field names the problem went away.


Return to “mySQL & php coding”

Who is online

Users browsing this forum: Google [Bot] and 1 guest