/    Sign up×
Community /Pin to ProfileBookmark

insert function inserting w/o mysql_query()

hello all, i’ve got an insert function set up and records are being inserted into my datasebase even tho “mysql_query( $sql, $con );” is commented out…

is this possible?

here is my code:

[CODE]
<?php
$max_insert = ($_POST[‘looper’]);

for ($a=1; $a <= $max_insert; $a++){

$sql=”INSERT INTO cars (#######)
VALUES (#######)”;

echo $_POST[“c_make_$a”];

//mysql_query( $sql, $con );

}

?>
[/CODE]

also any ideas why the for loop would insert the correct number of records and then insert the last record twice?? ?

thanks!

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@MrCoderJan 12.2007 — hello all, i've got an insert function set up and records are being inserted into my datasebase even tho "mysql_query( $sql, $con );" is commented out...

is this possible?[/QUOTE]



No.
Copy linkTweet thisAlerts:
@kreddauthorJan 12.2007 — then what is executing the sql?


[CODE]
<?php
$con = mysql_connect("mysql267.secureserver.net","kredd","lussier");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("kredd", $con);
?>

<?php

$max_insert = ($_POST['looper']);

for ($a=0; $a <= $max_insert; $a++){

$sql="INSERT INTO cars (c_make, c_model, c_year, c_color, c_trans, c_price, c_air, c_misc)
VALUES
("" . $_POST["c_make_$a"] . "","" . $_POST["c_model_$a"] . "","" . $_POST["c_year_$a"] . "","" . $_POST["c_color_$a"]. "","" . $_POST["c_trans_$a"] . "","" . $_POST["c_price_$a"] . "","" . $_POST["c_air_$a"] . "","" . $_POST["c_misc_$a"] . "")";


echo $_POST["c_make_$a"];


}
//mysql_query( $sql, $con );
?>


<?php

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}

mysql_close($con)

?>
[/CODE]
Copy linkTweet thisAlerts:
@MrCoderJan 12.2007 — if (!mysql_query($sql,$con))

That is.
Copy linkTweet thisAlerts:
@kreddauthorJan 12.2007 — thanks. i thot that code was only firing if it wasn't true.
Copy linkTweet thisAlerts:
@SheldonJan 12.2007 — i wouldnt recomend displaying your mysql username and password details. Any sort of half bad person with any php/mysql no how can hack and destroy your database
Copy linkTweet thisAlerts:
@NogDogJan 12.2007 — thanks. i thot that code was only firing if it wasn't true.[/QUOTE]
No, it executes the query, and then if the [i]result[/i] of the query evaluates as FALSE then the code which follows between the braces gets executed.
×

Success!

Help @kredd 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 5.17,
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: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

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

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...