By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,440 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,440 IT Pros & Developers. It's quick & easy.

insert data -

P: n/a
Hi Guys,

I try to insert data from a form into a mysql database, but it did not
work...
There is no error, but the data did not pass thru the table.
This is the short script:
<html>
<head>
<title>Insert Address</title>
</head>
<body>
<p><strong>Insert Address</strong></p>
<?php
print_r($_POST);
$link = mysql_connect("aaa", "aaa", "aaa")
or die("Could not connect: " . mysql_error());
mysql_selectdb("db182527668",$link) or die ("Can\'t use
dbserver : " . mysql_error());
$Lat = $_POST['Lat'];
$Lon = $_POST['Lon'];
$Name = $_POST['Name'];
$Owner = $_POST['Owner'];
$City = $_POST['City'];
$Street = $_POST['Street'];
$ZIP = $_POST['ZIP'];
$Country = $_POST['Country'];
$result = mysql_query("INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0',
'".$Lat."','".$Lon."','".$Name."' , '".$Owner."' ,'".$City."'
,'".$Street."' ,'".$ZIP."' ,'".$Country."')");
echo $result;
mysql_error();
mysql_close($link);
?>
</body>
</html>
And this is the table:
id int(11) Nein auto_increment
lat decimal(10,6) Nein 0.000000
lon decimal(10,6) Nein 0.000000
description varchar(255) latin1_german2_ci Nein
owner varchar(255) latin1_german2_ci Nein
city varchar(255) latin1_german2_ci Nein
street varchar(255) latin1_german2_ci Nein
zip varchar(20) latin1_german2_ci Nein
country varchar(255) latin1_german2_ci Nein
Thx for your help!!!

Oct 30 '06 #1
Share this Question
Share on Google+
6 Replies


P: n/a


On Oct 30, 8:14 pm, "VitaminB" <het...@web.dewrote:
Hi Guys,

I try to insert data from a form into a mysql database, but it did not
work...

There is no error, but the data did not pass thru the table.

This is the short script:
<html>
<head>
<title>Insert Address</title>
</head>
<body>
<p><strong>Insert Address</strong></p>

<?php
print_r($_POST);

$link = mysql_connect("aaa", "aaa", "aaa")
or die("Could not connect: " . mysql_error());
mysql_selectdb("db182527668",$link) or die ("Can\'t use
dbserver : " . mysql_error());

$Lat = $_POST['Lat'];
$Lon = $_POST['Lon'];
$Name = $_POST['Name'];
$Owner = $_POST['Owner'];
$City = $_POST['City'];
$Street = $_POST['Street'];
$ZIP = $_POST['ZIP'];
$Country = $_POST['Country'];

$result = mysql_query("INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0',
'".$Lat."','".$Lon."','".$Name."' , '".$Owner."' ,'".$City."'
,'".$Street."' ,'".$ZIP."' ,'".$Country."')");
echo $result;
mysql_error();

mysql_close($link);
?>

</body>
</html>

And this is the table:

id int(11) Nein auto_increment
lat decimal(10,6) Nein 0.000000
lon decimal(10,6) Nein 0.000000
description varchar(255) latin1_german2_ci Nein
owner varchar(255) latin1_german2_ci Nein
city varchar(255) latin1_german2_ci Nein
street varchar(255) latin1_german2_ci Nein
zip varchar(20) latin1_german2_ci Nein
country varchar(255) latin1_german2_ci Nein

Thx for your help!!!
Check whether your SQL statement is correct, print it and execute in
the database client, like Query Browser. Check the result of the
mysql_error function - now you just do not print the message it
returns.

Sincerely,
Alexander
http://www.alexatnet.com/ - Zend Framework and Ajax blog

Oct 30 '06 #2

P: n/a
VitaminB wrote:
I try to insert data from a form into a mysql database, but it did not
work...
There is no error,
I think you mean: "I didn't print the error," :)
but the data did not pass thru the table.
<snip>
$result = mysql_query("INSERT INTO wholocations(íd', 'lat',
'lon','description', ówner', çity', 'street', 'zip', çountry')
VALUES('0',
'".$Lat."','".$Lon."','".$Name."' , '".$Owner."' ,'".$City."'
,'".$Street."' ,'".$ZIP."' ,'".$Country."')");
If there is an error in your SQL statement, $result will be false and
echo $result;
this echo will be the same as <?php echo false; ?>
You need to test the return value of mysql_query()

if ($result === false) {
echo 'There was an error in the SQL statement. ';
echo 'The error was: ', mysql_error(), "].<br>\n";
}
mysql_error();
<snip>

--
I (almost) never check the dodgeit address.
If you *really* need to mail me, use the address in the Reply-To
header with a message in *plain* *text* *without* *attachments*.
Oct 30 '06 #3

P: n/a
On 30 Oct 2006 10:14:59 -0800, "VitaminB" <he****@web.dewrote:
>mysql_error();
Right idea, but this statement does nothing. You need to at least print it
out.

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Oct 30 '06 #4

P: n/a
"VitaminB" <he****@web.depíse v diskusním príspevku
news:11*********************@e3g2000cwe.googlegrou ps.com...
Hi Guys,

I try to insert data from a form into a mysql database, but it did not
work...
<?php
print_r($_POST);
$link = mysql_connect("aaa", "aaa", "aaa")
or die("Could not connect: " . mysql_error());
mysql_selectdb("db182527668",$link) or die ("Can\'t use
dbserver : " . mysql_error());
$Lat = $_POST['Lat'];
$Lon = $_POST['Lon'];
$Name = $_POST['Name'];
$Owner = $_POST['Owner'];
$City = $_POST['City'];
$Street = $_POST['Street'];
$ZIP = $_POST['ZIP'];
$Country = $_POST['Country'];
$result = mysql_query("INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0',
'".$Lat."','".$Lon."','".$Name."' , '".$Owner."' ,'".$City."'
,'".$Street."' ,'".$ZIP."' ,'".$Country."')");
It is curious syntax :-) Try this:

$query = "INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0', $Lat, $Lon, $Name, $Owner , $City, $Street, $ZIP,
$Country)";
$result = mysql_query($query) or die(mysql_error());
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Oct 31 '06 #5

P: n/a

Petr Vileta wrote:
"VitaminB" <he****@web.depíse v diskusním príspevku
news:11*********************@e3g2000cwe.googlegrou ps.com...
Hi Guys,

I try to insert data from a form into a mysql database, but it did not
work...
<?php
print_r($_POST);
$link = mysql_connect("aaa", "aaa", "aaa")
or die("Could not connect: " . mysql_error());
mysql_selectdb("db182527668",$link) or die ("Can\'t use
dbserver : " . mysql_error());
$Lat = $_POST['Lat'];
$Lon = $_POST['Lon'];
$Name = $_POST['Name'];
$Owner = $_POST['Owner'];
$City = $_POST['City'];
$Street = $_POST['Street'];
$ZIP = $_POST['ZIP'];
$Country = $_POST['Country'];
$result = mysql_query("INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0',
'".$Lat."','".$Lon."','".$Name."' , '".$Owner."' ,'".$City."'
,'".$Street."' ,'".$ZIP."' ,'".$Country."')");

It is curious syntax :-) Try this:

$query = "INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0', $Lat, $Lon, $Name, $Owner , $City, $Street, $ZIP,
$Country)";
$result = mysql_query($query) or die(mysql_error());
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Also, take a look at php's extract() function

