/    Sign up×
Community /Pin to ProfileBookmark

Inserting datas in different tables

How can I insert datas in different tables?
I have been trying this dbut didn’t worked out…

[code=php]
$sql = “INSERT INTO DatosInmueble ( Tipo, Localidad)” .
“VALUES (‘$Tipo’, ‘$Localidad)”;
$result = mysql_query($sql) or die(mysql_error().'<p>’.$sql.'</p>’);
$sql2 = “INSERT INTO Precios ( Ref, ene1)”.
“VALUES (Ref’, ‘$ene1′)”;
$result2 = mysql_query($sql2) or die(mysql_error().'<p>’.$sql2.'</p>’);
$sql3 = “INSERT INTO Disponibilidad ( Ref, ene1d)”.
“VALUES (Ref’, ‘$ene1d, ‘$ene2d)”
$result3 = mysql_query($sql3) or die(mysql_error().'<p>’.$sql3.'</p>’);
echo “¡Gracias! Hemos recibido sus datos.n”;
[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@YoNNov 08.2003 — You don't have to split it into two strings, anyways if that's the way you like it... there's no space between [COLOR=red]"INSERT INTO DatosInmueble ( Tipo, Localidad)" [/COLOR] and [COLOR=red]"VALUES ('$Tipo', '$Localidad)"[/COLOR] because you concatenated the strings but didn't put any space between them.

Anyways, I'd do it like this:
[code=php]$sql = "INSERT INTO DatosInmueble (Tipo, Localidad) VALUES ('".$Tipo."', '".$Localidad."')";
$result = mysql_query($sql) or die(mysql_error()."<p>".$sql."</p>");
$sql2 = "INSERT INTO Precios (Ref, ene1) VALUES ('Ref', '".$ene1."')";
$result2 = mysql_query($sql2) or die(mysql_error()."<p>".$sql."</p>");
$sql3 = "INSERT INTO Disponibilidad (Ref, ene1d) VALUES ('Ref', '".$ene1d.", '".$ene2d.")"
$result3 = mysql_query($sql3) or die(mysql_error()."<p>".$sql."</p>");
echo "¡Gracias! Hemos recibido sus datos.n";[/code]
HTH.
×

Success!

Help @Perfidus spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...