send data
-
Depends...is this second form on the same page or a different page?
Chris J www.redash.org
-
This is done with either a $_POST or a $_GET variable. Your can read more info and see some code sample here http://php.net/manual/en/language.variables.external.php[^]
Chris J www.redash.org
-
This is done with either a $_POST or a $_GET variable. Your can read more info and see some code sample here http://php.net/manual/en/language.variables.external.php[^]
Chris J www.redash.org
$_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable $row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global $_POST[t] but it's error
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 "";
echo "";
$result = mysql_query("SELECT * FROM class");
while($row = mysql_fetch_assoc($result))
{
if($_POST[t]==$row[lsname])
{
foreach($row as $key=>$var2)
{
echo "";
}
echo " ";} echo ""; }
echo"
Name
Professor
Capacity
Exam
classtime
$var2
";
?>
please help me I mystify in my project :(
-
$_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable $row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global $_POST[t] but it's error
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 "";
echo "";
$result = mysql_query("SELECT * FROM class");
while($row = mysql_fetch_assoc($result))
{
if($_POST[t]==$row[lsname])
{
foreach($row as $key=>$var2)
{
echo "";
}
echo " ";} echo ""; }
echo"
Name
Professor
Capacity
Exam
classtime
$var2
";
?>
please help me I mystify in my project :(
if you mean what I think you mean: first page:
';
// end your form here...
?>
second page:
-
$_POST and $_GET just for input type but my variable isn't that.this is my code I want when user click on button insert data to database but I can't access to variable $row[lsname],$row[teachername],...even this page and other page?another my question is why variable like$_POST[t] isn't recognaize in function?!!!even I write global $_POST[t] but it's error
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 "";
echo "";
$result = mysql_query("SELECT * FROM class");
while($row = mysql_fetch_assoc($result))
{
if($_POST[t]==$row[lsname])
{
foreach($row as $key=>$var2)
{
echo "";
}
echo " ";} echo ""; }
echo"
Name
Professor
Capacity
Exam
classtime
$var2
";
?>
please help me I mystify in my project :(
When I must debug post, get or session variables I use this at the top of the target page.
<?php
session_start();
echo "<pre>";
print_r($_POST);
print_r($_SESSION);
echo "</pre>";
/// rest of page below here
?>This will allow you to see what is being passed to your target page so you will know if the data is making it or not. I see that you defined your function aa()...but where is it called from?
Chris J www.redash.org
-
When I must debug post, get or session variables I use this at the top of the target page.
<?php
session_start();
echo "<pre>";
print_r($_POST);
print_r($_SESSION);
echo "</pre>";
/// rest of page below here
?>This will allow you to see what is being passed to your target page so you will know if the data is making it or not. I see that you defined your function aa()...but where is it called from?
Chris J www.redash.org
-
no you are calling a javascript function called aa() and that I'm guessing does not exist? remeber php is executed on the server. The onclick is a javascript event that is triggered on the users browser. So you are most likely getting a undefined from the browser if the form submits to itself (i.e. - the scripts name is "reqire.php") But the error I think is wiped as the page reloads. The php function aa() is never called. On a side note, its really bad to: 1) have a database connection based on root, to much access for what is needed. 2) display a password in a forum, big security hole.
Chris J www.redash.org
-
no you are calling a javascript function called aa() and that I'm guessing does not exist? remeber php is executed on the server. The onclick is a javascript event that is triggered on the users browser. So you are most likely getting a undefined from the browser if the form submits to itself (i.e. - the scripts name is "reqire.php") But the error I think is wiped as the page reloads. The php function aa() is never called. On a side note, its really bad to: 1) have a database connection based on root, to much access for what is needed. 2) display a password in a forum, big security hole.
Chris J www.redash.org
-
The function aa() work but I can't access the variable my big problem is I don't know user click in which button to insert data I agree with you but I can't insert in javascript!I think I should solve this problem in another way what's your suggestion?
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>"; }
-
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>"; }