mattd8752 Posted January 14, 2007 Share Posted January 14, 2007 I am receiving the error:Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/mattd/public_html/note/notepad.php on line 9on the page: http://mattdsworld.theicy.net/note/form.html from the script:[code]<?php $file = "opendoc.txt"; ?>Writing to <?php echo $file; ?>.<br><?php$location = "localhost";$username = "mattd_np";$password = "HIDDEN";$database = "mattd_notepad";mysql_query ("INSERT INTO notepad (username, filename, ip_address, content, key) VALUES ('$_GET['username']','$_GET['file']','$_SERVER['REMOTE_ADDR']','$_GET['content']','$_GET['key']')");?>[/code]The password is hidden, but it is correct. If you are trying it out to see what happens, the ajax/javascript page sends a request for that page with the following js script:[code] function sendRequest(q) { // Open PHP script for requests http.open('get', 'notepad.php?content='+q+'&file=test.txt&key=000000'); http.onreadystatechange = handleResponse; http.send(null); } [/code]as you can see, q is coming from the text area. q is updating onkeyup from the form, so after a letter is entered the user's data is saved. I know this is going to lag my database and mess around with stuff like that, however I am going to be recoding that so please don't comment on that. All I need right now is a fix for the PHP script. If anyone can even tell me what I should do to find the error please say so here. I have spent close to 3 hours debugging and I don't know what I've missed but I've fixed quite a lot of buggy code. Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/ Share on other sites More sharing options...
papaface Posted January 14, 2007 Share Posted January 14, 2007 edit. i will return with the right code in a sec Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160524 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 [quote author=devnerds link=topic=122345.msg504573#msg504573 date=1168790309]edit. i will return with the right code in a sec[/quote]Thanks Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160525 Share on other sites More sharing options...
papaface Posted January 14, 2007 Share Posted January 14, 2007 should be:[code]<?php $file = "opendoc.txt"; ?>Writing to <?php echo $file; ?>.<br><?php$location = "localhost";$username = "mattd_np";$password = "HIDDEN";$database = "mattd_notepad";mysql_query ("INSERT INTO notepad (username, filename, ip_address, content, key) VALUES ('".$_GET['username']."','".$_GET['file']."','".$_SERVER['REMOTE_ADDR']."','".$_GET['content']."','".$_GET['key']."')");?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160526 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 Just so I can know next time, could you tell me what you changed? Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160527 Share on other sites More sharing options...
papaface Posted January 14, 2007 Share Posted January 14, 2007 You were using ' in the $_GET variable which meant that php was coming in and out of the string when it wasnt supposed to. Therefore you have to come out of the string before the variable. Concatenate it into the variable and then go back into the string.e.g.[code]('".$_GET['username']."',[/code]as you can see it starts off with a ' then i use a " to come out of the string and then a . to concatenate it. then i enter the variable and come back into the string with a " and end it with a ' for the values.Sorry if that sounds confusing. Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160529 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 Ok, I understand that now, thankyou. I still have 1 problem. No php errors anymore. But I am not having the file write to database. It has full access and I did add the connection section to the code. I get the output:Writing to opendoc.txt.Connected to MySQLConnected to DatabaseWith the code:[code]<?php $file = "opendoc.txt"; ?>Writing to <?php echo $file; ?>.<br><?php$username = "mattd_np";$password = "HIDDEN";$database = "mattd_notepad";mysql_connect("localhost", $username, $password) or die(mysql_error());echo "Connected to MySQL<br />";mysql_select_db($database) or die(mysql_error());echo "Connected to Database";mysql_query ("INSERT INTO notepad (username, filename, ip_address, content, key) VALUES ('".$_GET['username']."','".$_GET['file']."','".$_SERVER['REMOTE_ADDR']."','".$_GET['content']."','".$_GET['key']."')");?>[/code]and it is running with the proper password on my server. Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160532 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 I also just attached all of the files. I made the password on the php file hidden again, but the rest is un-touched from what is on my server. Please help.[attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160535 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 Sorry for another bump, but I have seen many people read this and no replies. I don't have any complaints about this, but is there a way anyone could suggest I recode the PHP so that it doesn't have this problem. If there is a solution, I am willing to recode everything except the ajax as that has taken me 2hrs at least alone to get it working. (would have been way longer if it wasn't for the tutorials that I took some code from on ajaxfreaks.com). Anyway, thanks in advanced. Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160539 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 Bump, can anyone help? Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160550 Share on other sites More sharing options...
mattd8752 Posted January 14, 2007 Author Share Posted January 14, 2007 Bump... Quote Link to comment https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/#findComment-160583 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.