hey guys so im trying to display data into text boxes that are fetched from database according to checkbox with value id.

php:

<?php
if(isset($_POST['edit_event']) && isset($_POST['check']))
{
   require "connection.php";
   foreach($_POST['check'] as $del_id)
    {
    $del_id = (int)$del_id;
    $sql = mysql_query("SELECT * FROM event WHERE event_id = '$id' ") or die(mysql_error());
    $rw = mysql_fetch_array($sql);
    }
}
?>

one of the textbox:

<input type="text" name="ename" value="<?php if(@$sql){echo htmlentities (@$rw['event_name']);}?>"

im using the coding i used for a different project but with a little tweek here and there but it doesnt seem to work. as in the textboxes are empty, the data isnt in there.

thanks in advance!

Member Avatar
diafol

$id doesn't exist in your sql - use $del_id

right. haha sorry. changed that but i get an notice in the textbox

<br /><b>Notice</b>: Undefined variable: rw in <b>D:\Xampp\htdocs\EMS2\event.php</b> on line <b>305</b><br />

<?php
if(isset($_POST['edit_event']) && isset($_POST['check']))
{
    require "connection.php";
    foreach($_POST['check'] as $edit_id)
    {
    $edit_id = (int)$edit_id;
    $sql = mysql_query("SELECT * FROM event WHERE event_id = '$edit_id' ") or die(mysql_error());
    $rw = mysql_fetch_array($sql);      
    }
}
?>

Event Name : <input type="text" name="ename" value="<?php if($rw) {echo htmlentities($rw['event_name']);}  ?>" required />

hi nadiam,
i think you are using $rw variable out of the scope. let me know is $rw globally defined variable in your php page?

pls notice

  $rw = mysql_fetch_array($sql);  // you defined here
}  // closed loop here
}  // closed loop here
?>
Event Name : <input type="text" name="ename" value="<?php if($rw) {echo htmlentities($rw['event_name']);} ?>" required />

that might be a problem check it once

let me know the status

happy coding

my php is in the same page as the html and this is the first time $rw is used. so should i not close the loop where indicated?

<?php
    if(isset($_POST['edit_event']) && isset($_POST['check']))
    {
        require "connection.php";
        foreach($_POST['check'] as $edit_id)
        {
            $edit_id = (int)$edit_id;
            $sqls = mysql_query("SELECT * FROM event WHERE event_id = '$edit_id' ") or die(mysql_error());
            $rw = mysql_fetch_array($sqls);     
        }//closed loop
    }//closed loop
?>

html is below the php:

<form name="create" method="post" action="event.php">
<fieldset>
    <legend>Create an Event</legend>
    Event Name : <input type="text" name="ename" value="<?php if($rw) {echo htmlentities($rw['event_name']);} ?>" required />
    <p id="date">
        Event Start: <input type="text" name="datestart" class="date start" size="10"  required /><input type="text" id="date-start" name="timestart" class="time start" size="10" />
    </p>
    <p id="date">
        Event End: <input type="text" name="dateend" class="date end" size="10"  required/><input type="text" id="date-start" name="timeend" class="time end" size="10"  required />
    </p>
    Event Venue: <input type="text" name="evenue" required/><br/>
    <a href="add_guest"><input type="submit" name="submit" value="Create Event" /></a><input type="submit" id="cancel" name="cancel" value="Cancel" />
</fieldset>
</form>

i did so that :

        }
    }
?>

is below </form>
so its like this:

<?php
        }
    }
?>

but it made the edit button not function at all.

Revert the loop code. It is fine.
Variable is created and you can use it next in code.
My question is where do you pick $_POST['edit_event'] in your form?
Because you set condition for fetching data if edit_event is posted.

actually the <form> doesn't start at where i indicated(thought itd be easier) <form> starts here :

<form class="guest-button-wrap" method="post" action="event.php">
<div class="button-wrap">
<input type="button"class="add_event" id="add_event" name="add_event" value="Add Event"/>
<input type="submit" class="del_event" id="del_event" name="del_event" value="Delete Event"/>
<input type="submit" class="edit_event" id="edit_event" name="edit_event" value="Edit Event" />
<a href="add_guest.php"> 
    <input type="button" class="add_guest" id="add_guest" name="add_guest" value="Guest" />
