I am trying to create a page that has a form on it that will select a technician and then show his/her schedule in table for on the same page. The problem I am having is that when I click the select button it goes to a blank page. It will not print out the information. I want to have the variable sent to the second php file but I would like the information displayed on the same page instead of going to another page. Could yall please let me know what I am doing wrong?

[EDIT]I should add that I am somewhat new to php and mysql and this is my first project with it other than fooling around at home.

Thanks.

Form code:

<table border="0">
		<tr>
		    <form action="getschedule.php" method="post">
			<td><b>Name: </b></td>
			<td><select name="name">
				<option value="Aaron">Aaron </option>
				<option value="Dustin1">Dustin </option>
			        <option value="Dustin2">Dustin </option>
				<option value="Eric">Eric</option>
				<option value="Erik">Erik</option>
				<option value="Evan">Evan</option>
				<option value="Joe">Joe</option>
				<option value="Jonathan">Jonathan</option>
				<option value="Josh">Josh</option>
				<option value="Shay">Shay</option>
				</select><br />
			</td>
			<td><input type="submit" />
			</td></form></p>
		</tr>
	</table>

variable should be sent to this .php code (should do DB search and print table for schedule):

<?php

	$day = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};
	$y = 0;
	$q = $_GET["name"];	
	
	$con = mysql_connect('localhost', 'username', 'password');
	if (!$con)
	{
		die('Could not connect: ' . mysql_error());
	}
	
	mysql_select_db("schedule", $con);
	
	$sql = "SELECT * FROM technicianschedule WHERE employeename = '".$q."'";
	
	
	$result = mysql_query($sql);
	
	echo $name . "'s Schedule";
	
	echo "<table border='1'>
			<tr>
				<th>Day</th>
				<th>Date</th>
				<th>Location</th>
				<th>Start Shift</th>
				<th>End Shift</th>				
		    </tr>";
		  
	while($row = mysql_fetch_array($result))
	{
		echo "<tr>";
		echo "<td>" . $day[$y] . "</td>";
		echo "<td>" . $row['Date'] . "</td>";
		echo "<td>" . $row['Location'] . "</td>";
		echo "<td>" . $row['StartTime'] . "</td>";
		echo "<td>" . $row['EndTime'] . "</td>";
		echo "</tr>";
		
		$y = $y++;
	}
	
	echo "</table></div>";
	mysql_close($con);
?>
Member Avatar for diafol

You're sending data via 'post' and searching for a 'get' variable. Change the $_GET variable to a $_POST variable. I haven't checked the rest of it.

$day = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};

Is this even working? That is a syntax error, that's now how you declare arrays in PHP.

OK I was able to get it to work but I still cannot get it to display on page. Does anyone know how to keep this on the same page without putting the code all in one file?

$day = {"Saturday", "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday"};

Is this even working? That is a syntax error, that's now how you declare arrays in PHP.

You are right...that was not working...fixed it.

Your trying to echo the name but you havnt declared $name here:

echo $name . "'s Schedule";

you could change it to

echo $q . "'s Schedule";

or put $name = $q; somewhere before you try and echo the name.

As for the table, code seems fine, you should try checking if anything is being returned if nothing is showin up.

To keep the code all on one page but different files you can move the code elsewhere and use includes and some functions.

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.