0

Okay, so i have created a new support ticket system, but in my ticket search page it keeps giving me errors like undefined variable in line 197. the weird thing is that the variable is defined right above it. Please assist me in this here is a link to the code: http://pastebin.com/AMzRLDK4

I'm trying to make it possible for me to view the support tickets that are open and mark them as read or change the status and to reply to them by going to the pm system. I had it working last night but i must have changed something without realizing its effect.

Thanks in advance, Matt.

1
  • Which variable is it saying is undefined? Commented Apr 9, 2012 at 14:02

1 Answer 1

2

It looks like this is the first time you use $Sid or $Sname in your code. They are inside a code block for the while, which means that is the only place they exist. Also, I think you want to use mysql_fetch_assoc(). It'll actually work with the column names, instead of the indexes. (And probably best off to use the newer MySQLi for several reasons)

while($raw = mysql_fetch_array($ret)){ $Sid = $raw['id']; $Sname = $raw['username']; }

Quick Fix:

$Sid = null; //or 0 whichever makes sense for you
$Sname = null; //or ''
while($raw = mysql_fetch_assoc($ret)){ $Sid = $raw['id']; $Sname = $raw['username']; }

However, with the LIMIT 1 in the MySQL Query, you could drop the WHILE all together

$raw = mysql_fetch_assoc($ret);
if($raw === false)
{
    //Error Condition
}

$Sid = $raw['id'];
$Sname = $raw['username'];
Sign up to request clarification or add additional context in comments.

3 Comments

what do you recommend i do for the best fix? and which line do i insert the code at?
@MattMyers To fix the issue at hand, the undefined variables, I would use the second fix that doesn't have the while. You would be replacing the code on line 188. Beyond that, and especially since this is a login script, look into MySQLi statements. They'll go a long way towards being sure that your data is clean going into your queries. php.net/manual/en/class.mysqli-stmt.php
Thank you so much for the help, but i did deviate from your code sample (Quick Fix) a tad bit because it wasn't showing the username submitted by, so instead of null; after $Sid and $Sname i used the mysql grab memid; and username; i changed the null to memid because it also wouldn't allow me to click on the username outputted and it wouldn't take me to the members page. but it works good now, thank you so much :D

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.