Page 1 of 2
Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 3:52 pm
by Supplement
I'm sure it's possible but I can't seem to get it to fire correctly. Here's my code:
Code: Select all
<?php
header("Location:http://www.web.com/inte.php");
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("thedb", $con);
$sql="INSERT INTO affus (Cards, NoCards, User, Pass, hmnumber, BusinessType, Ctry, Company, addr1, City, State, zip, wknumber, wkfax, Fname, lname, Email, Email2)
VALUES
('$_POST[Cards]','$_POST[NoCards]','$_POST[User]','$_POST[Pass]','$_POST[hmnumber]','$_POST[BusinessType]','$_POST[Ctry]','$_POST[Company]','$_POST[addr1]','$_POST[City]','$_POST[State]','$_POST[zip]','$_POST[wknumber]','$_POST[wkfax]','$_POST[Fname]','$_POST[lname]','$_POST[Email]','$_POST[Email2]')";
$sql_1="INSERT INTO usup (username, password)
VALUES('$_POST[User]','$_POST[Pass]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
In need of a bit of help. Thanks in advance gents.
=]
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 3:53 pm
by Celauran
I don't see you ever executing mysql_query($sql_1)
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 3:55 pm
by Jade
You need to connect to the database on the other website, and you need to have the database on
http://web.com configured to allow access from whatever site you're putting this piece of code on. Then you'd do:
Code: Select all
<?php
$con = mysql_connect("http://web.com","username","password");
if (!$con)
die('Could not connect: ' . mysql_error());
mysql_select_db("thedb", $con);
$sql="INSERT INTO affus (Cards, NoCards, User, Pass, hmnumber, BusinessType, Ctry, Company, addr1, City, State, zip, wknumber, wkfax, Fname, lname, Email, Email2)
VALUES
('$_POST[Cards]','$_POST[NoCards]','$_POST[User]','$_POST[Pass]','$_POST[hmnumber]','$_POST[BusinessType]','$_POST[Ctry]','$_POST[Company]','$_POST[addr1]','$_POST[City]','$_POST[State]','$_POST[zip]','$_POST[wknumber]','$_POST[wkfax]','$_POST[Fname]','$_POST[lname]','$_POST[Email]','$_POST[Email2]')";
$sql_1="INSERT INTO usup (username, password)
VALUES('$_POST[User]','$_POST[Pass]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 3:57 pm
by Supplement
same website for both queries 'thedb'.
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 3:59 pm
by Celauran
What's with the header redirect at the top of the page?
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:02 pm
by Supplement
Celauran wrote:What's with the header redirect at the top of the page?
It just redirects to another form after the previous form data is injected.
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:04 pm
by Supplement
Celauran wrote:I don't see you ever executing mysql_query($sql_1)
right, it's only injecting the first query into 'thedb' into the table 'affus' but the second query is not inserting into the database 'thedb' and table 'usup'.
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:04 pm
by Supplement
is this not possible?
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:11 pm
by Celauran
Aside from the fact that you're completely ignoring one of the two queries, you're redirecting away from the page before either of them gets a chance to run.
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:15 pm
by Supplement
the first query runs fine.
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:18 pm
by Celauran
Strange. It shouldn't.
At any rate, $sql_1 isn't running because you aren't calling mysql_query($sql_1).
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:30 pm
by Supplement
ok, i got it working. thank you..
question
How come is won't insert if i add it here?
if (!mysql_query($sql,$sql_1,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:31 pm
by Supplement
i ended up adding it here:
$sql_1="INSERT INTO usup (username, password)
VALUES('$_POST[User]','$_POST[Pass]')"; mysql_query($sql_1);
and it worked.
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 4:34 pm
by Celauran
Supplement wrote:question
How come is won't insert if i add it here?
Code: Select all
if (!mysql_query($sql,[b]$sql_1[/b],$con))
Because functions expect certain arguments in a certain order.
mysql_query()
Re: Injecting two queries into two different tables in mysql
Posted: Fri Nov 04, 2011 7:13 pm
by Supplement
Additionally, I'd Imagine that I need to mysql_escape_string()???
I forget where it goes in the syntax.
Again, sorry for such a noob question.
