0

I'm a PHP-Newbie and want to create a simple Website to manage my CD Collection.

I connect to a MySQL-Database and create for each table a PHP-Array.

No i want to be able to edit my CDs within HTML-Forms and submit it back to the MySQL-Database.

For that i create a for-loop and put each array-varaible into an HTML-Form, so i can edit the text und via submit UPDATE my Database.

I know there is an answer for my question: stackoverflow Answer

But this solution didn't work for me.

One line:

echo "<input name="Titel" type="text" size="30" value="<?php echo $alben[$i]['Titel']; ?>">";   

This line doesn't work, an i don't understand why.

Can someone please help?

EDIT: If i just say:

echo $alben[$i]['Titel'];   

This work. But with the HTML-Form i'm getting this error message:

 syntax error, unexpected T_STRING, expecting ',' or ';'
Community
  • 1
  • 1
ohboy21
  • 4,259
  • 8
  • 38
  • 66

2 Answers2

1

Because you need escape the quotes and remove the 2nd echo

echo "<input name="Titel" type="text" size="30" value="<?php echo $alben[$i]['Titel']; ?>">";

into

echo "<input name=\"Titel\" type=\"text\" size=\"30\" value=\"" . $alben[$i]['Titel'] . "\">";

period is string concatination "a" . "b" becomes "ab"

RonPringadi
  • 1,294
  • 1
  • 19
  • 44
  • Woohoo... this works!! Great, thank you! EVERY Tutorial on the internet shows the wrong solution, but this one works. – ohboy21 Aug 10 '12 at 19:41
1

if you are in php tag use this:

<?php
...
echo '<input name="Titel" type="text" size="30" value="'. $alben[$i]['Titel']; .'">"';
..
?>

if you are in html, use this:

<input name="Titel" type="text" size="30" value="<?php echo $alben[$i]['Titel']; ?>">
Bruno Nardini
  • 461
  • 5
  • 13