简体   繁体   中英

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. 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

<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.

You will need to do $database_array = mysqli_fetch_array($query)then 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] ... ). 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). Hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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