a65 Posted January 1, 2013 Share Posted January 1, 2013 i have created a file editordelete.php from which reffering to another file edit2.php by <td><a href=edit2.php?id=<?php echo($row['id']); ?> and in edit2.php using $var1=$_GET['id']; to edit the date but it is giving Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\practices\edit2.php on line 4 Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 (edited) You need to write your link like so: <td><a href="edit2.php?id={$row['id']}">Your Link</a> Kind regards, Aotb. Edited January 1, 2013 by AoTBuNgLe Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 still it is giving the same error my whole code of editordelete.php is <?php mysql_connect("localhost","root",""); mysql_select_db("mydb"); $query="select * from table5"; $result=mysql_query($query); if (!$result) die(mysql_error()); ?> <table><tr><td>name</td><td>age</td><td>gender </td><td>language1</td><td>language2</td><td>country </td><td>address</td><td>edit</td><td>delete</td></tr> <?php while($row=mysql_fetch_assoc($result)) { ?> <tr> <td><?php echo($row['name']); ?></td> <td><?php echo($row['age']); ?></td> <td><?php echo($row['gender']); ?></td> <td><?php echo($row['language1']); ?></td> <td><?php echo($row['language2']); ?></td> <td><?php echo($row['country']); ?></td> <td><?php echo($row['address']); ?></td> <td><a href="edit2.php?id={$row['id']}">edit</a> </a></td> <td><a href=delete.php?id=<?php echo($row['id']); ?>></a></td> <?php } ?> </table> Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 Have you got your whole code for edit2.php? The error which is showing is related to that line 4 of the edit2.php file. Regards, AoTb. Quote Link to comment Share on other sites More sharing options...
jcbones Posted January 1, 2013 Share Posted January 1, 2013 Disregard that advice, there was nothing wrong with how you had it written. The problem isn't even in that page. It is a parse error, on line 4 of edit2.php, so post the contents of that file... in [ code ] [ /code ] blocks. Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 <?php mysql_connect("localhost","root","")'; mysql_connect_db("mydb"); $var1=$_GET['id']; $query="select * from table5 where id='".$var1."'"; $result=mysql_query($query); $row=mysql_fetch_assoc($result); ?> <FORM method=POST action=update.php> <table> <tr><td>name</td><td><input type=text name=myname value=<?php echo($row['name']); </td> <td>age</td><td><input type=text name=myage value=<?php echo($row['age']); ?></td> <td>gender</td><td><input type=radio name=mygender value=<?php echo($row['gender']); ?></td> <td>language1</td><input type=checkbox name=lang1 value=<?php echo($row['language1']); ?></td> <td>language2</td><input type=checkbox name=lang2 value=<?php echo($row['language2']); ?></td> <td>country</td><input type=select name=mycountry value=<?php echo($row['country']); ?></td> <td>address</td><input type=textarea name=myaddress value=<?php echo($row['address']); ?></td> </tr><table> Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 (edited) Disregard that advice, there was nothing wrong with how you had it written. The problem isn't even in that page. It is a parse error, on line 4 of edit2.php, so post the contents of that file... in [ code ] [ /code ] blocks. Sorry, I was under the impression you had to wrap XHTML attributes in quotations. I thought his table elements were written with PHP and not switching back to HTML mode to write it, which is why I thought the opening and closing php tags were unnecessary. But yes, sorry a65, you need to switch your first link back to how it was because you need to go into PHP mode to get the value to pass. Thank you for re-iterating my last solution though. Regards, AoTB. Edited January 1, 2013 by AoTBuNgLe Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 (edited) The problem could be the single quotation on this line: mysql_connect("localhost","root","")'; I also noticed that you haven't closed the PHP tag in your <form> here: <td><input type=text name=myname value=<?php echo($row['name']); </td> Just a tip also, I'd really put your HTML attributes in in quotes, if only for good practice. I also don't think you need to be echo'ing the value when passing it through the URL, maybe take the echo out and see what value you get. On the first line of edit2.php, try putting this: var_dump($_GET['id']); Regards, AoTb. Edited January 1, 2013 by AoTBuNgLe Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 1, 2013 Share Posted January 1, 2013 i have created a file editordelete.php from which reffering to another file edit2.php by <td><a href=edit2.php?id=<?php echo($row['id']); ?> and in edit2.php using $var1=$_GET['id']; to edit the date but it is giving Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in C:\wamp\www\practices\edit2.php on line 4 When you look at the URL in your address bar when you click on the link - does it have id= and then a number, or no number? It sounds like $row['id']; is not set. You can try doing a print_r($row); Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 the url shows http://localhost/practices/edit2.php?id={$row['id']} Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 1, 2013 Share Posted January 1, 2013 Go back to your original code, the one I quoted. Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 Yea sorry a65 that was my fault. I thought you were using PHP to write the html elements, not knowing you was breakig out of PHP mode and writing the actual HTML stynax. Also, re-read post #8, it might help you. Regards, ATb. Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 yeah i corrected that now after using if(!result) die(mysql_error()); i am getting You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id']}'' at line 1 Quote Link to comment Share on other sites More sharing options...
Love2c0de Posted January 1, 2013 Share Posted January 1, 2013 Can you post both of your updated files, edit2.php and editordelete.php? Regards, AoTB. Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 editordelete.php <?php mysql_connect("localhost","root",""); mysql_select_db("mydb"); $query="select * from table5"; $result=mysql_query($query); if (!$result) die(mysql_error()); ?> <table><tr><td>name</td><td>age</td><td>gender </td><td>language1</td><td>language2</td><td>country </td><td>address</td><td>edit</td><td>delete</td></tr> <?php while($row=mysql_fetch_assoc($result)) { ?> <tr> <td><?php echo($row['name']); ?></td> <td><?php echo($row['age']); ?></td> <td><?php echo($row['gender']); ?></td> <td><?php echo($row['language1']); ?></td> <td><?php echo($row['language2']); ?></td> <td><?php echo($row['country']); ?></td> <td><?php echo($row['address']); ?></td> <td><a href="edit2.php?id={$row['id']}">edit</a> </td> <td><a href=delete2.php?id={$row['id']}">delete</a></td> <?php } ?> </table> edit2.php <?php mysql_connect("localhost","root",""); mysql_select_db("mydb"); $var1=$_GET['id']; $query="select * from table5 where id='".$var1."'"; $result=mysql_query($query); $row=mysql_fetch_assoc($result); print_r($row); ?> <FORM method=POST action=update.php> <table> <tr><td>name</td><td><input type=text name=myname value=<?php echo($row['name']); ?>> </td></tr> <td>age</td><td><input type=text name=myage value=<?php echo($row['age']); ?>></td></tr> <td>gender</td><td><input type=radio name=mygender value=<?php echo($row['gender']); ?>>male <input type=radio name=mygender value=<?php echo($row['gender']); ?>>female</td></tr> <td>language1</td><td><input type=checkbox name=lang1 value=<?php echo($row['language1']); ?>>hindi</td></tr> <td>language2</td><td><input type=checkbox name=lang2 value=<?php echo($row['language2']); ?>>english</td></tr> <td>country</td><td><select name=mycountry value=<?php echo($row['country']); ?>><option>India</option><option>bangladesh</option><option>pakistan</option></td></tr> <td>address</td><td><textarea rows=5 cols=5 name=myaddress value=<?php echo($row['address']); ?>></textarea></td></tr> <tr><td><input type=submit value=update></td></tr></table> Quote Link to comment Share on other sites More sharing options...
a65 Posted January 1, 2013 Author Share Posted January 1, 2013 (edited) using if(!$result) die(mysql_error()); it shows You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'id']}'' at line 1 and in the url field it shows http://localhost/pra...t2.php?id={$row['id']} Edited January 1, 2013 by a65 Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 1, 2013 Share Posted January 1, 2013 Go back to your original code, the one I quoted. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.