0

I'm having this problem

Uncaught SyntaxError: Unexpected end of input

in this line

<?php ... foreach($res as $row) {echo '<input onclick="selectall('.$j.',"flow'.$row['uid'].'","hi'.$row['uid'].'")" type="submit" class="btn btn-primary btn-user btn-block" value="Update" />';} ?>

Output of that line

<input onclick="selectall(5,"flow9C2748C40A24","hi9C2748C40A24")" type="submit" class="btn btn-primary btn-user btn-block" value="Update" />

The problem is here i think

,"flow'.$row['uid'].'","hi'.$row['uid'].'"

because when i remove it, the problem disappear

Appreciate any help !

9
  • Is this inside or outside the <?php ... ?> tags? Commented May 23, 2020 at 7:05
  • @NigelRen inside <?php ... ?> tags Commented May 23, 2020 at 7:07
  • Are you encasing all of this in quotes if its inside PHP? Like this : '<input onclick="selectall('.$j.',"flow'.$row['uid'].'","hi'.$row['uid'].'")" type="submit" class="btn btn-primary btn-user btn-block" value="Update" />' Commented May 23, 2020 at 7:11
  • can you add the proper code - is this inside an echo statement for example? Commented May 23, 2020 at 7:11
  • @John yes of course, i'm using echo 'postedcode' ; Commented May 23, 2020 at 7:13

1 Answer 1

1

There are a couple of functions which should possibly help when it comes to formatting strings - namely printf and sprintf (others in this family also exist) - and these allow you to specify placeholders in the string which are substituted with the arguments provided. Using these helps simplify how the strings are escaped

printf(
    '<input type="submit" onclick="selectall( \'%1$s\', \'flow%2$s\', \'hi%2$s\' )" value="Update" class="btn btn-primary btn-user btn-block" />',
    $j,
    $row['uid']
);
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.