Jump to content

php/mysql problem


sliperypete

Recommended Posts

In this piece of code I am trying to update the ticket table in my mysql database based on the ticketid that is passed in the URL.  I am trying to insert data into the solution attribute.  For some reason I cant figure out why it is not working maybe a new set of eyes can help me out.  Thanks in Advance !

<?php
session_start();
include "level2_check.php";
include("config.php");

$status = $_POST['status'];
$solution = $_POST['solution'];

if(isset($_POST['Submit']))
{
$res = mysql_query("SELECT * FROM ticket WHERE ticket_id='$ticketid'");
if (mysql_num_rows($res) > 0)
{
    // found a match
    $sql="UPDATE ticket
        SET solution='$solution'
        WHERE ticket_id='$ticketid'";
    $result = mysql_query($sql) or die(mysql_error());
echo "The ticket is now closed good work!";
} else
{
    echo "There was an error trying to close this ticket please try again";
}
}
?>

<html>
<head>
<title>Close Ticket</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<?php include ("admin_header.html") ?>
</head>
<body>
<?php echo $ticketid; ?>
<h3 align="center">Close Ticket</h3>
<table width="60%" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000000">
<form name="form1" method="post" action="admin_closeticket.php">
<input name="status" type="hidden" id="status" value="0">
<tr>
      <td nowrap align="right">Solution:</td>
  <td height="100"><textarea name="solution" id="solution"></textarea></td>

    </tr>
<tr>
          <td><input type="submit" value="submit"></td>
    </tr>
    </form>

 
</table>
</body>
</html>
Link to comment
Share on other sites

Can you pls try like this
$query="SELECT * FROM ticket WHERE ticket_id='".$ticketid."'"
$res = mysql_query($query);
if (mysql_num_rows($res) > 0)
{
    // found a match
    $sql="UPDATE ticket
        SET solution='".$solution."'
        WHERE ticket_id='".$ticketid."'";
Link to comment
Share on other sites

[quote author=corbin link=topic=116548.msg474922#msg474922 date=1164690511]
Ooo you have register globals on then...

Try changing <form name="form1" method="post" action="admin_closeticket.php"> to <form name="form1" method="post" action="admin_closeticket.php?ticketid=<?=$ticketid;?>">
[/quote]

Yes I haev register globals on...

That code didnt work...
Link to comment
Share on other sites

Did you try concatination the variables.
like this
$query="SELECT * FROM ticket WHERE ticket_id='".$ticketid."'"
$res = mysql_query($query);
if (mysql_num_rows($res) > 0)
{
    // found a match
    $sql="UPDATE ticket
        SET solution='".$solution."'
        WHERE ticket_id='".$ticketid."'";


Can you pls paste the error if any
Link to comment
Share on other sites

[quote author=fiddy link=topic=116548.msg474924#msg474924 date=1164690808]
Can you pls try like this
$query="SELECT * FROM ticket WHERE ticket_id='".$ticketid."'"
$res = mysql_query($query);
if (mysql_num_rows($res) > 0)
{
    // found a match
    $sql="UPDATE ticket
        SET solution='".$solution."'
        WHERE ticket_id='".$ticketid."'";

[/quote]

Didn't help still doesnt work

Keep the suggestions coming guys I will try anything

I also realize it isnt very secure its for a school project and the thing being graded is the backend database the php front end will get me extra points so I just need it to work and look good..
Link to comment
Share on other sites

[quote author=fiddy link=topic=116548.msg474930#msg474930 date=1164692350]
I guess you are not passing the ticketid while clode(submit). Try having a hidden field which has the name as ticketid and value echo in it.
<input type="hidden" name="ticketid" value="<?=ticketid?>">
[/quote]

What would this do for me exactly, im confused ?
Link to comment
Share on other sites

<?php echo $ticketid; ?> -> Does this displays the ticketid after you submit (clicking the close button)

if it does not displays add hidden field like this.So that it will POST you ticket id.

<table width="60%" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000000">
<form name="form1" method="post" action="admin_closeticket.php">
    <input name="status" type="hidden" id="status" value="0">


    <input type="hidden" name="ticketid" value="<?=ticketid?>">


    <tr>
      <td nowrap align="right">Solution:</td>
    <td height="100"><textarea name="solution" id="solution"></textarea></td>

    </tr>
  <tr>
          <td><input type="submit" value="submit"></td>
    </tr>
    </form>
Link to comment
Share on other sites

When I put that code in this happens:

before I type in the solution in the text box the ticket ID is displayed because I have this on the page:
<?php echo $ticketid; ?>

Once I type out the solution and hit close it returns me back to the close ticket page and the ticket id is not in the URL anymore and the code above doesnt display anything.

So once I hit close it seems everything is lost....
Link to comment
Share on other sites

Its the same as above but it has changed alot:

<?php
session_start();
include "level2_check.php";
include("config.php");

$status = $_POST['status'];
$solution = $_POST['solution'];

if(isset($_POST['Submit']))
{
  $query="SELECT * FROM ticket WHERE ticket_id='".$ticketid."'";
  $res = mysql_query($query);
    if (mysql_num_rows($res) > 0)
{
    // found a match
    $sql="UPDATE ticket
        SET solution='".$solution."'
        WHERE ticket_id='".$ticketid."'";
    $result = mysql_query($sql) or die(mysql_error());
  echo "The ticket is now closed good work!";
} else
{
    echo "There was an error trying to close this ticket please try again";
}
}
?>

<html>
<head>
<title>Close Ticket</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="style.css" rel="stylesheet" type="text/css">
<?php include ("admin_header.html") ?>
</head>
<body>
<?php echo $ticketid; ?>
<h3 align="center">Close Ticket</h3>
<table width="60%" border="1" align="center" cellpadding="1" cellspacing="1" bordercolor="#000000">
<form name="form1" method="post" action="admin_closeticket.php">
    <input name="status" type="hidden" id="status" value="0">


    <input type="hidden" name="ticketid" value="<?=ticketid?>">


    <tr>
      <td nowrap align="right">Solution:</td>
    <td height="100"><textarea name="solution" id="solution"></textarea></td>

    </tr>
  <tr>
          <td><input type="submit" value="submit"></td>
    </tr>
    </form>
</body>
</html>
Link to comment
Share on other sites

if admin_closeticket.php is the same code, it will obviously show the close ticket page only. Please check the DB it its updated. and hope you get the message "The ticket is now closed good work!"

Before that please change if(isset($_POST['Submit'])) to if(isset($_POST['submit']))
Link to comment
Share on other sites

newest problem with this piece of code:

[code]$status = $_POST['status'];
$solution = $_POST['solution'];

if(isset($_POST['submit']))
{
    mysql_query ("UPDATE ticket
        SET status='$status', solution='$solution'
        WHERE ticket_id='$ticketid'") or die(mysql_error());
        echo "The ticket is now closed good work!";
} else
{
    echo "There was an error trying to close this ticket please try again";
}
?>
[/code]

When that goes to execute it automaticly puts this on the screen before I even type in the text box and hit submit:
There was an error trying to close this ticket please try again
Link to comment
Share on other sites

[quote author=fiddy link=topic=116548.msg474973#msg474973 date=1164699183]
Hi,

can you please tell if you get the message "The ticket is now closed good work!"; after clicking the close button. One more in the HTML i dont find the tags for close . Is that located in some other page. Bit confused in this

[/quote]

When I open the admin_closeticket.php page in my web browser it imediatly posts the message:

There was an error trying to close this ticket please try again?>


Before I even put in a value for solution and hit submit....
It looks like it is erroring out before I even hit submit for some reason ...???


What do you mean about the html tags for close ?
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.