Varibles from mySQL to PHP script?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
daytonadman
Forum Newbie
Posts: 5
Joined: Wed Nov 10, 2004 1:53 pm

Varibles from mySQL to PHP script?

Post by daytonadman »

Hello all! 8)

This is my first time posting here. I have a project that requires me to alter the following script.

Code: Select all

<?php

    $_url = "https://interneka.com/affiliate/WIDLink.php?WID=489&TotalCost=100.00&OrderID=test9999&AID=18888";

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$_url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);
    curl_exec ($ch);
    curl_close ($ch);

?>
Basically, rather than the above link $_url being hardcoded, I need to be able to populate the values for WID, TotalCost, OrderID, and AID from data stored in a mySQL database on our webserver. I have a pretty good idea of how to connect and open the database, select the data using a SQL query, but I'm not sure of what to do next.

Here is my general understanding of how this is supposed to work.

I need the script to connect to our mySQL database table, select WID, TotalCost, OrderID, and AID for a particular record. Then I need to take the values returned by the select statement and populate the values into the $_url above so that the script https://interneka.com/affiliate/WIDLink.php reads the values.

Any help would be greatly appreciated.

Thanks!
D

Weirdan | Help us, help you. Please use

Code: Select all

and

Code: Select all

tags where approriate when posting code. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]

Will do next time....sorry!
Last edited by daytonadman on Wed Nov 10, 2004 2:55 pm, edited 1 time in total.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Code: Select all

<?php
// Connect to your database and stuff then do the following
$query = "SELECT `stuff`, `morestuff`, `evenmorestuff` FROM `place` WHERE `thing` = '$something' LIMIT 1";
	$result = mysql_query($query) or die('Query failed: ' . mysql_error());
	while ( list($stuff, $morestuff, $evenmorestuff) =  mysql_fetch_array($result)) {
                      echo ("http://google.com/summin.php?stuff=$stuff&morestuff=$morestuff&evenmorestuff=$evenmorestuff");
}
?>
Just replace all the stuff with your variables
daytonadman
Forum Newbie
Posts: 5
Joined: Wed Nov 10, 2004 1:53 pm

Post by daytonadman »

Thanks for the response jshpro2! 8)

Here is what I have come up with so far, do you see any errors or anything that wouldn't work correctly. I have xxxxxx out my server, username, and password. Other than that this is the script.

Thanks again!

Code: Select all

<?php

$db = mysql_connect("mysqlconnect.xxxxxx.com","xxxxxx","xxxxxx") or
      mysql_die("Unable to connect");

      mysql_select_db("xxxxxx_xxxxxx",$db) or
      mysql_die("Unable to locate table");

$query = "SELECT `WID`, `cost`, `confirmation`, 'AID' FROM `assist` WHERE `billed` = 'Y' LIMIT 1";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
    while ( list($WID, $cost, $confirmation, $AID) =  mysql_fetch_array($result)) 

{
echo $_url = ("https://interneka.com/affiliate/WIDLink.php?WID=$WID&TotalCost=$cost&OrderID=$confirmation&AID=$AID");
}

mysql_close($db);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$_url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);
    curl_exec ($ch);
    curl_close ($ch);

?>
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

should work, does it?
daytonadman
Forum Newbie
Posts: 5
Joined: Wed Nov 10, 2004 1:53 pm

Post by daytonadman »

Don't know yet, still haven't received any feedback from Interneka!?

When I echo something, should it appear on the screen in the browser?

Here is an updated script with an added update query. Basically I want it to place a Y in my submitted field after the script has been executed to give the affiliate credit for the sale.

Code: Select all

<?php
$db = mysql_connect("xxxxxxx","xxxxxx","xxxxxx") or
      mysql_die("Unable to connect");

      mysql_select_db("xxxxxxx_xxxxxx",$db) or
      mysql_die("Unable to locate table");

$query = "SELECT `WID`, `cost`, `confirmation`, 'AID' FROM `assist` WHERE `billed` = 'Y' LIMIT 1";

$result = mysql_query($query) or die('Query failed: ' . mysql_error());
    while ( list($WID, $cost, $confirmation, $AID) =  mysql_fetch_array($result))

echo "Query performed sucessfully"; 

{
$_url = ("https://interneka.com/affiliate/WIDLink.php?WID=$WID&TotalCost=$cost&OrderID=$confirmation&AID=$AID");
}

echo "Transaction has been submitted";

$update = "UPDATE assist SET submitted = 'Y' WHERE BILLED = 'Y' LIMIT 1";

$result = mysql_query($update) or die('Update failed: ' . mysql_error());

echo "Record updated";

mysql_close($db);

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$_url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,  0);
    curl_exec ($ch);
    curl_close ($ch);

?>
?>
Post Reply