Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 3 of 4 FirstFirst 1234 LastLast
Results 31 to 45 of 54

Thread: PHP mysql error

  1. #31
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    http://friendkonnect.com/projects/em...t/new/message/

    Enter the 11digit code: KT019590332


    I tried the code fix with the selecting the columns, still not displaying echo vars from the while loop. Thanks!

  2. #32
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Your query is failing. Change this
    PHP Code:
    $query "SELECT id, email, key, carrier, cell FROM friendko_text WHERE key = '{$_POST['key']}'";
    $result mysql_query($query) or die($query); 
    to this
    PHP Code:
    $query "SELECT id, email, key, carrier, cell FROM friendko_text WHERE key = '{$_POST['key']}'";
    $result mysql_query($query) or die(mysql_error().'<br>'.$query); 
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  3. #33
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I did make that change now im getting the following

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'key, carrier, cell FROM friendko_text WHERE key = 'KT019590332'' at line 1
    SELECT id, email, key, carrier, cell FROM friendko_text WHERE key = 'KT019590332'

    I did check the manuel select query page, couldn't see whats wrong.

  4. #34
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,994
    Thanks
    4
    Thanked 2,662 Times in 2,631 Posts
    Haha, can't believe I missed that.
    Key is a reserved word in MySQL. You'll need to surround it with backquotes (`) if you want to use it as your column name.

  5. #35
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    How would I rename a mysql columns exactly, my alter query is failing

    PHP Code:
    alter users change key keycode varchar (11) ; 

  6. #36
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Quote Originally Posted by amcf1992 View Post
    How would I rename a mysql columns exactly, my alter query is failing

    PHP Code:
    alter users change key keycode varchar (11) ; 
    PHP Code:
    alter table users change `keykeycode varchar (11) ; 
    if Google is correct
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  7. #37
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    PHP Code:
    Table 'friendko_text.friendko_text' doesn't exist
    SELECT id, email, keycode, carrier, cell FROM friendko_text WHERE keycode = '
    KT019590332 

  8. #38
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thats the whats showing up upon changing the column name, the table does exist.

  9. #39
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    Code:
    Table 'friendko_text.friendko_text' doesn't exist
    It's looking for a table named 'friendko_text' within a database named 'friendko_text'. You may have created a new database with this name - unless your database is named the same (which would be confusing).

    Before altering a table-column you would need to ensure that you are using the correct database:
    Code:
    use your_database_name;
    # alter the column in a table
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  10. #40
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    I got the 11 digit number to pull mysql successfully. My variables work.
    I have one problem, app still stuck on send.php


    Full Code

    PHP Code:
    <?php

    $con 
    mysql_connect("localhost","friendko_admin","Macbookpro17#");
     if (!
    $con)
       {
       die(
    'Could not connect: ' mysql_error());
       }
     
    mysql_select_db("friendko_text"$con);



    $to $_POST['cell'];
    $carrier $row['carrier'];
    $message stripslashes($_POST['message']);
    $key $_POST['keycode'];
    $message stripslashes($_POST['message']);


    $query "SELECT id, email, keycode, carrier, cell FROM users WHERE keycode = '{$_POST['keycode']}'";
    $result mysql_query($query) or die(mysql_error().'<br>'.$query);  
    while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))  
    {
      echo 
    '11 Digit Key: ' $row['keycode'] . '<br>';
      echo 
    'Email: ' $row['email'] . '<br>';
      echo 
    'Carrier: ' $row['carrier'] . '<br>';
      echo 
    'To: ' $row['cell'] . '<br>';


    if ((empty(
    $key)) || (empty($message)) {
    header ("Location: sms_error.php");

    Last edited by amcf199209-03-2012 at 05:42 PM..
    amcf1992 is online now Add to amcf1992's Reputation Report Post       Reply With Quote Multi-Quote This Message Quick reply to this message
    Old 09-03-2012, 05:50 PM       PM User | Report this post  #29
    amcf1992
    Regular Coder

     
    Join Date: Jul 2011
    Posts: 100
    Thanks: 6
    Thanked 0 Times in 0 Posts
    amcf1992 is an unknown quantity at this point
        
    Full PHP Code
    PHP Code:
    <?php
    $con = mysql_connect("localhost","friendko_admin","Macbookpro17#");
     if (!$con)
       {
       die('
    Could not connect' . mysql_error());
       }
     
    mysql_select_db("friendko_text", $con);



    $to = $row['
    cell'];
    $key = $_POST['
    key'];
    $message = stripslashes($_POST['
    message']);
    $query = "SELECT id, email, key FROM friendko_text WHERE key = '
    {$_POST['key']}'";
    $result = mysql_query($query);
    while($row = mysql_fetch_array($result, MYSQL_ASSOC))  
    {
      echo '
    11 Digit Key' . $row['key'] . '<br>';
      echo '
    Email' . $row['email'] . '<br>';
      echo '
    Carrier' . $row['carrier'] . '<br>';
      echo '
    To' . $row['cell'] . '<br>';
    }  

    if ((empty($keycode)) || (empty($message)) {
    header ("Location: sms_error.php");
    }

    else if ($row['
    carrier'] == "verizon") {
    $formatted_number = $to."@vtext.com";
    mail("$formatted_number", "SMS", "$message"); 
    // Currently, the subject is set to "SMS". Feel free to change this.

    header ("Location: sms_success.php");
    }

    else if ($row['
    carrier'] == "tmobile") {
    $formatted_number = $to."@tomomail.net";
    mail("$formatted_number", "SMS", "$message");

    header ("Location: sms_success.php");
    }

    else if ($row['
    carrier'] == "sprint") {
    $formatted_number = $to."@messaging.sprintpcs.com";
    mail("$formatted_number", "SMS", "$message");

    header ("Location: sms_success.php");
    }

    else if ($row['
    carrier'] == "att") {
    $formatted_number = $to."@txt.att.net";
    mail("$formatted_number", "SMS", "$message");
    header ("Location: sms_success.php");
    }

    else if ($row['
    carrier] == "virgin") {
    $formatted_number $to."@vmobl.com";
    mail("$formatted_number""SMS""$message");

    header ("Location: sms_success.php");
    }

    ?>

  11. #41
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    You were advised that key is a reserved word in MySQL and would need to be enclosed in `backticks` if used as a fieldname:

    Code:
    $query = "SELECT id, email, key FROM friendko_text WHERE key = '{$_POST['key']}'";
    I notice at a quick glance that you use a variable $key but later refer to a variable named $keycode. So it looks like you need review your code so that it is consistent throughout.
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  12. #42
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    Thank you for that, I've been to successfully lookup the row information pertaining to that 11 digit code. Now im stuck sending the text message for that person. In other words, Any ideas on sending php mail to phone carriers?

  13. #43
    Regular Coder
    Join Date
    Jul 2011
    Posts
    141
    Thanks
    8
    Thanked 0 Times in 0 Posts
    My semi-working code upto the sms part

    PHP Code:
    <?php

    $con 
    mysql_connect("localhost","friendko_admin","Macbookpro17#");
     if (!
    $con)
       {
       die(
    'Could not connect: ' mysql_error());
       }
     
    mysql_select_db("friendko_text"$con);



    $to $row['cell'];
    $carrier $row['carrier'];
    $message stripslashes($_POST['message']);
    $keycode $_POST['keycode'];



    $query "SELECT id, email, keycode, carrier, cell FROM users WHERE keycode = '{$_POST['keycode']}'";
    $result mysql_query($query) or die(mysql_error().'<br>'.$query);  
    while(
    $row mysql_fetch_array($resultMYSQL_ASSOC))  
    {
      echo 
    '11 Digit Key: ' $row['keycode'] . '<br>';
      echo 
    'Email: ' $row['email'] . '<br>';
      echo 
    'Carrier: ' $row['carrier'] . '<br>';
      echo 
    'To: ' $row['cell'] . '<br>';



    if ((empty(
    $keycode)) || (empty($message)) {
    header ("Location: sms_error.php");
    }

    else if (
    $row['carrier'] == "Verizon") {
    $formatted_number $to."@vtext.com";
    mail("$formatted_number""SMS""$message"); 
    // Currently, the subject is set to "SMS". Feel free to change this.

    header ("Location: sms_success.php");
    }

    else if (
    $row['carrier'] == "T-Mobile") {
    $formatted_number $to."@tomomail.net";
    mail("$formatted_number""SMS""$message");

    header ("Location: sms_success.php");
    }

    else if (
    $row['carrier'] == "Sprint") {
    $formatted_number $to."@messaging.sprintpcs.com";
    mail("$formatted_number""SMS""$message");

    header ("Location: sms_success.php");
    }

    else if (
    $row['carrier'] == "AT&T") {
    $formatted_number $to."@txt.att.net";
    mail("$formatted_number""SMS""$message");
    header ("Location: sms_success.php");
    }

    else if (
    $row[carrier] == "Virgin") {
    $formatted_number $to."@vmobl.com";
    mail("$formatted_number""SMS""$message");

    header ("Location: sms_success.php");
    }

    ?>

    ?>

  14. #44
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    "Note:

    When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini."

    The docs
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS

  15. #45
    New Coder
    Join Date
    Sep 2012
    Posts
    71
    Thanks
    0
    Thanked 8 Times in 8 Posts
    Alright, before my head explodes... how about creating either a carrierto array or some other way of avoiding the big redirect list... I've taken the liberty of using stock symbols for the phone carriers:

    PHP Code:
    $carrierto = array();
    $carrierto['ATT'] = '@txt.att.net';
    $carrierto['DT']  = '@tomomail.net';
    $carrierto['S']   = '@messaging.sprintpcs.com';
    $carrierto['VM']  = '@vmobl.com';

    $cc $row['carrier']
    if ( isset(
    $carrierto[$cc]) )
    {
       
    $formatted_number $to $carrierto[$cc];
       
    mail("$formatted_number""SMS""$message");
       
    header ("Location: sms_success.php");
    }
    else
       die(
    "Oh crap... I don't know who that is!<br>\n"); 
    P.S. Is this just a learning experience project?


 
Page 3 of 4 FirstFirst 1234 LastLast

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •