<?php
include("config.php");
if (isset($_POST['submit_val']))
{
$cmeal = mysql_real_escape_string($_POST['meal']);
$meal = "INSERT INTO ebmealplans( MealPlanName, CreatedOn ) VALUES ( '{$cmeal}', NOW() )";
if(!mysql_query($meal, $link))
{
    die("Error : " .mysql_error());
}

$croom = mysql_real_escape_string($_POST['room']);
$ref_key = mysql_insert_id();
$room = "INSERT INTO ebroomtypes( RoomTypeName, CreatedOn ) VALUES ( '{$croom}', NOW() )";
if(!mysql_query($room, $link))
{
    die("Error : " .mysql_error());
}

if($room)
{
    echo "<script> alert('Stored successfully'); </script>";
}
else
{
    echo "<script> alert('Failed to store to database. Contact your administrator'); </script>";
}

mysql_close($link);
echo "<script> location.href='managevouchers.php'; </script>";
}
?>

look at this coding. i stored some values to two tables per form submission ($meal and $room). if values are inserted into database successfully na it should show the alert message. but here i am checking $room only. if i want to check $meal na what should i do? if i put another one like this...

if($meal)
{
    echo "<script> alert('Voucher stored successfully'); </script>";
}
else
{
    echo "<script> alert('Failed to store to database. Contact your administrator'); </script>";
}

it shown the alert message two times. how to avoid that? how to show alert message if values are inserted into mysql tables (more than two tables at a time?)

Do check using if- else statement.
First check for both room and meal, otherwise check for room else meal. Give alert message in each, problem solved

Member Avatar for diafol

I'm not sure if that's what he was asking IIM - I took it to be one annoying popup for all the messages together. I may be wrong. I'm not wrong about the annoying bit though ;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.