Simple PHP Script Help

Discussion in 'PHP' started by tushardhoot1, Jan 7, 2008.

  1. #1
    Hey,

    Idk why this isn't working. I've done it before successfully.

    $mysql_host = "localhost";

    $mysql_user = "*********";

    $mysql_pass = "******";

    $mysql_base = "************";


    mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die( "Unable to connect to SQL server");
    mysql_select_db( "$mysql_base") or die( "Unable to select database");

    mysql_query("INSERT INTO purchases (id,item_name,item_number,payment_status,payment_amount,payment_currency,txn_id,receiver_email,payer_email,date,registrations) VALUES('','$item_name','$item_number','$payment_status','$payment_amount','$payment_currency','$txn_id','$receiver_email','$payer_email','$date222','0') ") or die(mysql_error());
     
    tushardhoot1, Jan 7, 2008 IP
  2. hostingcoupon

    hostingcoupon Peon

    Messages:
    447
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    $link_id = mysql_connect($mysql_host, $mysql_user, $mysql_pass) or die( "Unable to connect to SQL server");
    
    mysql_select_db($mysql_base, $link_id) or die( "Unable to select database");
    
    mysql_query("abcde", $link_id);
    
    
    Code (markup):
     
    hostingcoupon, Jan 7, 2008 IP
  3. mvl

    mvl Peon

    Messages:
    147
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Do you get an error message? What does it say?
     
    mvl, Jan 7, 2008 IP
  4. Freewebspace

    Freewebspace Notable Member

    Messages:
    6,213
    Likes Received:
    370
    Best Answers:
    0
    Trophy Points:
    275
    #4
    Tell your error message and

    Whether SQL error message is necessary? (die( "Unable to select database");) as it sometimes confuses newbies
     
    Freewebspace, Jan 8, 2008 IP
  5. LittleJonSupportSite

    LittleJonSupportSite Peon

    Messages:
    386
    Likes Received:
    20
    Best Answers:
    0
    Trophy Points:
    0
    #5
    
    $mysql_host = "localhost";
    
    $mysql_user = "*********";
    
    $mysql_pass = "******";
    
    $mysql_base = "************";
    
    
    mysql_connect($mysql_host, $mysql_user, $mysql_pass)  or  die( "Unable  to  connect to  SQL  server"); 
    mysql_select_db( "$mysql_base")  or  die( "Unable  to  select  database"); 
    
    mysql_query("INSERT INTO purchases (id,item_name,item_number,payment_status,payment_amount,payment_currency,txn_id,receiver_email,payer_email,date,registrations) VALUES('','$item_name','$item_number','$payment_status','$payment_amount','$payment_currency','$txn_id','$receiver_email','$payer_email','$date222','0') ") or die(mysql_error());
    
    Code (markup):


    There is nothing wrong with this code.

    My guess is that you have a typo in the dbname/user/pass.
     
    LittleJonSupportSite, Jan 8, 2008 IP
  6. kmap

    kmap Well-Known Member

    Messages:
    2,215
    Likes Received:
    29
    Best Answers:
    2
    Trophy Points:
    135
    #6
    sometimes hostname is not localhost like for godaddy hosting its not localhost so please check hostname which is 99% "localhost"

    Secondly Where are these variables coming from? $item_name','$item_number','$payment_status','$payment_amount','$payment_currency'

    Are you using register global off


    Regards

    Alex
     
    kmap, Jan 8, 2008 IP
  7. Dagon

    Dagon Active Member

    Messages:
    122
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #7
    Register globals does not have any influence on this problem. Even if it was turned off and the variables are coming straight from get or post I think it would not produce an error message but insert an empty row.
     
    Dagon, Jan 8, 2008 IP
  8. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #8
    Nothing wrong with the variable, no error message, and the host is localhost. I know the rest of the script is working because I have told the script to email and add to database, but right now its only emailing me.
     
    tushardhoot1, Jan 8, 2008 IP
  9. sunnyverma1984

    sunnyverma1984 Well-Known Member

    Messages:
    342
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    120
    #9
    if id is auto increment the use NULL inside of ''

    VALUES(NULL,'$item_name','$item_number','$payment_status','$payment_amount','$payment_currency','$txn_id','$receiver_email','$payer_email','$date222','0')
     
    sunnyverma1984, Jan 8, 2008 IP
  10. HuggyStudios

    HuggyStudios Well-Known Member

    Messages:
    724
    Likes Received:
    20
    Best Answers:
    26
    Trophy Points:
    165
    #10
    Dont put anything in there, just leave the id blank.
     
    HuggyStudios, Jan 8, 2008 IP
  11. tushardhoot1

    tushardhoot1 Active Member

    Messages:
    3,013
    Likes Received:
    96
    Best Answers:
    0
    Trophy Points:
    90
    #11
    I even deleted date,registrations,payment_status,payment_currency and all from script and database, but still doesn't work.
     
    tushardhoot1, Jan 8, 2008 IP
  12. sharqi

    sharqi Guest

    Messages:
    105
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #12
    Using this will give you a lot of insight into why it went wrong.

    http://us2.php.net/mysql_error
     
    sharqi, Jan 9, 2008 IP