Oct 31 '06 #6

P: n/a
Thx for all these tips. I will try this tomorrow evening. The "currious
syntax" is from another forum (o.
strawberry wrote:
Petr Vileta wrote:
"VitaminB" <he****@web.depíse v diskusním príspevku
news:11*********************@e3g2000cwe.googlegrou ps.com...
Hi Guys,
>
I try to insert data from a form into a mysql database, but it did not
work...
>
>
<?php
print_r($_POST);
>
>
$link = mysql_connect("aaa", "aaa", "aaa")
or die("Could not connect: " . mysql_error());
mysql_selectdb("db182527668",$link) or die ("Can\'t use
dbserver : " . mysql_error());
>
>
$Lat = $_POST['Lat'];
$Lon = $_POST['Lon'];
$Name = $_POST['Name'];
$Owner = $_POST['Owner'];
$City = $_POST['City'];
$Street = $_POST['Street'];
$ZIP = $_POST['ZIP'];
$Country = $_POST['Country'];
>
>
$result = mysql_query("INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0',
'".$Lat."','".$Lon."','".$Name."' , '".$Owner."' ,'".$City."'
,'".$Street."' ,'".$ZIP."' ,'".$Country."')");
It is curious syntax :-) Try this:

$query = "INSERT INTO wholocations('id', 'lat',
'lon','description', 'owner', 'city', 'street', 'zip', 'country')
VALUES('0', $Lat, $Lon, $Name, $Owner , $City, $Street, $ZIP,
$Country)";
$result = mysql_query($query) or die(mysql_error());
--

Petr Vileta, Czech republic
(My server rejects all messages from Yahoo and Hotmail. Send me your mail
from another non-spammer site please.)
Also, take a look at php's extract() function
Oct 31 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.