Jump to content

Recommended Posts

Hi, I have a combo box populated with values from my database.

I want the user to select a company name and send 2 different values to the DB.

This is what I did

$email[] = array($_POST['id_cliente'], $_POST['cliente_email']);
$facturatitle = $_POST["factura_title"];
//paso la fecha inicial a formato mysql, tomo la fecha la convierto a una array y luego en 3 variables, luego las concateno en formato año/mes/dia
list($dia,$mes,$ano)=explode("/",$_POST['factura_date']);
$facturadate="$ano/$mes/$dia";
$facturanumber=$_POST["factura_number"];
$estadofactura=$_POST["estadofactura_titulo"];

$query = "INSERT INTO database.t_facturas (id_cliente, cliente_email, factura_title, factura_date, factura_number,estadofactura_titulo,factura_path) ".
"VALUES ('$email[0]','$email[1]','$facturatitle','$facturadate','$facturanumber','$estadofactura','$filePath')";

mysql_query($query) or die('Error, query failed : ' . mysql_error()); 

The information gets saved ok except for the values in the array. Needless to say what a newbie I am. Thanks all.

Link to comment
https://forums.phpfreaks.com/topic/238326-help-with-array/
Share on other sites

$email[] = array($_POST['id_cliente'], $_POST['cliente_email']);

This is the wrong way to populate an array.

This would make a multidimensional array.

 

Another approach you can use, while still keeping the brackets is

$email[] = $_POST['id_cliente']
$email[] = $_POST['cliente_email']

But if you really want to use the array function for a one-liner, then you'll have to ditch the brackets.

Link to comment
https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224767
Share on other sites

Thanks Zanus,

this is what i've done now

$email = array($_POST['id_cliente'], $_POST['cliente_email']);

but this is only saving 'cliente_email' on the DB.

This is my add record query

$query = "INSERT INTO airgom.t_facturas (id_cliente, cliente_email, factura_title, factura_date, factura_number,estadofactura_titulo,factura_path) ".
"VALUES ('$email[0]','$email[1]','$facturatitle','$facturadate','$facturanumber','$estadofactura','$filePath')";

I am not sure about the '$email[0]','$email[1]'....

Link to comment
https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224773
Share on other sites

Sorry zanus, I explained it wrong.

I have this form

<form action="<?php $PHP_SELF;?>" method="post" enctype="multipart/form-data">
  <table align="center" cellpadding="10">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Factura para:</td>
      <td><label>
        <select name="cliente_email" id="cliente_email">
          <option value="value">Seleccione cliente</option>
          <?php
do {  
?>
<option value="<?php echo $row_clientes_RS['id_cliente']?>"><?php echo $row_clientes_RS['company_name']?></option>
          <?php
} while ($row_clientes_RS = mysql_fetch_assoc($clientes_RS));
  $rows = mysql_num_rows($clientes_RS);
  if($rows > 0) {
      mysql_data_seek($clientes_RS, 0);
  $row_clientes_RS = mysql_fetch_assoc($clientes_RS);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Título factura:</td>
      <td><input type="text" name="factura_title" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Fecha factura:</td>
      <td><input type="text" name="factura_date" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Nº factura:</td>
      <td><input type="text" name="factura_number" value="" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Estado factura</td>
      <td><label>
        <select name="estadofactura_titulo" id="estadofactura_titulo">
          <option value="">Seleccione estado</option>
          <?php
do {  
?>
          <option value="<?php echo $row_estadofacturas_RS['estadofactura_titulo']?>"><?php echo $row_estadofacturas_RS['estadofactura_titulo']?></option>
          <?php
} while ($row_estadofacturas_RS = mysql_fetch_assoc($estadofacturas_RS));
  $rows = mysql_num_rows($estadofacturas_RS);
  if($rows > 0) {
      mysql_data_seek($estadofacturas_RS, 0);
  $row_estadofacturas_RS = mysql_fetch_assoc($estadofacturas_RS);
  }
?>
        </select>
      </label></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"> </td>
      <td><input type="file" name="factura_path" id="factura_path" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right"> </td>
      <td><input name="upload" type="submit" id="upload" value="insertar factura" /></td>
    </tr>
  </table>
  <input type="hidden" name="MM_insert" value="form1" />
</form>

 

What I'm trying to do is to send TWO values to the database 'id_cliente' and 'cliente_email' when the user selects a company from the drop down list.

Link to comment
https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224788
Share on other sites

This is the query

$email = array($_POST['id_cliente'], $_POST['cliente_email']);
$facturatitle = $_POST["factura_title"];

list($dia,$mes,$ano)=explode("/",$_POST['factura_date']);
$facturadate="$ano/$mes/$dia";
$facturanumber=$_POST["factura_number"];
$estadofactura=$_POST["estadofactura_titulo"];

$query = "INSERT INTO airgom.t_facturas (id_cliente, cliente_email, factura_title, factura_date, factura_number,estadofactura_titulo,factura_path) ".
"VALUES ('$email[0]','$email[1]','$facturatitle','$facturadate','$facturanumber','$estadofactura','$filePath')";

Link to comment
https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224795
Share on other sites

Sorry here it is

mysql_select_db($database_MySQLconnect, $MySQLconnect);
$query_clientes_RS = "SELECT * FROM t_clientes";
$clientes_RS = mysql_query($query_clientes_RS, $MySQLconnect) or die(mysql_error());
$row_clientes_RS = mysql_fetch_assoc($clientes_RS);
$totalRows_clientes_RS = mysql_num_rows($clientes_RS);

Link to comment
https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224799
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.