mercredi 29 mars 2017

PHP: retrieve value from within if statement to use within html input tags on same page

i am trying to retrieve values from an if statement, that is getting the values from a database here is the code i have;

<!DOCTYPE html>
<?PHP
    include('session.php');
    include('recipedbconfig.php');


    if(isset($_POST['submit'])) {
        $postrcpnmesrch = $_POST['rcpnmesrch'];

        if($_SERVER["REQUEST_METHOD"] == "POST") {
            $sql = "SELECT * FROM recipe_table WHERE recipe_name = '".$postrcpnmesrch."'";
            $result = mysqli_query($db, $sql);
            $row = mysqli_fetch_assoc($result);
        }
    }
?>
<html>
    <head>
        <title>Fresh Veg Admin, Edit Recipes</title>
        <link rel=stylesheet type="text/css" href="/FVRC/FVRC.css">
    </head>
    <body>
        <h1>Fresh Veg Admin, Edit Recipes</h1>
        <p>User:<b> <?PHP echo $login_session; ?></b>, logged in.</p>
        <form action="/FVRC/addeditrecipes.php">
            <button type="submit">Back</button>
        </form>
        <br/>
        <hr/>
        <table>
            <form method="POST">
                <tr>
                    <td>
                        <input type="text" placeholder="Search for recipes" name="rcpnmesrch">
                    </td>
                    <td>
                        <button type="submit">Search</button>
                    </td>
                </tr>
            </form>
        </table>
        <br/>
        <hr/>
        <form action="editrecipecheck.php" method="POST">
            <table cellspacing=0 cellpadding=5>
                <tr>
                    <td>
                    </td>
                    <td>
                        <label>Recipe Name:</label>
                    </td>
                    <td>
                        <input type="text" placeholder="Recipe Name" name="rcpnme" value="<?php echo $row['recipe_name']; ?>" required>
                    </td>
                </tr>
                <tr>
                    <td>
                        <label>Ingredient One:</label>
                    </td>
                    <td>
                        <input type="text" placeholder="Ingredient" name="ingnme1" required>
                    </td>

i need the values that the $row array contains, so it can be referenced to in the inputs:

<td>
    <input type="text" placeholder="Recipe Name" name="rcpnme" value="<?php echo $row['recipe_name']; ?>" required>
</td>

but as it is local i cant figure it out, i may just be having a brain fart moment, any help would be appreciated

all i get as an error message is this:

<br />
<b>Notice</b>:  Undefined index: recipe_name in <b>E:\Program Files\xampp\htdocs\FVRC\editrecipe.php</b> on line <b>52</b>
<br />

Aucun commentaire:

Enregistrer un commentaire