0

I am trying to insert into a mysql database several items, with information passed from pagea.php. below is some code which is on pageb.php

foreach($_POST as $key => $val) { 



  $insertSQL = sprintf("INSERT INTO transactions (equipid, movement) VALUES (%s, %s)",
                   GetSQLValueString($key, "int"),
                   GetSQLValueString($val, "int"));

}

i am receiving the following error when the form is submitted on pageb.php (which initiates the insert).

Parse error: syntax error, unexpected 'GetSQLValueString' (T_STRING)

i am open to other ideas but essentially i have no way of knowing what values are being passed over so i cant define the specific fields to insert.

thanks!

  • It kinda depends on what `GetSQLValueString()` actually does, and whether you have included it in your script. Would you mind terribly showing us that as well – RiggsFolly Mar 03 '16 at 11:00
  • can you vardump your $_POST array? – Anonymous Duck Mar 03 '16 at 11:03
  • 1
    I just found another question asking about this function. Looking at it makes me think you are using the `mysql_` database extension still. **BAD** Please dont use [the `mysql_` database extension](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php), it is deprecated (gone for ever in PHP7) Especially if you are just learning PHP, spend your energies learning the `PDO` or `mysqli_` database extensions, [and here is some help to decide which to use](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – RiggsFolly Mar 03 '16 at 11:06
  • Wow thanks for the quick responses guys. Yep I can dump my array and comes out fine. But based on what Riggsfolly suggested I might have a look at mysqli extension before I go too far down the rabbit hole.. Thanks guys! – Patty Jay Mar 03 '16 at 11:35

0 Answers0