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 ';'
4
  • What happens if you print_r($alben[$i]) ? Commented Aug 10, 2012 at 19:33
  • i always get the above error message. even with your solution Commented Aug 10, 2012 at 19:35
  • What line is that error on? Maybe the error is elsewhere in the code. Commented Aug 10, 2012 at 19:36
  • The Error is for this line. It says the error is in line 26, and this is the line 26. When i comment it, i don't get the message Commented Aug 10, 2012 at 19:37

2 Answers 2

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"

Sign up to request clarification or add additional context in comments.

1 Comment

Woohoo... this works!! Great, thank you! EVERY Tutorial on the internet shows the wrong solution, but this one works.
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']; ?>">

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.