lingo5 Posted June 3, 2011 Share Posted June 3, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/ Share on other sites More sharing options...
Zane Posted June 3, 2011 Share Posted June 3, 2011 $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. Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224767 Share on other sites More sharing options...
lingo5 Posted June 3, 2011 Author Share Posted June 3, 2011 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]'.... Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224773 Share on other sites More sharing options...
Zane Posted June 3, 2011 Share Posted June 3, 2011 are you even sure that $_POST['id_cliente'] contains anything? Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224777 Share on other sites More sharing options...
lingo5 Posted June 3, 2011 Author Share Posted June 3, 2011 you're right it doesn´t contain anything. I'm not sure what I want to do is possible. I want the user to select a company name from a combo and send it to the databse together with he company's id....do I make any sense? Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224780 Share on other sites More sharing options...
Zane Posted June 3, 2011 Share Posted June 3, 2011 What does your form look like.. and how are you attempting to send this id right now? Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224783 Share on other sites More sharing options...
lingo5 Posted June 3, 2011 Author Share Posted June 3, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224788 Share on other sites More sharing options...
Zane Posted June 3, 2011 Share Posted June 3, 2011 Ok, so from this code, I see that id_cliente is coming from $row_clientes_RS['id_cliente'] i.e an array called $row_clientes_RS Where's the query at for $clientes_RS Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224790 Share on other sites More sharing options...
lingo5 Posted June 3, 2011 Author Share Posted June 3, 2011 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')"; Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224795 Share on other sites More sharing options...
Zane Posted June 3, 2011 Share Posted June 3, 2011 Ok, let me rephrase the question. Where do you decalare $clientes_RS? Post that and the code around it. Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224798 Share on other sites More sharing options...
lingo5 Posted June 3, 2011 Author Share Posted June 3, 2011 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); Quote Link to comment https://forums.phpfreaks.com/topic/238326-help-with-array/#findComment-1224799 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.