Multiple Queries

Discussion in 'PHP' started by Philosophaie, Feb 16, 2012.

  1. #1
    This works:
    $conn = mysql_connect('localhost', 'username1', 'password1') or die(mysql_error());
    mysql_select_db('database1');
    $sql = "INSERT INTO table1 VALUES (NULL,NOW(),value1,value2,value3);";
    $result = mysql_query($sql, $conn) or die('Query failed: ' . mysql_error());
    Code (markup):
    I want to add directly another query but if I add another $sql2 and $result2 it does not work:
    $sql2 = "SELECT * FROM table1";
    $result2 = mysql_query($sql2, $conn) or die('Query failed: ' . mysql_error());
    Code (markup):
    How do you go about adding two, three, four results?
     
    Philosophaie, Feb 16, 2012 IP
  2. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #2
    How do you know it isn't working? Did you try outputting the results of the second query?
     
    Andre91, Feb 16, 2012 IP
  3. Philosophaie

    Philosophaie Member

    Messages:
    21
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #3
    I added the top to the bottom lines, uploaded and opened the website. All I got was an empty php screen. No 'SELECT'. I am not sure what you meant by:

    I was just wondering if there was any code that goes in between the first and second queries.

    Or maybe it is where the"Select" is printing out. Maybe it is not to print out on the php screen. But where?
     
    Last edited: Feb 17, 2012
    Philosophaie, Feb 17, 2012 IP
  4. ankushsharma

    ankushsharma Peon

    Messages:
    19
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for sharing information about multiple queries...
     
    ankushsharma, Feb 19, 2012 IP