• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 161
  • Last Modified:

PHP MySQL not inserting data into database

I am trying to insert multiple rows of data into my DB.  My script appears to be working, showing me the confirmations on my page, but nothing gets inserted into the DB.  I setup a var_dump() and it shows the first row correctly.  Any help is appreciated.

 
// insert values to the DB here 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$count=mysql_num_rows($rsDesAcct);
$acctID = $_POST['acctID'];
$amount = $_POST['amount'];
$desclID = $_POST['acctgrpID'];
for($i=0; $i<$count; $i++){
mysql_select_db($database_con_portal_test, $con_portal_test);
  $SQL = "INSERT INTO tbldepbrk (depBrkAmnt, depBrkDate, depDesAcctID, depBrkClientID ) VALUES ('$amount[$i]' , '$_POST[date]' , '$acctID[$i]' , '$desclID')";
   
   if (!$SQL)
  {
  echo ('Error: ' . mysql_error($con_portal_test));
  }
}}
?>

Open in new window


 
// if your email succesfully sent
if(isset($_POST['submit1'])) {
if($SQL){
echo "Your Deposit Has Been Added - <a href='bookkeeping_depositenter.php'> Add Another</a>";
var_dump($SQL); 
} }

Open in new window

0
axessJosh
Asked:
axessJosh
  • 2
3 Solutions
 
Marco GasiFreelancerCommented:
You have to add mysql_query command:

$SQL = "INSERT INTO tbldepbrk (depBrkAmnt, depBrkDate, depDesAcctID, depBrkClientID ) VALUES ('$amount[$i]' , '$_POST[date]' , '$acctID[$i]' , '$desclID')";
mysql_query($SQL);
0
 
Chris StanyonCommented:
Nothing in your code is running the SQL statement. Your line that starts $SQL="... only prepares the SQL statement to run. You then need to give the command to run it, using mysql_query.


$SQL = "INSERT INTO tbldepbrk (depBrkAmnt, depBrkDate, depDesAcctID, depBrkClientID ) VALUES ('$amount[$i]' , '$_POST[date]' , '$acctID[$i]' , '$desclID')";

$result = mysql_query($SQL);

if (!$result)
{
echo ('Error: ' . mysql_error($con_portal_test));
}

Open in new window

0
 
Marco GasiFreelancerCommented:
if (!$SQL)

This line has no sense: $SQL is only a string which holds an sql query. The correct syntax is:

$SQL = "INSERT INTO tbldepbrk (depBrkAmnt, depBrkDate, depDesAcctID, depBrkClientID ) VALUES ('$amount[$i]' , '$_POST[date]' , '$acctID[$i]' , '$desclID')";
$result = mysql_query($SQL);

if (!$result)
  {
  echo ('Error: ' . mysql_error($con_portal_test));
  }

I suggest to read this book: http://www.sitepoint.com/books/phpmysql4/. It will give you many useful informations about Php and MySql :-)
0
 
axessJoshAuthor Commented:
Thanks Guys.

I had it working on another page before I transferred it to a new page.  Guess I should have cut and pasted the statement instead of re-writing.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now