Professional Web Applications Themes

hm??? integer converting? - PHP Development

Hi, I got following Code and get Below Error, why? :( Code: function reportSpam($email_address_and_relay) { $connection=mysql_connect(db_server,db_user,db_passwort); mysql_select_db(db_name); $date = date("y-m-d"); $tmp=explode("*",$email_address_and_relay); $address = $tmp[0]; $relay = $tmp[1]; $query = "insert into blacklist (`Date`,`Address`, `Relay`) values ('$date','$address', $relay)"; mysql_query($query) or die(mysql_error()); mysql_close($connection); echo "reported ".$email_address."<br>\n"; } [Error] 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 '.160.97)' at line 2 [/Error] In Variable $email_address_and_relay there is something like com*255.127.53.49 I'd like to explode that and save the e-mail address and the relay IP in diffrent ...

  1. #1

    Default hm??? integer converting?

    Hi,
    I got following Code and get Below Error, why? :(
    Code:
    function reportSpam($email_address_and_relay)
    {
    $connection=mysql_connect(db_server,db_user,db_passwort);
    mysql_select_db(db_name);
    
    $date = date("y-m-d");
    $tmp=explode("*",$email_address_and_relay);
    $address = $tmp[0];
    $relay = $tmp[1];
    $query = "insert into blacklist (`Date`,`Address`, `Relay`) values
    ('$date','$address', $relay)";
    
    mysql_query($query) or die(mysql_error());
    mysql_close($connection);
    echo "reported ".$email_address."<br>\n";
    }
    [Error]
    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 '.160.97)' at
    line 2
    [/Error]
    In Variable $email_address_and_relay there is something like
    com*255.127.53.49 I'd like to explode that and save the e-mail
    address and the relay IP in diffrent cols in the same row. shouldn't it
    work? :(
    table blacklist looks like this:
    Date - date
    Address - varchar(100)
    Relay - varchar(50)
    do I have to convert $relay to an integer before I'm gonna save it to the
    DB? Yes? How?
    --
    chEErs roN
    I'm root. I'm allowed to do this! ;)
    keep on rockin'


    roN Guest

  2. #2

    Default Re: hm??? integer converting?

    roN work wrote: 

    Sorry, I meant convert it to a String for sure....

    --
    chEErs roN
    I'm root. I'm allowed to do this! ;)
    keep on rockin'


    roN Guest

  3. #3

    Default Re: hm??? integer converting?

    roN work wrote:
     

    "Relay" in your example is a varchar(50) and yet in your sql query you
    do not surround the value with quotes.

    Either save it as a varchar/char field type with quotes around the
    value, or make the field type numeric and use the ip2long() function to
    convert it to a numeric type (and then long2ip() to convert it back
    again when you need to use it).

    http://www.php.net/ip2long
    http://www.php.net/long2ip

    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
    Chris Guest

  4. #4

    Default Re: hm??? integer converting?

    roN work wrote:
     
    >
    > Sorry, I meant convert it to a String for sure....[/ref]

    Read my other post. You don't need to convert it to a string as it
    should already be a string; you just need to put quotes around the
    value ie

    $query = "insert into blacklist (`Date`,`Address`, `Relay`) values
    ('$date','$address', $'relay')";
    ^ ^

    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
    Chris Guest

  5. #5

    Default Re: hm??? integer converting?

    "Chris Hope" <com> wrote in message
    news:dalhce$u6f$ihug.co.nz... 
    >>
    >> Sorry, I meant convert it to a String for sure....[/ref]
    >
    > Read my other post. You don't need to convert it to a string as it
    > should already be a string; you just need to put quotes around the
    > value ie
    >
    > $query = "insert into blacklist (`Date`,`Address`, `Relay`) values
    > ('$date','$address', $'relay')";
    > ^ ^[/ref]


    And I'm sure Chris meant '$relay' instead of $'relay', but I thought I'd
    mention it...

    --
    Welcome to Usenet! Please leave tolerance, understanding
    and intelligence at the door. They aren't welcome here.
    eternal piste erection miuku gmail piste com


    Kimmo Guest

  6. #6

    Default Re: hm??? integer converting?

    Kimmo Laine wrote:
     
    >>
    >> Read my other post. You don't need to convert it to a string as it
    >> should already be a string; you just need to put quotes around the
    >> value ie
    >>
    >> $query = "insert into blacklist (`Date`,`Address`, `Relay`) values
    >> ('$date','$address', $'relay')";
    >> ^ ^[/ref]
    >
    > And I'm sure Chris meant '$relay' instead of $'relay', but I thought
    > I'd mention it...[/ref]

    Yep :)

    --
    Chris Hope | www.electrictoolbox.com | www.linuxcdmall.com
    Chris Guest

Similar Threads

  1. Replies: 0
    Last Post: October 27th, 11:19 AM
  2. Replies: 0
    Last Post: October 27th, 11:13 AM
  3. Do we have any class converting binary string to integer?
    By Daqian in forum UNIX Programming
    Replies: 3
    Last Post: January 30th, 10:29 AM
  4. ASP integer date/time converting problems
    By Ralph Hodenius [MS] in forum ASP Database
    Replies: 0
    Last Post: January 8th, 02:01 PM
  5. converting Raw integer color values to RGB?
    By paul in forum Macromedia Director Lingo
    Replies: 3
    Last Post: August 28th, 05:11 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139