PHP Database form CSS - php

I have the following code:
<?php
require "dbconn.php";
$register="SELECT * from register WHERE username = '". $_SESSION['username']."'";
$re = $connect->query($register);
$numrow = $re->num_rows;
echo "<table>";
echo "<tr>";
echo"<th>Username</th>";
echo"<th>Forename</th>";
echo"<th>Surname</th>";
echo"<th>Course</th>";
echo"<th>Subject</th>";
echo"<th>Level</th>";
echo"<th>Date</th>";
echo"<th>Time</th>";
echo"</tr>";
$count = 0;
while ($count < $numrow)
{
$row = $re->fetch_assoc();
extract($row);
echo "<tr>";
echo "<td>";
echo $username;
echo "</td>";
echo "<td>";
echo $firstName;
echo "</td>";
echo "<td>";
echo $surname;
echo "</td>";
echo "<td>";
echo $course;
echo "</td>";
echo "<td>";
echo $subject;
echo "</td>";
echo "<td>";
echo $level;
echo "</td>";
echo "<td>";
echo $date;
echo "</td>";
echo "<td>";
echo $time;
echo "</td>";
echo "</tr>";
$count = $count + 1;
}
?>
It shows the records from the database as a form. I have the following button:
<FORM METHOD="LINK" ACTION="register.php">
<INPUT TYPE="submit" VALUE="Go back to register"></INPUT></form>
No matter what DIV I put the button in, or what CSS I give it. The button always stays ABOVE the form from the database and I cannot get it below the table.
Any ideas?

Firstly, you did not close your table with a </table> tag; it's important that you do.
Then there's METHOD="LINK" which doesn't exist and isn't a valid method.
You either want to use method="post" or method="get".
See this answer on Stack about it:
https://stackoverflow.com/a/11582427/

Related

How to set a table cel color based on its value in PHP?

<?php
$res=mysqli_query($con,"select * from tab_cont");
while($rows = mysqli_fetch_assoc($res))
{
echo "<tr>";
echo "<td>"; echo $rows["id"]; echo"</td>";
echo "<td>";echo $rows["date"]; echo "</td>";
echo "<td>";echo $rows["category"];echo "</td>";
echo "<td>";echo $rows["issue"];echo "</td>";
echo "<td>";echo $rows["cr_status"];echo "</td>";
echo "<td>";echo $rows["priority"];echo "</td>";
echo "<td>"; echo $rows["assigned"]; echo "</td>";
echo "<td>"; echo $rows["escalation"]; echo "</td>";
echo "<td>"; echo $rows["action"]; echo "</td>";
echo "<td>"; echo $rows["resol"]; echo "</td>";
echo "<td>"; ?> <a href="edit.php?id=<?php echo $rows["id"];?>"><button type="button" class=btn btn-success">Edit</button> <?php echo "</td>";
echo "<td>"; ?> <a href="delete.php?id=<?php echo $rows["id"];?>"><button type="button" class=btn btn-danger">Delete</button> <?php echo "</td>";
}
?>
Here I want to set the color for cr_status based on its value "open:green" and "red:close".I tried foreach() code, after echo $rows["cr_status"];echo..... . But I got "unexpected foreach()" error in the browser. The code I used is:
foreach($rows["cr_status"] as $cell)
{
if($cell=="OPEN")
{
echo '<td style="background:#FF6347">'.$cell.'</td>';
}
elseif ($cell=="CLOSE")
{
echo '<td style="background:#228B22">'.$cell.'</td>';
}
}
Can anyone, Plz help me with this code?
$rows["cr_status"] isn't an array, so it makes no sense to loop through it. That's the reason for your error. It's not quite clear what you thought this code was supposed to be doing.
If you just want to set the colour of the cr_status cell (and open/close are the only two statuses), then
echo "<td style='background:".($rows["cr_status"] == "OPEN" ? "#FF6347" : "#228B22")."'>".$rows["cr_status"]."</td>";
should do what you need.

I want to know how to get the selected data on another webpage using PHP

