Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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!

<body>
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("wrapper");

if(isset($_POST['update'])){
$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'>
<tr>
<th>ID</th>
<th>ARTICLE</th>
</tr>";

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>";

?>
</body>




Thank you very much!
Posted
Comments
ZurdoDev 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

You need to escape your quote characters inside the string, like:
PHP
echo "<form action="\"index1.php\"" method="\"post\"">";
</form>

See http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double[^] for more details.
 
Share this answer
 
Comments
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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900