PHP Coding Help
#1

Hey guys, I'm currently trying to learn how to get better at PHP coding and am making a system for a server I play on's Sheriffs Department for dispatching. I am having a bit of trouble doing a few things. I need to find out what to put to modify a mysql column. The name of columns are badge and status. I already have the other stuff sorted out, to get the username from where it's typed in the box, but need to know what to put meaning the second section is either "Set Badge" or "Set Status" and I need to make it so it changes that in the mysql for their row. (Sorry if I confused you :P)

Thanks in advance.

SIMLIFIED:

How do I make it so whatever I input to the text box is what the specified mysql column changes to
Reply
#2

Use an HTML form or AJAX, up to you. Most importantly, make sure you don't allow SQL injection.
Reply
#3

Would be best to use AJAX.
Reply
#4

INSERT to insert a record
UPDATE to update a record


To do what you want use the UPDATE function.

For example
This is a textboxl:
-------------------------------------------
| Set Badge |
| #9582 |

Button:
-----------
| Submit |
-----------

When you use the UPDATE function it will update the X record.

So lets you're an admin you logged in you want to set an officers b adge number.

You go to lets say..

Admin CP >> Set Badge.

"Enter Officers Name"

"Mark_Weston" and lets say my account is user id 857

setbadge.php?userid=857

This shows up:

-------------------------------------------
| Set Badge |
| # |

Button:
-----------
| Submit |
-----------

You enter a badge number press submit

and the UPDATE record will insert the new badge number into the SQL.


Its kind of hard to explain, but is that what you want to do?


That's how I made my web based MDC.
Reply
#5

All these replies are useless (except maybe Mark's). He's asking how to write a SQL query for what he is trying to achieve. He explicitly said, "I already have the other stuff sorted out, to get the username from where it's typed in the box".

Anyway, as I understand it, you have a form that allows you to set a specific player's badge number.
I'm not sure what the table name and column names are but this should point you in the right direction.
Код:
UPDATE users SET badge='12345' WHERE user_id=42
Reply
#6

Quote:
Originally Posted by DaRealShazz
Посмотреть сообщение
All these replies are useless (except maybe Mark's). He's asking how to write a SQL query for what he is trying to achieve. He explicitly said, "I already have the other stuff sorted out, to get the username from where it's typed in the box".

Anyway, as I understand it, you have a form that allows you to set a specific player's badge number.
I'm not sure what the table name and column names are but this should point you in the right direction.
Код:
UPDATE users SET badge='12345' WHERE user_id=42
Yeah I've tried this before but I want it to set whatever I put in the box



So it sets whatever is put in the Badge part to the username that is entered above. I can also change it from username to User ID as the way the login system works every registered user has an ID.
Reply
#7

Код:
UPDATE users SET badge='{$badge_val}' WHERE user_id='{$user_val}'
replace $badge_val and $user_val with your PHP vars.

Also ensure that you protect from things like SQL Injection.
Reply
#8

I believe I have it sorted out but for some reason I'm getting this when I try to open the file on localhost.
Код:
Parse error: syntax error, unexpected 'users' (T_STRING) in C:\xampp\htdocs\cad\setbadge.php on line 26
Here is whats inside the file

PHP код:
<html>
<head>
<style type="text/css">
a { text-decoration:none }
button {
  color: #00FF00;
  border: 1px solid #00FF00;
  background: #000000;
  font-weight: bold;
}
</style> 
<title>SASD CAD - Set Badge</title>
</head>
<body bgcolor="black" text="00FF00" alink="00FF00" link="00FF00" vlink="00FF00">
<font face="Lucida Console">
<br /><br /><p align=center>
<?php
    
require("common.php"); 
    
    
UPDATE users SET badge='{$badge_val}' WHERE user_id='{$user_val}'
?><center>
<h1>Set Badge</h1> 
<form action="setbadge.php" method="post"> 
    Username:<br /> 
    <input type="text" name="username" value="<?php echo $user_val?>" /> 
    <br /><br /> 
    Badge:<br /> 
    <input type="badge" name="badge" value="<?php echo $badge_val?>" /> 
    <br /><br /> 
    <input type="submit" value="Submit" /> 
</form> 
<a href="supervisor.php">Go Back</a>
</center>
Reply


Forum Jump:


Users browsing this thread: 2 Guest(s)