FreakingOUT Posted May 15, 2014 Share Posted May 15, 2014 PHP = 5.5.14 MySQL = 5.2.17 I've cloned a mysqli_connect() statement in a 'require' file placed in a non-public access location on the server. It's the same format (and location) currently working fine with another application, EXCEPT i changed the database name to what I need to use for this application, AND added the $con= part on the front end to substitute for the commented out $con= line in the example code I'm modifying to insert data into a new MySQL DB Table. The dB Table is fine and I have Inserted data via myPHPAdmin with no problems. Only two form variables are in the simple PHP script thus far just to test if it will work before proceeding. I've used pseudonames for the actual /home/.... location and filename, and am now Baffled about the Line 2 Error Message I'm getting (below the code). <?php require '/home/myusername/domains/mydomain.com/myclonedrequire.php'; //$con=mysqli_connect("example","uid","pwd","my_db"); // Check connection if (mysqli_connect_errno()) { echo "Failed to connect to MySQL: " . mysqli_connect_error(); } // escape variables for security $year = mysqli_real_escape_string($con, $_POST['year']); $callsign = mysqli_real_escape_string($con, $_POST['callsign']); $sql="INSERT INTO `lqplogs` (`year`, `callsign`) VALUES ('$year', '$callsign'); if (!mysqli_query($con,$sql)) { die('Error: ' . mysqli_error($con)); } echo "1 record added"; mysqli_close($con); ?> ERROR Message: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in (above file & location) on line 2 There are NO '\' characters in any of my files. Here is the simple Form file code: <?php ?> <html: <head><title></title></head> <body> <form action="insert.php" method="post"> YEAR: <input type="text" name="year"> CALLSIGN: <input type="text" name="callsign"> <input type="submit"> </form> </body> </html> <?php ?> Thanks for any assistance! -FreakingOUT Quote Link to comment Share on other sites More sharing options...
FreakingOUT Posted May 15, 2014 Author Share Posted May 15, 2014 Got a couple hours of sleep and just corrected <html: to <html> in the submit script, but still getting the Error Message. - FreakingOUT Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 15, 2014 Share Posted May 15, 2014 (edited) errors like this are typically caused by copy/pasting code that was 'published' using a non-ascii character set and the characters may display correctly on a web page, but in the actual .php source code they aren't what they appear to be. i would delete and RETYPE the first two lines in your file. also, the posted code contains a php syntax error starting at about line 17. are you sure that's the actual file being saved/put onto your server that the first error is occurring in? Edited May 15, 2014 by mac_gyver Quote Link to comment Share on other sites More sharing options...
FreakingOUT Posted May 15, 2014 Author Share Posted May 15, 2014 errors like this are typically caused by copy/pasting code that was 'published' using a non-ascii character set and the characters may display correctly on a web page, but in the actual .php source code they aren't what they appear to be. i would delete and RETYPE the first two lines in your file. also, the posted code contains a php syntax error starting at about line 17. are you sure that's the actual file being saved/put onto your server that the first error is occurring in? Yes, the missing " error was corrected - sorry. I did more research about the error and made sure to delete any trailing spaces, etc. from the copy & paste. Just re-typed the first 2 lines as you suggested in hopes that might solve the problem, but still get the same Error Message. Baffling ;-( - FreakingOUT Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 15, 2014 Share Posted May 15, 2014 does the posted code start at line one of the file or is there any sort of html/xml markup before that point? are you using a dedicated programming editor or some other means of creating/editing files? are you FTP'ing this file to your server or what? i would create a new empty file with just an opening php tag and see if it produces any errors when you request it (this could be a broken php installation.) Quote Link to comment Share on other sites More sharing options...
FreakingOUT Posted May 15, 2014 Author Share Posted May 15, 2014 does the posted code start at line one of the file or is there any sort of html/xml markup before that point? are you using a dedicated programming editor or some other means of creating/editing files? are you FTP'ing this file to your server or what? i would create a new empty file with just an opening php tag and see if it produces any errors when you request it (this could be a broken php installation.) No html/xml markup. I'm using NotePad & WordPad {SIGH}, and SmartFTP for uploading to the server (I use this no problem with many other files). On a whim, I did another pass at deleting/retyping stuff, and now got these error messages: Warning: mysqli_connect() [function.mysqli-connect]: (42000/1044): Access denied for user 'myname@'localhost' to database 'myuid_test' in /home/myuid/mydomains/in myrequirefile.php on line 3 Failed to connect to MySQL: Access denied for user 'eric'@'localhost' to database 'myuid_test' Warning: mysqli_real_escape_string() expects parameter 1 to be mysqli, boolean given in <snip> on line 13 Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in <snip> on line 19 Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in <snip> on line 20 Error: The "access denied" rang a bell about some past .php file access to the particular database where I added the new Test Table (but not problems accessing or using it via myPHPAdmin). So I modified the html & php scripts to attempt an INSERT of a single variable into a *different* test database & Table that I can read test data from and now got this Error: Error: Duplicate entry '' for key 'PRIMARY' At least I'm now connecting to something without the initial Line 2 Errors, but with NO idential/duplicate entry in what I tried to Insert, need to figure out what's going on. I did a Google search and found a bunch of explanations which included droping the Table and re-creating, but for several reasons that would be a major hassle at the moment. I'll keep digging. Thanks, mac_gyver! - FreakingOUT Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted May 15, 2014 Share Posted May 15, 2014 notepad and certainly wordpad are NOT programming editors. there are a number of free programming editors, such as notepad++ - http://notepad-plus-plus.org/ the duplicate entry error is because you are inserting a duplicate value in a column that's defined as the primary key for your table. you shouldn't be providing a value at all for a primary index, it should be an autoincrement value supplied by the database itself. Quote Link to comment Share on other sites More sharing options...
FreakingOUT Posted May 15, 2014 Author Share Posted May 15, 2014 notepad and certainly wordpad are NOT programming editors. there are a number of free programming editors, such as notepad++ - http://notepad-plus-plus.org/ the duplicate entry error is because you are inserting a duplicate value in a column that's defined as the primary key for your table. you shouldn't be providing a value at all for a primary index, it should be an autoincrement value supplied by the database itself. Thanks for the notepad++ tip. Years ago I used Dreamweaver which worked well and recently tried a PHP Editor trial install that didn't work out too well. GREAT NEWS... I know cleaning up the copy & paste was part of the solution as you recommended. I decided to go-for-the-Gold and via myPHPAdmin created the full blown 32 column table I end to use (there will only be about 100 records total, so dispensed with splitting into separate tables & Foreign Keys for this one). Further modified the submit & insert scripts (and mysqli_connect 'require' file) and took a new Test Drive. Here was the result out-of-the-gate: 1 record added BINGO :^) I had tried to delete the Primary Key in the other database via myPHPAdmin, but the ALTER command kept wanting to add it back in ;-( Thanks again for your assistance !!! - FreakingOUT Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.