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

Edited by Indians

3
Contributors
2
Replies
13
Views
3 Years
Discussion Span
Last Post by diafol
0

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

Edited by IIM

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.