Page 1 of 1

Stuck on ticket system

Posted: Tue Jan 24, 2017 1:23 am
by Connor
I've been trying to build a really basic ticket system for hours and i am really stuck on what to do next


The following code is what i have so far, it displays my category and ticket priories from my mysql table, which is great! Buuuttt, i do not have a clue to how i would fill it in (As a user) and then submit it. I've tried loads of things and it just wont insert into my database. Help would be really appreciated, thanks!

(Also, yes i know my coding is horrible, i am extremely bad at it, but it works lol)


Ticket.php

Code: Select all

<?php
include_once 'connect.php';
session_start();

include_once 'logo.php';

?>
 <link href="style.css" rel="stylesheet" type="text/css" />
<div id="login2" div align="center">


<?php
if (isset($_SESSION['player']))
{
  $player=$_SESSION['player'];
}
else
{
  echo "Not Logged in <br><br> <A href='login.php'>Login</a>";
  exit;
}
?>
</div>



<?php
$bypass = 0;
$playerinfo="SELECT * from players where name='$player'";
$playerinfo2=mysql_query($playerinfo) or die("could not get player stats!");
$playerinfo3=mysql_fetch_array($playerinfo2);
include_once 'runcron.php';
include_once 'statpanel.php';
 ?>
 <div id ="pageinfobar">
 Ticket System
 </div>
 <div id ="locations">
 

 <br />
 
 Type of problem:
  <?php
 mysql_connect('localhost', 'root', '');
mysql_select_db('tutorial');

$sql = "SELECT type FROM tickettype";
$result = mysql_query($sql);

echo "<select name='ticketpriority'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['type'] ."'>" . $row['type'] ."</option>";
}
echo "</select>";
?>
 <br>
 <br>
 Select importance:
 <?php
 mysql_connect('localhost', 'root', '');
mysql_select_db('tutorial');

$sql = "SELECT level FROM ticketpriority";
$result = mysql_query($sql);

echo "<select name='ticketpriority'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['level'] ."'>" . $row['level'] ."</option>";
}
echo "</select>";
?>
<br>
 <br>
Describe the problem:
<br>
 <textarea value="" rows="10" cols="50" name="">
 </textarea>
 <br>
 <br>
 
 
</div>
</html>

The code for the ticket system

Code: Select all

Type of problem:
  <?php
 mysql_connect('localhost', 'root', '');
mysql_select_db('tutorial');

$sql = "SELECT type FROM tickettype";
$result = mysql_query($sql);

echo "<select name='ticketpriority'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['type'] ."'>" . $row['type'] ."</option>";
}
echo "</select>";
?>
 <br>
 <br>
 Select importance:
 <?php
 mysql_connect('localhost', 'root', '');
mysql_select_db('tutorial');

$sql = "SELECT level FROM ticketpriority";
$result = mysql_query($sql);

echo "<select name='ticketpriority'>";
while ($row = mysql_fetch_array($result)) {
    echo "<option value='" . $row['level'] ."'>" . $row['level'] ."</option>";
}
echo "</select>";
?>
<br>
 <br>
Describe the problem:
<br>
 <textarea value="" rows="10" cols="50" name="">
 </textarea>

Re: Stuck on ticket system

Posted: Wed Jan 25, 2017 3:53 pm
by hallsofvallhalla

Re: Stuck on ticket system

Posted: Sat Apr 22, 2017 1:18 am
by KyleMassacre
First things first. Get rid of MySQL and look into at a minimum MySQLi. It's 2017 which means your nearing the end of support for that.

Now that is settled, I am going to assume you at least know what $_GET and $_POST is right? $_POST is data that you would normally send through a form. I noticed your code does not include a form which would be a problem. And $_GET is data you get from your URL like what I see in this URL for my response: ?mode=reply&f=71&t=9234. $_GET['mode'] would come out to reply, so on and so forth......

For $_POST the array key ($_POST['key']) would be your input name. That is the data you want to insert into your database.
So without killing your whole learning experience what you need to do is check for the existence of what thy should be typing in, validate it to make sure that's something you want them to enter, and then insert it.

Here are somethings you should look into:
  • isset()
  • array_key_exists()
  • in_array()
  • filter_var()
  • filter_input()