imsry Posted December 28, 2014 Share Posted December 28, 2014 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 Quote Link to comment Share on other sites More sharing options...
Jacques1 Posted December 28, 2014 Share Posted December 28, 2014 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. Quote Link to comment Share on other sites More sharing options...
imsry Posted December 28, 2014 Author Share Posted December 28, 2014 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; ?> Quote Link to comment Share on other sites More sharing options...
imsry Posted December 28, 2014 Author Share Posted December 28, 2014 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; ?> Quote Link to comment Share on other sites More sharing options...
imsry Posted January 1, 2015 Author Share Posted January 1, 2015 bump Quote Link to comment Share on other sites More sharing options...
Barand Posted January 1, 2015 Share Posted January 1, 2015 One connection will suffice, and when you decide on MySQLi or PDO, use a prepared query. And you do not specify which column the value $killforumid should be written to Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.