Php code that is like a public variable in java?
MYSQL DATA: table schedule
ID | Subject | Day | Slot
1 | Math | MWF | 1
2 | Math | MWF | 0
3 | PE | TTH | 2
4 | Math | Sat | 0
In the Data above I already get how to subtract the slot to 1 when I ADD Schedule to the student and now I already Confucius when I Delete the Schedule on the student the slot will also update to + 1 to specific subject. I just use the same variable that i use in ADD schedule and i just change the - sign to + sign to add, When I run my code my variable is undefined I use one page only.
Code for update the slot for add schedule then subtract the slot:
textslot = $_post['txtslot'];<br>
textwholenumber = $_post['wholenumber'];<br>
$sql = "UPDATE schedule ". "SET Slot = $textslot - $textwholenumber". "WHERE Subject = '$textsubject' and Day = '$textday'";
Code for update the slot for delete schedule then add the slot:
$sql = "UPDATE schedule ". "SET Slot = $textslot + $textwholenumber". "WHERE Subject = '$textsubject' and Day = '$textday'";
the$textslot
and$textwholenumber
in the delete code is undefined?
Answer
Solution:
You need to prefix variable name with the
$
symbol to declare a variable, try this;The
<br>
elements are not valid PHP, end the PHP code with the closing?>
or use theecho
function to output these linebreaks. I suspect you don't need them at all, try removing them altogether.Read up on SQL Injection, your SQL statement is exposed to this. Try parametised queries to overcome this.
Hope it helps!