# help w/mysqli



## ckir5951 (Nov 16, 2014)

Hi guys, the below code creates my dropdown. 
I select the record and submit and the selected record is displayed.
------------------------------------------------------------------
<!DOCTYPE>email menu


<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';

//This creates the drop down box
echo "";
echo ''.'--- Select email account ---'.'';
$query = mysqli_query($con,"SELECT target FROM lookuptbl");
$query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
while($row=mysqli_fetch_array($query))
{echo "".$row['target']
.'';}
echo '';
?>


<!DOCTYPE>email menu


<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT target, purpose, user, password, email, visits, date,
saved FROM lookuptbl WHERE target = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}

//display the table
echo '
'. 'Email menu'. ''.'

'.'
'.'
<td bgcolor="#CFB53B>'.'target'.'
'.'
'.'
'.'
';
echo '
'.'

 $data[0]$data[1]$data[2]$data[3]$data[4]$data[5]$data[6]$data[7]
'.'
<td bgcolor="#ccffff>'.'purpose'. '[/TD]'.'
<td bgcolor="#ccffff>'.'user'.'[/TD]'.'
<td bgcolor="#ccffff>'.'password'.'[/TD]'.'
<td bgcolor="#ccffff>'.'email'.'[/TD]'.'
<td bgcolor="#CFB53B>'.'visits'. '[/TD]'.'
<td bgcolor="#CFB53B>'.'date'.'[/TD]'.'
<td bgcolor="#CFB53B>'. 'saved' .'[/TD]'.'
';
while($data=mysqli_fetch_row($result))
{echo ("
");}
echo '
'.'[/TD]'.'
'.'';
}
?>

=========================================

but the headers
should be: target purpose user password email visits date saved
but are: purpose password visits saved
target,user,email,and date are skipped (every other heading is skipped)?
-----------------------------------------------
a screenshot is included to illustrate
--------------------------------------------
What's left after is that I want include a button to link to the target.
suggestions?​


----------



## JiminSA (Dec 15, 2011)

Your table:

```
//display the table
echo '[TABLE]'.'[TR]'.'[TD]'. 'Email menu'. '[/TD]'.'[/TR]';
echo '[TR]'.'[TD]'.'[TABLE]'.'[TR]'.'
<td bgcolor="#CFB53B>'.'target'.'[/TD]'.'
<td bgcolor="#ccffff>'.'purpose'. '[/TD]'.'
<td bgcolor="#ccffff>'.'user'.'[/TD]'.'
<td bgcolor="#ccffff>'.'password'.'[/TD]'.'
<td bgcolor="#ccffff>'.'email'.'[/TD]'.'
<td bgcolor="#CFB53B>'.'visits'. '[/TD]'.'
<td bgcolor="#CFB53B>'.'date'.'[/TD]'.'
<td bgcolor="#CFB53B>'. 'saved' .'[/TD]'.'[/TR]';
while($data=mysqli_fetch_row($result)){
echo '[TR][TD]'.$data[0].'[/TD]
[TD]'.$data[1].'[/TD]
[TD].'$data[2].'[/TD]
[TD]'.$data[3].'[/TD]
[TD]'.$data[4].'[/TD]
[TD]'.$data[5].'[/TD]
[TD]'.$data[6].'[/TD]
[TD]'.$data[7].'[/TD][/TR]';
}
echo '[/TABLE]'.'[/TD][/TR][/TABLE]';
```
has superfluous stuff:

```
//display the table
echo '[TABLE][TR][TD]Email menu[/TD][/TR]
[TR][TD][TABLE]
<th bgcolor="#CFB53B>target[/TH]
<th bgcolor="#ccffff>purpose[/TH]
<th bgcolor="#ccffff>user[/TH]
<th bgcolor="#ccffff>password[/TH]
<th bgcolor="#ccffff>email[/TH]
<th bgcolor="#CFB53B>visits[/TH]
<th bgcolor="#CFB53B>date[/TH]
<th bgcolor="#CFB53B>saved[/TH][/TR]';
while($data=mysqli_fetch_row($result)){
echo '[TR][TD]'.$data[0].'[/TD]
[TD]'.$data[1].'[/TD]
[TD].'$data[2].'[/TD]
[TD]'.$data[3].'[/TD]
[TD]'.$data[4].'[/TD]
[TD]'.$data[5].'[/TD]
[TD]'.$data[6].'[/TD]
[TD]'.$data[7].'[/TD][/TR]';
}
echo '[/TABLE]'.'[/TD][/TR][/TABLE]';
```
... there were spaces included in some of the '.' joiners you were unnecessarily using (viz - '. '), which I think affected the display ...


----------



## colinsp (Sep 5, 2007)

You have some problems there with your table. Use th rather than td for your headings.

Your echo is totally wrong for the results.

```
while($data=mysqli_fetch_row($result)){
echo '[TR][TD]'.$data[0].'[/TD]
[TD]'.$data[1].'[/TD]
[TD].'$data[2].'[/TD]
[TD]'.$data[3].'[/TD]
[TD]'.$data[4].'[/TD]
[TD]'.$data[5].'[/TD]
[TD]'.$data[6].'[/TD]
[TD]'.$data[7].'[/TD][/TR]';
}
echo '[/TABLE]';
}
```


----------



## ckir5951 (Nov 16, 2014)

here is what I tried. of course no go:

<!DOCTYPE>lookup menu


<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';

//This creates the drop down box
echo "";
echo ''.'--- Select account ---'.'';
$query = mysqli_query($con,"SELECT target FROM lookuptbl");
$query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
while($row=mysqli_fetch_array($query))
{echo "".$row['target']
.'';}
echo '';
?>



<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT target, purpose, user, password, email, visits, date,
saved FROM lookuptbl WHERE target = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}