I have use loop to show limited data and each loop i have button to select it.
I have a syntax error in my view.php i dont know what to put in that query
How do i select a row in index.php to view more details in view.php. I tried giving it a name in the echo $rows; loop but i got syntax error too.
This is my code in index.php
<?php
$sqlQuery = mysql_query("SELECT fname FROM info");
while ($rows = mysql_fetch_array($sqlQuery)){
echo $rows['fname'];
echo "<input type='submit' value='Show more info' name='submit' class='btn btn-info'>";
}
?>
-----------------------end code for index------------------------------
this is my code in view
<?php
$sqlQuery = mysql_query("SELECT * FROM info WHERE fname=$_POST['fname']");
echo "<table border='1' width='50%'>";
echo "<tr>";
echo "<td>First Name</td>";
echo "<td>last Name</td>";
echo "<td>Age Name</td>";
echo "</tr>";
while ($rows = mysql_fetch_array($sqlQuery)){
echo "<tr>";
echo "<td>";
echo $rows['fname'];
echo "</td>";
echo "<td>";
echo $rows['lname'];
echo "</td>";
echo "<td>";
echo $rows['age'];
echo "</td>";
echo "</tr>";
}
echo "</table>";
?>
-------------------------------end code for view--------------------
<form method="POST" action="view.php">
<?php
$sqlQuery = mysql_query("SELECT fname FROM info");
while ($rows = mysql_fetch_array($sqlQuery)){
echo "<input type='text' value='".$rows['fname']."' name='fname'>";
echo "<input type='submit' value='Show more info' name='submit' class='btn btn-info'>";
}
?>
</form>
Try this in view.php
echo $_POST['fname'];
$query = "SELECT * FROM info WHERE fname LIKE ".$_POST['fname']."";
echo $query;
check what output are you getting

php mysql how to join two table

