Data does not display in text box

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


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

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, like the data isnt in there.

Don’t suppress errors with @
Also I would think you would need the input fields withing the scoop and loop of the query.

<?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 event_name FROM event WHERE event_id = '$edit_id' ") or die(mysql_error());
			$rw = mysql_fetch_array($sql);
			echo '<input type="text" name="ename" value="' . htmlentities($rw['event_name']) . '" />';
		}
	}
?>

the @ coz notice undefine … would show up in the textbox. is there a way without having to echo the textbox?

like it would insert into the textbox value?


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


<?php
if($sql) {
  $eventname = htmlentities($rw['event_name']);
  $startdate = htmlentities($rw['start_date']);
  // and so on for all your other columns
  }
else {
  $eventname = '';
  $startdate = '';
  // and so on for all your other columns
  }
?>
<form name="create" method="post" action="event.php">
		<fieldset>
			<legend>Create an Event</legend>
			Event Name: <input type="text" name="ename" value="<?php echo $eventname; ?>" required/>
			<p id="date">
				Event Start : <input type="text" name="datestart" class="date start" size="10" value="<?php echo startdate; ?>" required/><input type="text" id="date-start" name="timestart" class="time start" size="10" value="<?php if($sql){echo htmlentities ($rw['start_time']);}?>" required/>
			</p>
			<p id="date">
				Event End : <input type="text" name="dateend" class="date end" size="10" value="<?php if($sql){echo htmlentities ($rw['end_date']);}?>" required/><input type="text" id="date-start" name="timeend" class="time end" size="10" value="<?php if($sql){echo htmlentities ($rw['end_time']);}?>" required/>
			</p>
			Event Venue: <input type="text" name="evenue" value="<?php if($sql){echo htmlentities ($rw['event_venue']);}?>" required/><br/>
			<input type="submit" name="submit" value="Create Event" /><input type="submit" id="cancel" name="cancel" value="Cancel" />
		</fieldset>

I haven’t edited all the code, but to me it’s much nicer to do the check outside the html, set a variable for each form attribute, then use those within the form. Much easier to handle what you might want to use for start dates for example if you’re not trying to shoe-horn it all into the form itself. My opinion only, of course.

I’m a bit confused as to what the page does. The title suggests you’re creating an event (to me, that means a new event), so why would any of the data already be there? If you’re editing an existing event, and you’ve got to the form stage by selecting the data based on the id from a previous page, would you want to display the form, or deal with the fact that an id that was in the previous page for the user to select is now missing? Anyway, that’s off the question.

droopsnoot i did try ur way and it didn’t work either i got the same warning and i m still getting the same warning:

<br /><b>Notice</b>: Undefined variable: z in <b>D:\Xampp\htdocs\EMS2\event.php</b> on line <b>298</b><br />
well of course when i did ur way it said Undefined variable for $eventname etc…

so i changed it a bit. not so much just the html structure:

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

<input type=“submit”> 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


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

Error message implies that your query is returning nothing and therefore mysql_fetch_array() does not create the array. Is the value of $edit_id what you would expect it to be when you echo it?

ETA: My point about creating separate variables before you start displaying the form was about your note saying that you suppress error messages so that they don’t appear in your text boxes. By controlling that away from the textbox contents you don’t have to try to deal with it in inline code.


$edit_id =  join(',', array_map('intval', $_POST['check']));
print_r $edit_id;

Parse error: syntax error, unexpected ‘$edit_id’ (T_VARIABLE) in D:\Xampp\htdocs\EMS2\event.php on line 44

that would mean that my code itself is wrong right? okay.

I would say so. Check the line before as well, perhaps a missing ; on the end can cause a parse error on the next line.

im wondering if its not working because edit event table is handled with js and the edit button shows the edit event table when clicked.