Click to See Complete Forum and Search --> : insert function inserting w/o mysql_query()
kredd
01-12-2007, 11:04 AM
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:
<?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 );
}
?>
also any ideas why the for loop would insert the correct number of records and then insert the last record twice?? :confused:
thanks!
MrCoder
01-12-2007, 01:45 PM
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?
No.
kredd
01-12-2007, 03:29 PM
then what is executing the sql?
<?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)
?>
MrCoder
01-12-2007, 03:32 PM
if (!mysql_query($sql,$con))
That is.
kredd
01-12-2007, 03:41 PM
thanks. i thot that code was only firing if it wasn't true.
Sheldon
01-12-2007, 04:19 PM
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
NogDog
01-12-2007, 05:25 PM
thanks. i thot that code was only firing if it wasn't true.
No, it executes the query, and then if the result of the query evaluates as FALSE then the code which follows between the braces gets executed.