Jump to content

Recommended Posts

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 9
on 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.
Link to comment
https://forums.phpfreaks.com/topic/34126-php-notepad-script-problem/
Share on other sites

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]
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.
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 MySQL
Connected to Database

With 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.
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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.