PDA

View Full Version : Need help with PHP and Mysql coding.



Zdeamon
03-17-2016, 05:45 AM
I am making a GM system where i can monitor activity from website so i dont have to log the Host server to check things.


Ok so heres where im having some issue, I want to pull mysql info from the server and display that information in either a text box or a neater system much like this : 5856 and i have made many systems such as our login system and so on yes the login systems password is MD5 then salted so no need to worry there . Now the way i see the data is here : 5857 , i want to Add text to where the values are being posted but dont know how to do that with the current code im using which i got from this website : http://www.homeandlearn.co.uk/php/php13p2.html




Heres the code i used , its the same as on the websites only my values.



<?PHP

$user_name = "root";
$password = "xxxxxxxxxx";
$database = "log_gmoperator";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM log_gmoperator";
$result = mysql_query($SQL);

while ( $db_field = mysql_fetch_assoc($result) ) {

print $db_field['dwGmID'] . "<BR>";
print $db_field['szCommand'] . "<BR>";
print $db_field['bSuccess'] . "<BR>";
print $db_field['time'] . "<BR>";

}

mysql_close($db_handle);

}
else {

print "Database NOT Found ";
mysql_close($db_handle);

}

?>


Any ideas from all you coder junkies???

Beverleyh
03-17-2016, 06:34 AM
To structure your output like the first image, you would need to echo/print HTML markup to the page, along with the actual data variables. You currently only have <br> tags, which is why there is no neat layout, but if you were to build up a table around your data variables, it would look much neater.

Your next request needs further clarification. You say you want to add text but do you mean that you want to add text to the page by pulling in data that already exists in the database? OR, do you mean that you want to add data to the database via a form (textarea and submit button) on the web page? Where and how do you want to add?

If you clarify your requirement our members will be able to better assess how/whether they can help you.

Zdeamon
03-18-2016, 08:31 AM
Your kidding me right??? why would i want to add data to the database when its a log sql file that is being logged from our server besides i know how to input data from php.


As i stated above i want to pull the sql data then display that data in Neat text boxes such as a form , each form section will have their own identification such as ID , Command , Success , Time.


And Its not my code as i posted the original link to the post i got the code from, Im not trying to sound rude or anything but , did you even understand what i meant?

Nile
03-18-2016, 02:48 PM
Your kidding me right??? why would i want to add data to the database when its a log sql file that is being logged from our server besides i know how to input data from php.
There's no need to get defensive. It's extremely unclear what you want.


As i stated above i want to pull the sql data then display that data in Neat text boxes such as a form , each form section will have their own identification such as ID , Command , Success , Time.
In what context do you want to do this? In your original post, you made it seem like you wanted your output as depicted in the table-formatted image. If you just want to put the queried data in input fields, you can adjust your output. For example:


print "<input type='text' value='" . $db_field['dwGmID'] . "'>";

If that's not what you want, you need to make it more clear. I don't know what you're trying to communicate.

Zdeamon
03-18-2016, 10:31 PM
Sorry about that , i didnt mean to make you guys assume i was being defensive as thats not the cause at all , my goal is to see about having the data displayed in a form like environment that would auto populate without having to manually add the form as you see in firat image as i had to create that manually then added the info , now the reason i want to do this is cause i am also makeing a online item mall with the same script so users can see it from our website. Sorry for going off tho , havent had much luck with things these days.

Zdeamon
03-19-2016, 02:35 AM
Ok so i have bean playing around with the code quite a bit and thank you Nile for your code. im getting closer to what i need. So i made the page smaller and i see exactly the format i need but need the boxes to be wider for the text.

http://i.imgur.com/p9qiKAr.png

I need the page to display as it is on the link but only displays like that when you make the page smaller , This is what i have bean asking but don't know how to correctly ask for it.

And i actually don't want users to be able to delete the text in the boxes so if there is away to make a table view exactly like this , it would be exactly what i needed.

The text forms are a good idea and i like it , however i just need the data that's being pulled from mysql into a table view with the ability to add text in the column's that the data is being displayed in so i can help our staff members understand what each column is.


<?PHP


$user_name = "root";
$password = "xxxxxxxxx";
$database = "Inxxxxxxx Pxx";
$server = "127.0.0.1";

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);

if ($db_found) {

$SQL = "SELECT * FROM log_gmoperator";
$result = mysql_query($SQL);

while ( $db_field = mysql_fetch_assoc($result) ) {

print "<input type='text' value='GMID - " . $db_field['dwGmID'] . "'>";
print "<input type='text' value='Command- " . $db_field['szCommand'] . "'>";
print "<input type='text' value='Suceeded-" . $db_field['bSuccess'] . "'>";
print "<input type='text' value='Time-" . $db_field['time'] . "'>";

}

mysql_close($db_handle);

}
else {

print "Database NOT Found ";
mysql_close($db_handle);

}

?>

Zdeamon
03-19-2016, 03:25 AM
ok i was able to solve my problem , i had the wrong MySQL type and should of used MySQLI.


Heres my final Result http://69.64.52.65/test/GM-OP-Log.php

I would like to thank you guys for trying to help me , I didn't think about having to use MySQLI for this.

W3Schools.com version of this code : http://www.w3schools.com/php/showphpfile.asp?filename=demo_db_select_oo_table

IF you get to this post and my link for the test page doesn't work here's the code that i found on W3Schools but my version


<!DOCTYPE html>
<html>
<head>
<style>
table, th, td {
border: 1px solid black;
}
</style>
</head>
<body>

<?php
$servername = "127.0.0.1";
$username = "root";
$password = "Input your Mysql Password here";
$dbname = "Input your Database Name here";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT dwGmID, szCommand, bSuccess, time FROM log_gmoperator";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
echo "<table><tr><th>GM ID</th><th>Command</th><th>Succeeded</th><th>Time<tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["dwGmID"]. "</td><td>" . $row["szCommand"]. "</td><td>" . $row["bSuccess"]. "</td><td>" . $row["time"]. "</td></tr>";
}
echo "</table>";
} else {
echo "0 results";
}

$conn->close();
?>

</body>
</html>

Deadweight
03-20-2016, 12:15 PM
Im not entirely sure if your ids are in order but if not add this to the end
ORDER BY dwGmID ASC

Also, If i may suggest adding a few things (not sure if you plan to link database table) but try something like this:

First, change the table name to something like this tbl_GmOperatorLog



SELECT
gol.dwGmID, gol.szCommand, gol.bSuccess, gol.time
FROM tbl_GmOperatorLog gol
ORDER BY gol.dwGmID


However, I think you can just call it this way


SELECT
gol.*
FROM tbl_GmOperatorLog glo
ORDER BY gol.dwGmID

This is assuming that the ID column is called dwGmID

Zdeamon
03-20-2016, 09:30 PM
Actually it is in order , we have more than one GM on the server so if i use a command then they use one it will log in that order.


what you see there is exactly how it shows in the database.