Jump to content

MySQL Task


imsry

Recommended Posts

wanting to take a variable and use that variable to search my sql table for another variable

 

example : (from outside prog XXX is sent in as 'killacct')

 

$killacct = $_GET['killacct'];

 

now take 'killacct' and search table 'blahblah' for the row 'variable'

 

so if the table was

killacct = XXX | blahblah = YYY

 

so then i can pull a second variable from my first one

XXX is associated with YYY

 

 

 

 

 

sorry this was probably really hard to understand im very exhaused lol

Link to comment
https://forums.phpfreaks.com/topic/293446-mysql-task/
Share on other sites

sorry this was probably really hard to understand im very exhaused lol

 

Maybe you should get some sleep and try again. ;)

 

Concrete code is always better than vague high-level descriptions. Show us what you have (code excerpts, database tables etc.), and tell us specifically what you want. Then I'm pretty sure we can help you.

 

The better your question, the better the answer. If you just do a quick brain dump with no effort whatsoever, don't expect anything.

Link to comment
https://forums.phpfreaks.com/topic/293446-mysql-task/#findComment-1500915
Share on other sites

Maybe you should get some sleep and try again. ;)

 

Concrete code is always better than vague high-level descriptions. Show us what you have (code excerpts, database tables etc.), and tell us specifically what you want. Then I'm pretty sure we can help you.

 

The better your question, the better the answer. If you just do a quick brain dump with no effort whatsoever, don't expect anything.

 

well i can change my part of the code, but ill post it anyways. assume i defined the connection variables ofc.

 

OKAY. so each of these first variables will be defined from an outside source, but for killacct, i want to use that variable to get a new one.

 

i will have a separate sql table 'whatever'

killacct = A

forumid = B

 

so i want this code to take killacct and query my seperate sql table to get forumid.

then for values i can add 'forumid'

<?php
$deadchar = $_GET['deadchar'];
$level = $_GET['level'];
$class = $_GET['class'];
$killacct = $_GET['killacct'];
$realm = $_GET['realm'];
$date = $_GET['date'];



try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO pkdata (deadchar)
    VALUES ('$deadchar', '$level', '$class', '$realm', '$date')";
    // use exec() because no results are returned
    $conn->exec($sql);
    echo "New record created successfully";
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }

$conn = null;
?>
Link to comment
https://forums.phpfreaks.com/topic/293446-mysql-task/#findComment-1500916
Share on other sites

lil sloppy and two sep connections, ill merge em together if it works, but here is what i worked out

<?php
$deadchar = $_GET['deadchar'];
$level = $_GET['level'];
$class = $_GET['class'];
$killacct = $_GET['killacct'];
$realm = $_GET['realm'];
$date = $_GET['date'];

$servername = "diipk.net.mysql";
$username = "diipk_net";
$password = "fkdivin123";
$dbname = "diipk_net";

$sql=mysqli_connect($servername,$username,$password,$dbname);
$killforumid = mysqli_query($sql,"SELECT `killforumid` FROM `pkusers` WHERE killacct = '$killacct'");

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $sql = "INSERT INTO pkdata (deadchar, level, class, killacct, realm, date)
    VALUES ('$deadchar','$level', '$class', '$killforumid',$killacct '$realm', '$date')";
    // use exec() because no results are returned
    $conn->exec($sql);
    echo "w00tw00t";
    }
catch(PDOException $e)
    {
    echo $sql . "<br>" . $e->getMessage();
    }

$conn = null;
?>
Link to comment
https://forums.phpfreaks.com/topic/293446-mysql-task/#findComment-1500937
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.