简体   繁体   English

获取php以自动填充来自Mysql的电子邮件地址

[英]Getting php to autofill an email address from Mysql

I have a working form that allows the user to add invoices to a database, it will then display the invoices in a table, within the table there in a email button within the Name section. 我有一个工作表,允许用户将发票添加到数据库中,然后它将在表中的表格中显示发票,该表位于“ Name部分内的电子邮件按钮中。 When the user clicks the button it will pull up a bootstrap modal that asks for the email, subject, and content. 当用户单击按钮时,它将弹出一个引导程序模版,询问您的电子邮件,主题和内容。 It will then shoot an email address to the entered email address. 然后它将拍摄一个电子邮件地址到输入的电子邮件地址。 This is working perfectly, however i would now like it to grab the email address that's associated with the name inside the database. 这是完美的工作,但是我现在希望它获取与数据库中的名称关联的电子邮件地址。

This is what i've been trying with no success 这是我一直没有成功的尝试

Home.php Home.php

<div class="form-group">
  <label class="col-md-4 control-label" for="email">Email:</label>  
  <div class="col-md-5">
  <input id="email" name="email" type="text" placeholder="placeholder@gmail.com" class="form-control input-md" 
  value="<?php echo $query['email']?>">

   </div>
 </div>

up in my code im connecting o the database like this 在我的代码中我像这样连接数据库

        $query = mysql_query("SELECT id, Rep, Date, email, Name, P_O, ADDDATE(Date, Terms) AS Due_Date, Terms, GREATEST(DATEDIFF(NOW(), ADDDATE(Date, Terms)), 0) AS Aging, Open_Balance from Book1");

So what im looking for is when the suer clicks the email button next to the customers Name, it will auto fill the modal with the emailaddress thats in the same ROW as the Name. 因此,我要寻找的是当用户单击客户名称旁边的电子邮件按钮时,它将自动使用与名称相同的ROW中的电子邮件地址填充模式。

You will need to do $database_array = mysqli_fetch_array($query)then echo $database_array['email']; 您将需要执行$ database_array = mysqli_fetch_array($ query),然后执行echo $ database_array ['email'];

$query = mysql_query("SELECT id, Rep, Date, email, Name, P_O, ADDDATE(Date, Terms) AS Due_Date, Terms, GREATEST(DATEDIFF(NOW(), ADDDATE(Date, Terms)), 0) AS Aging, Open_Balance from Book1");

$database_array = mysqli_fetch_array($query);

<input id="email" name="email" type="text" placeholder="placeholder@gmail.com"     class="form-control input-md" 
value="<?php echo $database_array['email']?>">

It appears to me that the row you're attempting to pull doesn't have an email value ( [email] => [4] ... ). 在我看来,您要提取的行没有电子邮件值( [email] => [4] ... )。 Reassure that the row you're pulling has a value in the email column. 请确保您要拉的行在“电子邮件”列中具有一个值。

Also I realized that your SQL doesn't have a WHERE clause (meaning multiple rows could return if more than one row exist in the table). 我也意识到您的SQL没有WHERE子句 (意味着如果表中存在多行,则可能返回多行)。 Hope this helps! 希望这可以帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM