Click here to Skip to main content
13,047,131 members (58,617 online)
Rate this:
Please Sign up or sign in to vote.
See more:
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 8-Mar-13 8:41am
Can you tell us what is wrong? Do you get an error?
namo77 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 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 8-Mar-13 11:54am
There is no point telling me this, please address it to OP.
Prasad Khandekar 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
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2017
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