Click here to Skip to main content
11,703,617 members (68,692 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: SQL HTML PHP
Hello everyone!

Please I need help updating my database from a html form.

I'm quite new to PHP. I can't figure out where the error is.

Please can anyone help?

Thank you very much!

mysql_connect("localhost", "root", "");
$UpdateQuery = "UPDATE articles_selection SET article = '$_POST[article]' WHERE id ='$_POST[hidden]'";
mysql_query($UpdateQuery, $sql);


$sql = mysql_query("SELECT * FROM articles_selection");
echo "<table border = '1'>
while($record = mysql_fetch_array($sql)){
echo "<form action="index1.php" method ="post">";
echo "<tr>";
echo "<td>" . "<input type = "text" name = "id" value ="  . $record['id'] . " </td>";
echo "<td>" . "<input type = "text" name = "article" value ="  . $record['article'] . " </td>";
echo "<td>" . "<input type = "hidden" name = "hidden" value ="  . $record['id'] . " </td>";
echo "<td>" . "<input type = "submit" name = "Update" value = "update">" . " </td>";
echo "</tr>";
echo "</form>";
echo "</table>";

Thank you very much!
Posted 8-Mar-13 2:40am
ryanb31 at 8-Mar-13 8:41am
Can you tell us what is wrong? Do you get an error?
namo77 at 8-Mar-13 8:48am
Thank you. Yes I get an error (Parse error: syntax error, unexpected 'index1' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\ptest\index1.php on line 30)

That is, on this line: echo "<form action="index1.php" method ="post">";

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

You need to escape your quote characters inside the string, like:
echo "<form action="\"index1.php\"" method="\"post\"">";
See[^] for more details.
Prasad Khandekar at 8-Mar-13 9:32am
Yes you definitely need to escape or else use single quote ' for outer double quotes. One more suggestion why are you outputting multiple forms per row. You should try and move form outside the loop.
Richard MacCutchan at 8-Mar-13 11:54am
There is no point telling me this, please address it to OP.
Prasad Khandekar at 9-Mar-13 12:30pm
Sorry Richard,

My intent was not to address it to you, I was just adding more things to your comment.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 550
1 Maciej Los 530
2 Sergey Alexandrovich Kryukov 381
3 Andy Lanng 294
4 CPallini 195
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web04 | 2.8.150819.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100