HELP! new to php, cant insert into database using pdo.

Hi, I have problem with inserting stalls into my database, i have a foodCourtID which is from another table as a foreign key and i have problems inserting data into my database. Can anyone please take a look and help out? Thanks!
This is my createStalls.php // basically this is the html.

<?php require_once('../header.php'); ?>
    <h2>Stalls</h2>
    <hr>
    <p></p>
    </div>
    <form action="adminHandleStalls.php" method="post" enctype="multipart/form-data">
    <table>
        <tr>
            <td>Stall Name</td>
            <td>: <input type="text" name="stallName" /></td>    
        </tr>
        <tr>
            <td>Stall Image</td>
            <td>:  <input type="file" name="stallImage"></td>    
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td align="right"><input type="submit" name="submit" value="Set New FoodCourt"/></td>    
        </tr>
    </table>
    </form>
<?php require_once('../footer.php'); and this is my handleStalls.php // to handle the store <?php require_once('../databaseStorage/dbFunction.php'); require_once('/adminHandleFoodCourt.php'); if(empty($stallName) && empty($stallImage)){ echo "Error!"; header("Location: ../admin/adminCreateStalls.php"); }else{ $sqlStr = $db->prepare("INSERT INTO stalls (stallName, stallImage, foodCourtID) VALUES (?,?,?)"); $sqlStr->execute([$_POST['stallName'], $_POST['stallImage'], $_SESSION['foodCourtID']]); header("Location: ../index.php"); } Thanks a loads!

Are you getting an error?

There is no error, but i cant seem to insert the inputs into the database, i do not know why, sorry i am new at php coding.

Put this at the top of each of your PHP pages

[php]error_reporting(E_ALL);
ini_set(“display_errors”, 1);
[/php]

After you do that, does it show an error?

Yes.
Notice: Undefined index: foodCourtID in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\WADCA1Project\admin\adminHandleStalls.php on line 12

Notice: Array to string conversion in C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\data\localweb\WADCA1Project\admin\adminHandleStalls.php on line 12

In your original message you said this.

and this is my handleStalls.php // to handle the store

Did you mean adminHandleStalls.php ?

When dealing with code, we can’t make any assumptions…

Yes, sorry i made a typo error, its adminHandleStalls.php

Sponsor our Newsletter | Privacy Policy | Terms of Service