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