0

I am trying to add products to my database. I am creating a PHP page to allow me to select the artist by name or enter a new one, upload an image, and enter the details of the product.

When I run my code, I am not getting no where forward.
I get an error on this line of my code:

<p>
  <b>Print Name: </b> 
  <input type="text" name="print_name" size="30" maxlength="60"
      value="<?php if (isset($_POST['print_name']))
                       echo htmlspecialchars($_POST['print_name']);?>" />
</p>

The error is:

Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING

Saugat Bhattarai
  • 2,614
  • 4
  • 24
  • 33
manda
  • 9
  • 1

2 Answers2

0

Your code should be like below :

<p>
  <b>Print Name: </b> 
  <input type="text" name="print_name" size="30" maxlength="60" value="<?php echo (isset($_POST['print_name'])) ? htmlspecialchars($_POST['print_name']) : '' ;?>"
/>
</p>

You are using Unary operator in wrong way :

The structure of unary is :

<?php echo (condition) ? true : false ; ?>
Muthu17
  • 1,481
  • 12
  • 20
  • Thank you for your help, but it's still giving the same error: Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in – manda Mar 11 '17 at 11:43
  • Remove htmlspecialchars() function and check. Still you facing the issue ? – Muthu17 Mar 11 '17 at 11:45
  • If you faces the issue still please change as like : {htmlspecialchars($_POST['print_name'])} – Muthu17 Mar 11 '17 at 11:46
  • I have removed the htmlspecialchars() function and checked it, didnt work did this

    Print Name:

    – manda Mar 11 '17 at 11:56
  • still same error – manda Mar 11 '17 at 11:56
  • This might be silly, Give a try, Remove all php code which is inside value="", Still you facing the issue? – Muthu17 Mar 11 '17 at 12:02
  • Thank you very much the error is not for this code now, but i have another error in this code

    /> Existing => if you can help me

    – manda Mar 11 '17 at 12:40
  • the same error as the previous but in different code @Muthu17 – manda Mar 11 '17 at 12:40
  • give us line numbers errors and show us which line is error-line – Sysix Mar 11 '17 at 12:47
0

You can try this you have to start and over curly brackets

<input type="text" name="print_name" size="30" maxlength="60"  value="<?php if (isset($_POST['print_name'])){
echo htmlspecialchars($_POST['print_name']);}?>">
bharat savani
  • 339
  • 5
  • 18