Search code examples
phpmysqlformsidentify

Identifying MySQL ID in a form


Using the following code:

<?php
print"<form name='delete' action="" method='POST'>
<input type='text' name='ID' value=".$info['ID'].">
<input type='submit' value='Delete Car' onclick='deleteRecord(); return false;'>
</form>";
?>

Is giving me the following error message, which in turn won't let me load the page:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in (etc)...

It is meant to get the ID of an MySQL record from user input.

What is wrong with that? I have another file where it works without any problems.


Solution

  • Use this code:

    <form name="delete" action="" method="POST">
        <!-- Use php echo instead of print -->
        <input type="text" name="id" value="<?php echo $info['ID'] ?>">
        <!-- Try not to use inline javascript -->
        <button type="submit" onClick="deleteRecord(); return false"></button>
    </form>
    

    In action="" the quotes where messing with your php, so I recommend not to print html tags with php. Hope it helps