Click here to Skip to main content
Rate this: bad
good
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!
 
<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>";
 
?>
 

 
Thank you very much!
Posted 8-Mar-13 3:40am
namo77470
Comments
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
good
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\"">";
</form>
See http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.double[^] for more details.
  Permalink  
Comments
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 350
1 Jochen Arndt 190
2 Richard MacCutchan 135
3 Sergey Alexandrovich Kryukov 130
4 DamithSL 105
0 OriginalGriff 6,045
1 DamithSL 4,601
2 Maciej Los 4,087
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,310


Advertise | Privacy | Mobile
Web04 | 2.8.141220.1 | Last Updated 8 Mar 2013
Copyright © CodeProject, 1999-2014
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