-3

I want my php to print something when the user submits.this is the error I get:

Parse error: syntax error, unexpected 'javascript' (T_STRING), expecting ',' or ';' in /homepages/31/d585123241/htdocs/test/xe5/form.php on line 9

This is my code, what can I do to fix it:

<?php
echo "$ret bytes written to file<a href ="javascript:history.go(-1)">go back</a>";
userlond
  • 3,632
  • 2
  • 36
  • 53
parseguy
  • 129
  • 2
  • 17

2 Answers2

4

Use single quotes inside the string

echo "$ret bytes written to file<a href ='javascript:history.go(-1)'>go back</a>";
SQL Hacks
  • 1,322
  • 1
  • 10
  • 15
0

Wrap the string in single quotes instead.

echo $ret.' bytes written to file<a href ="javascript:history.go(-1)">go back</a>';

UPDATE:

There are multiple ways to solve this:

  1. Use single quotes inside the string per @SQL hacks answer
  2. Wrap the string in singe quotes as originally shown in this answer. This requires concatenation of PHP variables.
  3. Escape the double quotes inside the string
    echo "$ret bytes written to file<a href =\"javascript:history.go(-1)\">go back</a>";

I'm sure other solutions are possible but the most valuable approach would be to learn about PHP strings and string operations/functions in general. A good starting point would be here: http://php.net/manual/en/language.types.string.php

BillK
  • 317
  • 2
  • 11