Log in

View Full Version : Script error


SilverDragonTears
04-29-2012, 02:04 AM
I don't know how to get this to work with the new script. I've been trying since last night.


$query = "SELECT * FROM ".$GLOBALS['prefix']."tabs WHERE username = '".$GLOBALS['username']."'";
$result = runquery($query);
$num = mysql_numrows($result);

SilverDragonTears
04-29-2012, 07:17 PM
Ok here is what I have so far and it isn't working LOL


function gettabs() {
$formcontent = "";
$data = $adopts->select("tabs", array("username", "name"), "username = '{$username}'")->fetchObject();
$num = count($data);

$i=0;
while ($i < $num) {
$tabname=@mysql_result($data, $i,"name");
$formcontent = $formcontent."<option value='myadopts.php?tab=".$tabname."'>".$tabname."</option>";
$i++;
}
return $formcontent;
}

fadillzzz
04-30-2012, 01:32 AM
Don't mix the old mysql_* functions with PDO. The two are very different.


$result = $adopts->select(...);
while ($row = $result->fetchObject())
{
echo $row->name;
}

SilverDragonTears
04-30-2012, 01:56 AM
ok now I have this.. and still not working. Bear with me.

function gettabs() {
$formcontent = "";
$result = $adopts->select("tabs", array("username", "name"), "username = '{$username}'")->fetchObject();

$i=0;
while ($row = $result->fetchObject()) {
$tabname=@mysql_result($data, $i,"name");
$formcontent = $formcontent."<option value='myadopts.php?tab=".$tabname."'>".$tabname."</option>";
$i++;
}
return $formcontent;
}

Hall of Famer
04-30-2012, 02:28 AM
First of all, you are having an issue Id refer to as 'variable scope'. You are defining a function gettab() without passing any arguments, while the variable $username is undefined as a local variable inside your function. You either have to declare $username as global variable, or pass it as an argument to your function. Read this manual from PHP for reference:
http://php.net/manual/en/language.variables.scope.php

On the other hand, you still use mysql_result() which no longer works with this new script as we are incorporating PDO. I thought Fadillzzz already explained clearly to you not to use mysql functions anymore... Now change this line:


$tabname=@mysql_result($data, $i,"name");
to


$tabname=$row->name;
And now the $tabname will not be malfunctioning. However I strongly recommend you to remove all lines associated with $i since its totally unnecessary.

SilverDragonTears
04-30-2012, 02:33 AM
Ok another thing. I'm suppose to add this...
AND ".constant("PREFIX")."owned_adoptables.tab = '{$tab}'
to the myadopts.php query... but when I do it still doesn't list the tabs.

Is this correct for functions.php?

function gettabs() {
$formcontent = "";
$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '{$username}'");

while ($row = $result->fetchObject()) {
$tabname=$row->name;
$formcontent = $formcontent."<option value='myadopts.php?tab=".$tabname."'>".$tabname."</option>";
}
return $formcontent;
}

Hall of Famer
04-30-2012, 04:37 AM
Umm are you trying to select from multiple tables? If so, use the method join() before calling select().

SilverDragonTears
04-30-2012, 05:04 AM
I figured it out :D Thank you for the help!

SilverDragonTears
04-30-2012, 03:35 PM
Hmm... this pulls up everyone's tabs instead of just the logged in user


$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '{$username}'");

i see why but I don't know how to fix it.


heh.

$result = $GLOBALS['adopts']->select("tabs", array("username", "name"), "username = '".$GLOBALS['username']."'");
Seems to do the trick ;)

Hall of Famer
05-01-2012, 02:59 PM
Of course the old script wont work, didnt I tell you before that you need to worry about the variable scope issue? What is $username in your function? If you neither pass it as an argument to your function tab(), nor declare it as global variable, it will be considered an undefined variable.

SilverDragonTears
05-01-2012, 04:43 PM
I edited it before you posted... I fixed it. I'm learning slowly ;)

Hall of Famer
05-01-2012, 05:17 PM
I see, still Id recommend you to pass $username as argument in function tab() instead of declaring it as superglobal variable. As you see, superglobals have security issues and I've been removing them from the core script since Mys v1.3.0 release.

SilverDragonTears
05-01-2012, 05:22 PM
I don't know how :(