//display the table
echo '
lookup menu



[TH]target[/TH]

[TH]purpose[/TH]
[TH]user[/TH]
[TH]password[/TH]
[TH]email[/TH]
[TH]visits[/TH]
[TH]date[/TH]
[TH]saved[/TH]
[TD]

$data[0]$data[1]$data[2]$data[3]$data[4]$data[5]$data[6]$data[7]
';
while($data=mysqli_fetch_row($result))
{echo ("
");}
echo '
'.'[/TD]'.'[/TR]'.'';
}
?>
[/I][/I]​


----------



## colinsp (Sep 5, 2007)

Your echo at the bottom to display the data from your database is still totally wrong use the code I posted and then come back.


----------



## JiminSA (Dec 15, 2011)

colinsp said:


> Your echo at the bottom to display the data from your database is still totally wrong use the code I posted and then come back.


Yes please do, as it affects the header display, which without the db interrogate displays correctly. (You do not join your db variables using '.')


----------



## ckir5951 (Nov 16, 2014)

current code:
------------------------------------------------------------------------
<!DOCTYPE>email menu


<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';

//This creates the drop down box
echo "";
echo ''.'--- Select email account ---'.'';
$query = mysqli_query($con,"SELECT target FROM lookuptbl");
$query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
while($row=mysqli_fetch_array($query))
{echo "".$row['target']
.'';}
echo '';
?>


<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT target, purpose, user, password, email, visits, date,
saved FROM lookuptbl WHERE target = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}

//display the table
echo '
Email menu


<th bgcolor="#CFB53B>target[/TH]
<th bgcolor="#ccffff>purpose[/TH]
<th bgcolor="#ccffff>user[/TH]
<th bgcolor="#ccffff>password[/TH]
<th bgcolor="#ccffff>email[/TH]
<th bgcolor="#CFB53B>visits[/TH]
<th bgcolor="#CFB53B>date[/TH]
<th bgcolor="#CFB53B>saved[/TH]
[TD]

'.$data[0].''.$data[1].'.'$data[2].''.$data[3].''.$data[4].''.$data[5].''.$data[6].''.$data[7].'
';
while($data=mysqli_fetch_row($result)) 
{
echo '
';
}
echo '
'.'[/TD]'.'[/TR]'.'';
}
?>

=============================================
gets:
Parse error: syntax error, unexpected '$data' (T_VARIABLE), expecting ',' or ';' in C:\xampp\htdocs\home\crue-link.php on line 50​


----------



## colinsp (Sep 5, 2007)

Please post your code in code tags it makes it easier to read. Use the icon to the left of the disk one above.

Presumably your file has a php file name if not it needs to. Also as it is a php file it needs to have php right at the start. You have duplicated line which are unnecessary I have commented out those. You really do need to read up on php syntax so that you understand what you are doing rather than relying on others to do it for you.

Is this live? If so post the url.

Give this a try I have corrected your error with a wrongly placed . BUT I haven't run it


