0

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.

Charles L.
  • 1,844
  • 2
  • 34
  • 56
  • Possible duplicate of http://stackoverflow.com/questions/10379624/how-to-pass-values-arguments-to-modal-show-function-in-bootstrap – Akshay Nov 02 '15 at 16:39
  • @Akshay not quit i did look through this, im trying to pull data from a database to fill the form with. – Charles L. Nov 02 '15 at 16:42
  • Try performing a `print_r ($results)` where `$results` is the returned value from `mysql_fetch_array`. If it doesn't print anything then there were no results and if the `email` shows up blank, well the field is empty – Jujunol Nov 02 '15 at 17:27
  • @Jujunol that actually grabbed something, its grabing the entire row of the array, it is also grabbing the row at the very top of the array? – Charles L. Nov 02 '15 at 18:21
  • @Charles Okay, when you say "grabbing the entire row of array" do you mean it's retrieving all the rows from the table? If you could more carefully explain the results then I believe I could produce an answer for you – Jujunol Nov 02 '15 at 19:10
  • @Jujunol of coures this is what its pulling into the input form `Array( [0] => 1 [id] => 1 [1] => KP [Rep] => KP [2] => 2015-09-01 00:00:00 [Date] => 2015-09-01 00:00:00 [3] => [email] => [4] => United Carrier Service, Inc. [Name] => United Carrier Service, Inc. [5] => [P_O] => [6] => [Due_Date] => [7] => [Terms] => [8] => [Aging] => [9] => 55.00 [Open_Balance] => 55.00)` – Charles L. Nov 02 '15 at 19:42

2 Answers2

0

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']?>">
Hadley8899
  • 136
  • 1
  • 12
  • That makes sense however it gave me this error mysqli_fetch_array() expects parameter 1 to be mysqli_result – Charles L. Nov 02 '15 at 16:49
  • Hmm wrap your query in an if statement and make sure your sql is not returning false, then if it is returning true run the fetch array. if($query = mysqli_query($connection,"SQL CODE HERE") { //Do the fetch array $datbase_array($query); } else { //Database query failed echo "Error Message"; } Could be a case that your using mysql_query() not mysqli_query() so try mysql_fetch_array() instead – Hadley8899 Nov 02 '15 at 16:52
  • its getting to the database because the table is being filled from the database. The problem i believe is your mixing mysqli and mysql. – Charles L. Nov 02 '15 at 16:54
  • Did you have any luck with using mysql_fetch_array() ? Also i thought the database connection variable had to be used in the mysql_query function ? – Hadley8899 Nov 02 '15 at 17:03
  • If i change it to mysql_fetch_array($query) it removes the error but still isnt filling the form – Charles L. Nov 02 '15 at 17:18
0

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!

Jujunol
  • 457
  • 5
  • 18