Do i actually have to add each field into select table fields?
Using *
will select all fields.
But unless you need all fields it’s best to just list those you need separated by commas.
I thought you had this code working.
These are basic SQL failures, that haven’t changed between versions.
Means you didnt put quotes around things.
The table you’re referencing does not contain a field 'playfinder.
If you want to pull all the fields, you can specify the query as SELECT * FROM tablename, but its not considered best practice, if you’re not going to use all the fields.
Here is what I have now
<?php
include "connect.php";
$datalink = mysqli_connect($hostname,$username, $password, $dbname);
if (!$datalink) {
die('Unable to connect to database! Please try again later.' . mysqli_error());
}
mysqli_select_db;
$sql = 'SELECT DISTINCT "playfinder" FROM playfinder ORDER BY formation ASC';
/* ORDER BY playbook ASC */
$query = $sql;
$result = mysqli_query($datalink,$sql) or die(mysqli_error($datalink));
$header = mysqli_num_fields;
//echo '<p class="Heading"><strong>Madden 16 Play Finder</strong></p>';
//------------------------------------------------------------
// List Box
echo '<form id="form1" name="form1" method="post" action="formation.php">
<label><p class="Text"><strong>Choose Formation:
</strong></p></lable>
<select name="formation" id="formation">';
while ($row = mysqli_fetch_row($result))
{
for ($i=0; $i<$header; $i++)
{
if (!isset($row[$i])) //test for null value
{
echo "NULL";
}
else
{echo '<option value="' . $row[$i] . '">' . $row[$i].'</option>';}
}
}
echo '
</select>
</label>
</p>
<p>
<input type="submit" name="Select" id="Select" value="Submit" />
</p>
</form>';
mysqli_close($datalink);
?>
I did call my hosting company just a bit ago and they thought the code looked right. However, I am still now able to connect.
I thought we had established that connection was not the issue.
You are still putting the database name where the column names should be.
Sam, the database name is
maddengu_play_finder
the table name is
playfinder
I am able to connect to data base, just not able to pull the data from it.
…and the data you want is in columns called what??
I have four different playbook, formation, set, play
I have these 5 php files
connect
index
formation
set
play
Also this worked in version 5.2 but not in version 5.6
Thanks
If you like I can files if that helps, I am just confused on why this won’t work.
Driving me nuts, been up a good part of the night trying to figure it out.
The query should be something like:-
SELECT DISTINCT this_column, that_column, another_column FROM playfinder ORDER BY formation ASC
It may be best to test your queries in PhpMyAdmin to be sure the sql syntax is correct. Sometimes you don’t know if its the sql or php that’s wrong. Here I think it’s a bit of both, so one thing at a time.
Really you should be using at least version 7 and PDO is better than mysqli IMO. 5.6 is the very oldest you should be using, but support end at the end of this year, so it’s not a good time to “upgrade” to it.
Great about upgrade:. More or less, this a waste of time. I guess I either will have to learn the newer stuff or pay someone to upgrade it. Really don’t have much of choice it looks like.
Sam do you do this type of work for a charge? If so how much?
Thanks
It can still work in the short term if you get your syntax in order.
But my advice would be that if you are doing an upgrade, upgrade to something modern and current, not to something nearly obsolete.
mysqli will still work in php 7+ (unlike mysql) so you don’t have to go with pdo, but since you appear to new to mysqli, it may be worth starting out with pdo.
Your problem is this hanging line. Actually, you have quite a few hanging lines that do nothing.
Since you are still at the beginning of this, I would suggest that you throw this away and write a completely better one using the OOP
style instead of procedural. You don’t even need to upgrade PHP
versions, though I highly suggest that you upgrade because of security reasons. But in the case of using modern technology, you don’t necessarily need to upgrade since this modern technology was implemented a decade ago. So it is also supported in PHP
5.2 as well.
EDIT: So I am also picking up that the query is also failing. The ORDER BY
is causing the issue. I am looking into what is causing it to fail and trigger.
Actually, @SamA74 fixed this which I failed to see until now. So the issue with the query should be corrected using Sam’s pseudo query.
I think there are more errors further down the line, but one step at a time.
I far prefer to program with maximum error_reporting and display errors. The script stops until the errors are fixed.
Without this preferred setup it is like driving a car blindfolded; it is only a matter of time before a disastrous crash
The for
loop is also unnecessary. The while
loop already does the looping. Then there’s the HTML
. It’s missing a starting paragraph tag, then it’s using an extra label. This is why I emphasize on doing HTML
first because once you get the HTML
done correctly, you can replace the parts that require PHP
using PHP
. This makes it a whole lot easier without the need to go back and try to figure out what HTML
elements you are missing.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.