Help - Search - Member List - Calendar
Full Version: hm??? integer converting?
WorkTheWeb Forums > Webmaster Resources > PHP Help
Support our Sponsors!
roN @ work
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
[Email Removed]*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 @ work
roN @ work wrote:
QUOTE
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
[Email Removed]*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?

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

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

Chris Hope
roN @ work wrote:

QUOTE
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
[Email Removed]*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?

"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 Hope
roN @ work wrote:

QUOTE
roN @ work wrote:
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
[Email Removed]*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?

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

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

Kimmo Laine
"Chris Hope" <[Email Removed]> wrote in message
news:dalhce$u6f$[Email Removed]...
QUOTE
roN @ work wrote:

roN @ work wrote:
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
[Email Removed]*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?

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

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')";
^    ^


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

Chris Hope
Kimmo Laine wrote:

QUOTE
"Chris Hope" <[Email Removed]> wrote in message
news:dalhce$u6f$[Email Removed]...
roN @ work wrote:

roN @ work wrote:
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
[Email Removed]*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?

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

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')";
^    ^

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

Yep :)

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


PHP Help | Linux Help | Web Hosting | Reseller Hosting | SSL Hosting
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2006 Invision Power Services, Inc.