Jump to content

Error In Getting The Id From Previous Page


a65

Recommended Posts

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

<?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>

Link to comment
Share on other sites

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 by AoTBuNgLe
Link to comment
Share on other sites

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 by AoTBuNgLe
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.