I have these codes:
<?php
$records = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('records', $records);
if(isset($_GET['src']))
{
$sql = "SELECT * FROM students where studentnumber like '%{$_GET['src']}%'";
$cnt = mysql_num_rows(mysql_query($sql));
if ($cnt == 0)
{
echo "<script>alert('No Record Found');</script>";
}
$result = mysql_query($sql, $records);
echo "<table border='0' class='table table-striped table-bordered table-hover'>";
echo "<tr class='info'><td width='10%'>Name</td><td width='11%'>Course Yr-Sec</td><td width='10%'>Student Number</td><td width='10%'>Violation</td><td width='10%'>Punishment</td><td width='9%'>Violation Date</td><td width='7%'>Punishment Date</td><td width='5%'>CS Length</td><td width='4%'>CS Done</td><td width='4%'>CS Left</td><td width='17%'><center>Action</center></td></tr></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo $row['Lastname'];
echo ", ";
echo $row['Firstname'];
echo " ";
echo $row['Middleinitial'];
echo "</td>";
echo "<td>";
echo $row['Course'];
echo " ";
echo $row['Year'];
echo "-";
echo $row['Section'];
echo "</td>";
echo "<td>";
echo $row['Studentnumber'];
echo "</td>";
echo "<td>";
echo $row['Violation'];
echo "</td>";
echo "<td>";
echo $row['Punishment'];
echo "</td>";
echo "<td>";
echo $row['Violationdate'];
echo "</td>";
echo "<td>";
echo $row['Punishmentstartdate'];
echo "</td>";
echo "<td>";
echo $row['CSlength'];
echo "</td>";
echo "<td>";
echo $row['CSDone'];
echo "</td>";
echo "<td>";
echo $row['CSLeft'];
echo "</td>";
echo "<td>";
echo "<a href='edit.php?no={$row['ID']}'><input type='button' name='edit' value='Edit' class='btn btn-success'></a>";
echo " <a href='delete.php?no={$row['ID']}'><input type='button' name='delete' value='Delete' class='btn btn-danger'></a>";
echo " <input type='button' name='view' value='View' class='btn btn-info'>";echo "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
$sql = 'SELECT * FROM students';
$result = mysql_query($sql, $records);
echo "<table border='0' class='table table-striped table-bordered table-hover'>";
echo "<tr class='info'><td width='10%'>Name</td><td width='11%'>Course Yr-Sec</td><td width='10%'>Student Number</td><td width='10%'>Violation</td><td width='10%'>Punishment</td><td width='9%'>Violation Date</td><td width='7%'>Punishment Date</td><td width='5%'>CS Length</td><td width='4%'>CS Done</td><td width='4%'>CS Left</td><td width='17%'><center>Action</center></td></tr></tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>";
echo $row['Lastname'];
echo ", ";
echo $row['Firstname'];
echo " ";
echo $row['Middleinitial'];
echo "</td>";
echo "<td>";
echo $row['Course'];
echo " ";
echo $row['Year'];
echo "-";
echo $row['Section'];
echo "</td>";
echo "<td>";
echo $row['Studentnumber'];
echo "</td>";
echo "<td>";
echo $row['Violation'];
echo "</td>";
echo "<td>";
echo $row['Punishment'];
echo "</td>";
echo "<td>";
echo $row['Violationdate'];
echo "</td>";
echo "<td>";
echo $row['Punishmentstartdate'];
echo "</td>";
echo "<td>";
echo $row['CSlength'];
echo "</td>";
echo "<td>";
echo $row['CSDone'];
echo "</td>";
echo "<td>";
echo $row['CSLeft'];
echo "</td>";
echo "<td>";
echo "<a href='edit.php?no={$row['ID']}'><input type='button' name='edit' value='Edit' class='btn btn-success'></a>";
echo " <a href='delete.php?no={$row['ID']}'><input type='button' name='delete' value='Delete' class='btn btn-danger'></a>";
echo " <input type='button' name='view' value='View' class='btn btn-info'>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
}
?>
It contains search, edit, delete and view functions...now my question is...I wanted to join the two tables in the database by the column studentnumber...
my table students contains the column Lastname, Firstname, Middleinitial, Course, Year, Section, Studentnumber, Violation, Punishment, Violationdate, Punishmentstartdate, CSlength, ID, CSDone, CSLeft...now my another table named students2 contains the following rows ID, Studentnumber, Violation, Punishment, Violationdate, Punishmentstartdate, CSlength, CSDone, CSLeft...I want to display the information from my both tables...for example I want to view all the records from database with a studentnumber of 20101000...do I have to inner join the tables?
I'm just a newbie in php...
Thank you in advance... :)
This is a LEFT JOIN. It will return all of the records from students1, as well as any records from students2 where the record has the same studentnumber as a record in students1:
SELECT * FROM students1
LEFT JOIN students2
ON students1.studentnumber = students2.studentnumber
AND students1.studentnumber = 20101000
An INNER JOIN returns only records that produce a match, so you will only get records where there is an identical studentnumber in both students1 and students2. Based on your comments, I believe this is the style you are looking for:
SELECT * FROM students1
INNER JOIN students2
ON students1.studentnumber = students2.studentnumber
AND students1.studentnumber = 20101000
If you want to get your head around using JOINs, I'd recommend trying both of these statements to observe the results. Then try a few other approaches, perhaps using this excellent tutorial on the Coding Horror Blog.

Object not Found 404 Error [duplicate]

