Jump to content

insert a query after getting a query


hyster
Go to solution Solved by mac_gyver,

Recommended Posts

I'm getting a json feed but with not all the data I want so I'm trying to pull the extra data from a sql table I already have.

 

the insert query works fine but not the select query (the "cont" and "tip" is for testing)

 

I don't no if the $tank_id in the select query is missing or if the whole query section just does not work the way I coded it

 

thanks for any help.

$count = '0';
foreach ($output['data'][$id] as $item){
// works fine   
   $tank_id = $item['tank_id'] ;
   $master =  $item['mark_of_mastery'] ;

//    does not seem to be working   
// get tank details from another table                                       
    $show01 = mysql_query("SELECT * from tank_list where tank_id = '$tank_id' LIMIT 1"); 
    $row01 = mysql_fetch_assoc($show01);        
            $country = 'cont'.$row01['nation']; //cont for testing
            $type = 'tip'.$row01['type'];       //tip for testing
                   
//   works fine      
//insert players complete garage data
      $sql9="INSERT INTO garage_list ( country, type, player, account_id, tank_id, master)VALUES('$country', '$type', '$nick','$id','$tank_id', '$master')";
      $count ++;
          if ($conn->multi_query($sql9) === TRUE) {
              //echo "New records created successfully, thanks " .$nick;
          } else {
              //echo "Error: " . $sql9 . "<br>" . $conn->error;
          }
}
Link to comment
Share on other sites

  • Solution

i recommend that you tell or show us what symptom or error you are getting that leads you to believe that something doesn't work. we are not sitting there with you and don't know what it is you are seeing in front of you.

 

why are you using both the msyql and mysqli extensions in one script? do you even have a connection using the mysql extension? there would be php error's if you don't. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would help you by reporting and displaying all the errors it detects?

 

your code should ALWAYS detect and handle errors with database statements, so that it doesn't try to run logic that's dependent on database statements working when they haven't and test to make sure that a query matched a row of data before using the data.

 

why are you using a multi_query() statement for a single query? this opens the door for sql injection to run ANY type of query, especially since you are not doing anything to protect against sql injection. even if you currently trust the data source, someone at some point can get nefarious data onto the site you are getting your data from. you must ALWAYS protect against sql injection.

 

btw - the php mysql extension has been removed from php for almost a year. you should not be using it at all at this point in time.

Link to comment
Share on other sites

thanks mac_gyver

u asked enough question for me to look back over it and got it working with the correct type of query.

I was modding a 4 year old script and I not really done any coding at all in 2 so I'm just a little behind :$

 

the problem I had was it was running the script with 0 errors, if I had errors I could have stumbled on from there lol

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.