```
<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';
?>

<!DOCTYPE>email menu
[CENTER]

<?php
//This creates the drop down box
echo "";
echo ''.'--- Select email account ---'.'';
$query = mysqli_query($con,"SELECT target FROM lookuptbl");
$query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
while($row=mysqli_fetch_array($query))
{echo "".$row['target']
.'';}
echo '';
?>


<?php
// error_reporting(0);
//error_reporting(E_ALL ^ E_NOTICE); You have already defined this
//include 'homedb-connect.php'; You have already included this
if(isset($_POST['target']))
{
$name = $_POST['target'];
$fetch="SELECT target, purpose, user, password, email, visits, date,
saved FROM lookuptbl WHERE target = '".$name."'";
$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}

//display the table
?>

[TABLE]
    Email menu
[TR]
<th bgcolor="#CFB53B>target[/TH]
<th bgcolor="#ccffff>purpose[/TH]
<th bgcolor="#ccffff>user[/TH]
<th bgcolor="#ccffff>password[/TH]
<th bgcolor="#ccffff>email[/TH]
<th bgcolor="#CFB53B>visits[/TH]
<th bgcolor="#CFB53B>date[/TH]
<th bgcolor="#CFB53B>saved[/TH]
[/TR]

<?php
while($data=mysqli_fetch_row($result))
{
echo '[TR][TD]'.$data[0].'[/TD]
[TD]'.$data[1].'[/TD]
[TD]'.$data[2].'[/TD]
[TD]'.$data[3].'[/TD]
[TD]'.$data[4].'[/TD]
[TD]'.$data[5].'[/TD]
[TD]'.$data[6].'[/TD]
[TD]'.$data[7].'[/TD][/TR]';
}
?>
[/TABLE]
```


----------



## JiminSA (Dec 15, 2011)

I presume that this:

```
[TD].'$data[2].'[/TD]
```
is line 50 ...
Do you see the error? Your first connector dot is being treated as a literal character - it must be next to the variable that it is being joined on.


----------



## colinsp (Sep 5, 2007)

JiminSA said:


> I presume that this:
> 
> ```
> [TD].'$data[2].'[/TD]
> ...


That's the bug I fixed @JiminSA


----------



## JiminSA (Dec 15, 2011)

colinsp said:


> That's the bug I fixed @JiminSA


No denying that @colinsp and thank you. I was simply attempting to explain to the Original Poster why it was an error ...


----------



## ckir5951 (Nov 16, 2014)

ll the code below is intended to and does create a dropdown which selects a record(url)
and submit produces and does not display a table row with a link to the record.
"select & submit" goes back to "select & submit". I've been working on this a long time.
anyone work with mysqli?
-----------------------------------------------------------------
<!DOCTYPE>
lookup menu

*

<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';

//This creates the drop down box
echo "";
echo ''.'--- Select account ---'.'';
$query = mysqli_query($con,"SELECT target FROM lookuptbl");
$query_display = mysqli_query($con,"SELECT * FROM lookuptbl");
while($row=mysqli_fetch_array($query))
{echo "".$row['target']
.'';}
echo '';
?>



<?php
// error_reporting(0);
error_reporting(E_ALL ^ E_NOTICE);
include 'homedb-connect.php';

// ==============================================
if(isset($_GET['target']))
{
$target = $_GET['target'];
// ===============================================
$fetch="SELECT target, purpose, user, password, email, visits, date, saved
FROM lookuptbl WHERE target = '". mysqli_real_escape_string ( $con , $target ) . "'";
// ===============================================================================

$result = mysqli_query($con,$fetch);
if(!$result)
{echo "Error:".(mysqli_error($con));}

//display the table
echo '
lookup menu

 Target  Purpose  User  Password  Email  Visits  Date  Saved  $link $data[1]$data[2]$data[3]$data[4]$data[5]$data[6]$data[7]
';
while($data=mysqli_fetch_row($result)) 
{
// ==========================================================
$url= "
http://localhost/home/crud-link.php?target=
". $data[0];
$link= '
'. $data[0]. '
';
// ===========================================================

echo ("
");
} 
echo ' 
';
}
?>​*​


----------



## colinsp (Sep 5, 2007)

We have offered you help with this but you clearly don't want to do what we suggest, your code is wrong. So until you do no further help from me.


----------



## JiminSA (Dec 15, 2011)

When you have a fresh problem, please submit a fresh thread. This improves your chances of getting fresh help, as you do not use the advice given by Colin and I, so far.
TIP: $_GET is used to interrogate the url, $_POST is used to interrogate the form and $_REQUEST is used to interrogate either.


----------