This question already has answers here:
Object Not Found error for simple php script
(4 answers)
Closed 9 years ago.
This code returns me a 404 Object Not Found error that I could not solve by modifying the code. And I don't know whether it's a code problem or a localhost problem. I need this to be running for my Final Year Project. Please help. Thanks a lot guys.
<?php
session_start();
require "dbc.php";
echo "<center>";
echo "<img src='web_header.jpg'/>";
echo "</center>";
if($_SESSION['admin_username'])
{
echo "Hello : ".$_SESSION['admin_username'];
echo "<p><a href ='admin_panel.php'>Admin Main</a> || <a href='manage_patients.php'>Manage Patients</a> || <a href ='manage_doctor.php'>Manage Doctors</a> || <a href ='mail_form.php'>Send Email</a> || <a href='logout.php'>Logout</a> ";
echo "<title>Manage Patients</title>";
echo "<h2>Manage Patients</h2>";
$query = mysql_query("SELECT * FROM users");
$numrows = mysql_num_rows($query);
if ($numrows != 0)
{
echo "<table width='1285' height='102' border='1'>";
echo "<tr><th>ID</th><th>Name</th><th>IC Number</th><th>Address</th><th>Mobile Number</th><th>E-mail Address</th><th>Doctor ID</th></tr>";
while ($rows = mysql_fetch_assoc($query))
{
echo "<tr>";
echo "<td width='57' height='33'>";
echo "<center>";
echo $rows['id'];
echo "</center>";
echo "</td>";
echo "<td width='173'>";
echo $rows['name'];
echo "</td>";
echo "<td width='113'>";
echo "<center>";
echo $rows['icnum'];
echo "</center>";
echo "</td>";
echo "<td width='622'>";
echo $rows['address'];
echo "</td>";
echo "<td width='110'>";
echo "<center>";
echo $rows['mobile'];
echo "</center>";
echo "</td>";
echo "<td width='170'>";
echo "<center>";
echo $rows['email'];
echo "</center>";
echo "</td>";
echo "<td width='90'>";
echo "<center>";
echo $rows['docID'];
echo "</center>";
echo "</td>";
echo "</tr>";
}
echo "</table>";
echo"<br>";
echo"</br>";
echo "<form action = 'manage_patients.php method=POST'>";
echo "<p>Assign Doctor ID : ";
echo "<input type='text' name='assign_id' value='Insert Doctor ID Here'>";
echo " for Patient ID : ";
echo "<input type='text' name='id' value='Insert Patient ID Here'></p>";
echo "<input type= 'submit' name='submit' value='Assign Now'>";
echo "</form>";
if (isset($_POST['submit']))
{
require "dbc.php";
$name = mysql_real_escape_string($_POST['assign_id']);
$id = mysql_real_escape_string($_POST['id']);
$query = mysql_query("UPDATE users SET docID='$assign_id' WHERE id='$id'");
echo "Doctor ID Successfully Assigned for Patient ID : $name ";
echo "<p>Refresh page to view changes.</p>";
}
}
}
else
{
header("location:index.html");
}
?>
change this
<form action = 'manage_patients.php method=POST'>
to
<form action = 'manage_patients.php' method='POST'>
If you are getting a 404 Error, it means that the page could not be found. So it is most likely not a problem with your code (that would give you a 500 Server Error). Instead you most likely have used the wrong URL.
<form action = 'manage_patients.php method=POST'>
I find this line of yours a bit suspiscious

PHP postback on submit

I have a question on php postback
My code is :
<?php
if(isset($_POST["Delete"]))
{
echo "DELETE";
}
if(isset($_POST["Modifier"]))
{
echo "Modifier";
}
if(!empty($_SESSION["Status"]))
{
if($_SESSION["Status"] == "u")
{
header("Location: Index.php?Action=Acceuil");
}
if($_SESSION["Status"] == "a")
{
$Connection = mysql_connect("localhost","root") or die(mysql_error());
mysql_select_db("tpw34") or die("Nope.");
$query = "Select * From Products";
$result = mysql_query($query);
While($ligne = mysql_fetch_assoc($result))
{
//Index.php?Action=AdminDeleteProduct&Delete=".$ligne["ProductID"]."
echo "<form method='POST' Action='#'>";
echo "<table border='1'>";
echo "<tr>";
echo "<td colspan='2'><center><img width='250' height='250' src='".$ligne["Image"]."'/></center></td>";
echo "</tr>";
echo "<tr>";
echo "<th>Nom du produit :</th>";
echo "<td>".$ligne["ProductName"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<th>Prix :</th>";
echo "<td>".$ligne["Prix"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<th>Description :</th>";
echo "<td>".$ligne["Description"]."</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='2'h><input type='Submit' value='Delete' name='Delete'/><input type='Submit' value='Modifier' name='Modifier'/></td>";
echo "</tr>";
echo "</table>";
echo "<br>";
echo "</form>";
}
}
}
?>
My Question is : I want to get the ProductID of the item ( in the table ) to be in the $_POST["Delete"] and $_POST["Modifier"] but i dont wanna change the text on the button. I want to keep DELETE and MODIFIER. I have read many things on the web but i dont find the correct answer.
Include a hidden form value for ProductID. Then you can retrieve the value in $_POST['ProductID']
echo "<input type=hidden name='ProductID' value='" . $ligne["ProductID"] . "'>";
You could work with sessions, where you can temporarily save your information.
Sessions
Or like Tim Dearborn suggested, use a hidden input to send it with the next form submit.

Categories