Click here to Skip to main content
15,500,227 members
Home / Discussions / Linux, Apache, MySQL, PHP
   

Linux, Apache, MySQL, PHP

 
GeneralRe: send data Pin
cjoki24-Mar-11 5:55
Membercjoki24-Mar-11 5:55 
GeneralRe: send data Pin
Elham M24-Mar-11 23:17
MemberElham M24-Mar-11 23:17 
GeneralRe: send data Pin
effayqueue25-Mar-11 2:25
Membereffayqueue25-Mar-11 2:25 
GeneralRe: send data Pin
cjoki25-Mar-11 3:52
Membercjoki25-Mar-11 3:52 
GeneralRe: send data Pin
Elham M25-Mar-11 4:15
MemberElham M25-Mar-11 4:15 
GeneralRe: send data Pin
cjoki25-Mar-11 4:32
Membercjoki25-Mar-11 4:32 
GeneralRe: send data Pin
Elham M25-Mar-11 8:05
MemberElham M25-Mar-11 8:05 
GeneralRe: send data Pin
cjoki25-Mar-11 11:02
Membercjoki25-Mar-11 11:02 
This is what I have issues with in your code..


<?php 
	session_start(); 
	echo ($_SESSION[users]);
	echo "$_POST[t]"; // "$_POST[t]" should be $_POST['t']
?>
<html> 
	<form method="post" action="reqire.php">
	<?php 
		require_once ('db.php');
		// never ever show log in data in code to others. I will make a 
		// seperate script just for the connection function and include the page and call the function for the page that will run queries
		$db = new db("root","","regstudent","localhost"); 
		
		function aa()  // function is defined... but not called, this is useless
		{
			require_once ('db.php');
			// calling this again when you could just use the one defined outside of the function like this
			// global $db;....or you could pass the $db as a parameter of the function like aa($db)
			$db = new db("root","","regstudent","localhost");
			
			$db->query("INSERT INTO register(`user`, `lsname`, `teachername`, `classday`, `starttime`, `endtime`, `examtime`)VALUES('$_SESSION[user]','$row[lsname]','$row[teachername]','$row[classday]','$row[starttime]','$row[endtime]','$row[examtime]') ");
			
			echo "one record added"; 
		}
		
		echo "<table border='4' bordercolor='CC0099' width=100% height=20% >";  
		echo "<tr><th>Name</th><th>Professor</th><th>Capacity</th><th>Exam</th><th colspan='3'>classtime</th></tr>";   
		
		// add a die condition in case of failure. In production code it should write to a log, but is ok to display for development
		$result = mysql_query("SELECT * FROM class");   
		 // btw - the * will make a additional query on the db to look up the field names, best practice is to include field names yourself.
		 
		// this is how I would write the die....test it by forcing an error, like an incorrect table name in the query.
		$result = mysql_query("SELECT * FROM class") or die("<br>...LINE ".__LINE__."<br>...SQL: ".$sql."<br>...ERROR: ".mysql_error()."<br>");
		
		while($row = mysql_fetch_assoc($result)) 
		{    
			if($_POST[t]==$row[lsname])  // $_POST[t] should be $_POST['t'], but why do you want to show either 1 record or 0 records?
			{
				foreach($row as $key=>$var2)     
				{       
					// this is risky, the table will look like hell if the db schema changes with more or less
					//	fields than the seven columns expected in the header of this table
					echo "<td align='center'>$var2 </td>"; 
				}    
				echo "<td align='center'><input type='submit'  value='Register'  onclick='aa()'></td> ";    // <-- onclick is to javascript not php...it will not call the php function of defined above.
			}      
			echo "</tr>";    // where is the opening <tr>...?
		}   
		echo"</table>";
	?>
	</form>



This is a framework of how I would structure the same thing...
<?php
	session_start();
	include("resources.php"); // this would contain a list of includes for what was needed within my scripts.
	$dbh=dbconn(); // this function would be found in db.php referenced from resources.php
	if(isset($_POST['action'])) // I name my submits action
	{
		//....process logic in here. You could call your function from here too or take the logic out of the function
	}
	echo "<form action='reqire.php' method='post'>\n";
	//.. your form structure is here....
	echo "</form>\n";
	?>

Chris J
www.redash.org

GeneralRe: send data Pin
Elham M25-Mar-11 22:17
MemberElham M25-Mar-11 22:17 
GeneralRemove a File Using PHP Pin
Haroon Mughal23-Mar-11 3:35
MemberHaroon Mughal23-Mar-11 3:35 
GeneralRe: Remove a File Using PHP Pin
Joan M30-Mar-11 8:48
professionalJoan M30-Mar-11 8:48 
GeneralPHP Tips By Google Master Pin
Haroon Mughal23-Mar-11 3:33
MemberHaroon Mughal23-Mar-11 3:33 
GeneralPHP performance tips Pin
Haroon Mughal23-Mar-11 3:32
MemberHaroon Mughal23-Mar-11 3:32 
Questioncss and link styles Pin
Joan M22-Mar-11 5:59
professionalJoan M22-Mar-11 5:59 
AnswerRe: css and link styles Pin
Luc Pattyn22-Mar-11 6:25
sitebuilderLuc Pattyn22-Mar-11 6:25 
QuestionWhy do images are not shown? Pin
Joan M21-Mar-11 6:43
professionalJoan M21-Mar-11 6:43 
AnswerRe: Why do images are not shown? Pin
Luc Pattyn21-Mar-11 6:50
sitebuilderLuc Pattyn21-Mar-11 6:50 
GeneralRe: Why do images are not shown? Pin
Joan M21-Mar-11 7:10
professionalJoan M21-Mar-11 7:10 
GeneralRe: Why do images are not shown? Pin
Luc Pattyn21-Mar-11 7:22
sitebuilderLuc Pattyn21-Mar-11 7:22 
GeneralRe: Why do images are not shown? Pin
Joan M21-Mar-11 7:22
professionalJoan M21-Mar-11 7:22 
AnswerRe: Why do images are not shown? Pin
Luc Pattyn21-Mar-11 7:24
sitebuilderLuc Pattyn21-Mar-11 7:24 
GeneralRe: Why do images are not shown? Pin
Joan M21-Mar-11 7:47
professionalJoan M21-Mar-11 7:47 
GeneralRe: Why do images are not shown? Pin
Luc Pattyn21-Mar-11 7:52
sitebuilderLuc Pattyn21-Mar-11 7:52 
GeneralRe: Why do images are not shown? Pin
Joan M21-Mar-11 8:09
professionalJoan M21-Mar-11 8:09 
GeneralRe: Why do images are not shown? Pin
Luc Pattyn21-Mar-11 8:17
sitebuilderLuc Pattyn21-Mar-11 8:17 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.