</a>
</div>

above Create Event form and closes somewhere at the near bottom of the page. The processing is at the top before <!DOCTYPE html>

changed the structure

<form class="guest-button-wrap" method="post" action="event.php">
        <div class="button-wrap">
        <input type="submit" class="edit_event" id="edit_event" name="edit_event" value="Edit Event" />
        </div>

        <?php
            if(isset($_POST['edit_event']) && isset($_POST['check']))
            {
                require "connection.php";
                foreach($_POST['check'] as $edit_id)
                {
                    $edit_id = (int)$edit_id;
                    $sqls = mysql_query("SELECT * FROM event WHERE event_id = '$edit_id' ") or die(mysql_error());
                    $rw = mysql_fetch_array($sqls);
                }
            }       
        ?>
        <div id="doverlay" class="doverlay"></div>
        <div id="ddialog" class="ddialog">
        <form method="post" action="event.php"><fieldset>
            <legend>Update Event</legend>
                Event Name&nbsp; : <?php echo "<input type='text' name='en_' value='".$rw['event_name']."'>" ?>
                <p id="date">
                Event Start &nbsp;&nbsp;: <?php echo "<input type='text' name='dates_' class='date start' size='10' values='".$rw['date_start']."' required placeholder='Date' /><input type='text' name='times_' size='10' value='".$rw['time_start']."' required placeholder='Time' />";?>
                </p>
                <p id='date'>
                Event End &nbsp;&nbsp;: <?php echo "<input type='text name='datee_' class='date end' size='10' value='".$rw['date_end']."' required placeholder='Date' /><input type='text' id='tm-end' name='time_' class='time end' size='10' value='".$rw['time_end']."' required placeholder='Time' />";?>
                </p>
                Event Venue&nbsp;: <?php echo "<input type='text' name='ev_' class='ev_' value='".$rw['event_venue']."' required/><br/>";?>
                <input type='submit' name='update' value='Update Event' /></a><input type='submit' id='cancel' name='cancel' value='Cancel' />
        </fieldset></form>
        </div>
</form>

php is before <!DOCTYPE html>

<?php
    if(isset($_POST['edit_event']) && isset($_POST['check']))
    {
        foreach($_POST['check'] as $edit_id)
        {
            require "connection.php";
            $edit_id = (int)$edit_id;
            $sqls = mysql_query("SELECT * FROM event WHERE event_id = '$edit_id' ");
            $z = mysql_fetch_array($sqls);
        }
    }       
?>

button and form opens:

<form method="post" action="event.php">
<input type="submit" name="edit_event" value="Edit Event">

this is the html where the data will be echoed, below button and form

<div id="doverlay" class="doverlay"></div>
<div id="ddialog" class="ddialog">
    <table class="cevent">
    <thead><tr><th>Update Event</th></tr></thead>
    <tbody>
        <tr>
            <td>
            <input type="text" name="en_" value="<?php echo $z['event_name']; ?>">
            </td>
        </tr>
        <tr>
            <td>
            <input type="text" name="dates_" value="<?php echo $z['start_date']; ?>">
            <input type="text" name="times_"  value="<?php echo $z['start_time']; ?>">
            </td>
        </tr>
        <tr>
            <td><input type="text" name="datee_" value="<?php echo $z['end_date']; ?>">
            <input type="text"  name="time_" value="<?php echo $z['end_time']; ?>">
            </td>
        </tr>
        <tr>
            <td><input type="text" name="ev_" value="<?php echo $z['event_venue']; ?>">
            </td>
        </tr>
        <tr>
            <td><input type="submit" name="update" value="Update Event" id="update">
            <input type="submit" id="cancelupdate" name="cancel" value="Cancel" >
            </td>
        </tr>
    </tbody>
    </table>
</div>

this is part of table which is populated by data from database where isset($_POST['check'] gets the 'check' from:

    echo 
    "<tr>
        <td><input type='checkbox' name='check[]' value='$id'>$name
      </td>
     </tr>";

and form is closed down here

</form>

fixed. sort of. i had to restructure how the page works.