Multiple Questions php, html & mysql related

Place for questions and answers for all newcomers and new coders. This is a free for all forum, no question is too stupid and to noob.
Post Reply
jwoolman0
Posts: 10
Joined: Sun Feb 03, 2013 2:51 am

Multiple Questions php, html & mysql related

Post by jwoolman0 »

If anyone is interested in the answers to the issues I had in this OP they are covered in Halls reply on page 2.

Just to inform responders: I look for as many answers as possible through many different locations before posting here...unfortunately coding is a PAI to find solutions for as almost everything overlaps...(ex: How to make a table in php leads to a ton of mysql database tables...etc..) Needless to say I'm only posting here as a last resort...

First Question was in regard to Query issues. Still have a lot of problems with them but I've moved on....(here to acknowledge responses)

Current issues:
$playerinfo="SELECT * from users where username='Vlad'";
I can't for the life of me figure out how to create a username variable without actually entering the name in the blank...
Is login/authenticate/reguser/register/session etc... intended to create the "name" that links to the $username variable...
The Query question doesn't really make sense (though I assume it's written wrong since it obviously doesn't work)
$query = "select username from users where username='username' and password='password'";
For information: My table is users In my table my player reference is username and password is password

Next issue:
echo "<center><table width= '150' cellspacing='5' cellpadding='30' border='10'>";
echo "<tr><td bgcolor=lightblue>".$playerinfo3['username'] . $gold['gold'];
echo "</body></center></table>";

The above code works....it creates a table and shows the players username and gold...unfortunately I couldn't figure out how to space the two of them.
Google mentions \n and I'm aware of &nbsp and one page mentioned '<br>' NONE worked...or I inputted them incorrectly which wouldn't be unlikely.
All I want to do is put a stupid SPACE inbetween the two...so I'm sure you understand the frustration when I've fiddled with that line for over an hour.
(though in that time I actually got the variables to work etc...so wasn't all dead time)

Next issue:
With the above issue can someone please explain how a table works in php code...html is a cakewalk. php is a touchmenot...and I can't get a second row going.
If not it's fine I'm considering placing my variables inside an html table anyway. I just hit roadblocks with that originally (not understanding variables and all) so I changed directions and in doing so found a reference to my previous problem which may be a SOLUTION...

I'm posting multiple issues because the response time is rather slow and it's 2am so I doubt I'll have an answer soon. Most likely I'll find my answers before I get a response but that's a win-win anyway :lol:
Also still no clue how to get errors to show up other than "error etc in line 25" but I'm getting by anyway. If you can't fix it...pretend it ain't broke. :roll: :lol:
I do appreciate all help...I understand that everything is on my end and that despite heaps of knowledgeable information I'm still the only one with the wrench in my hand.
Last edited by jwoolman0 on Tue Feb 05, 2013 12:55 pm, edited 3 times in total.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Having a lot of Query issues...

Post by Jackolantern »

You need to be outputting the errors from your MySQL queries. Here is a page outlining how to check the errors from a MySQL query. Here is some code from that page showing how to output MySQL errors:

Code: Select all

<?php
$link = mysql_connect("localhost", "mysql_user", "mysql_password");

mysql_select_db("nonexistentdb", $link);
echo mysql_errno($link) . ": " . mysql_error($link). "\n";

mysql_select_db("kossu", $link);
mysql_query("SELECT * FROM nonexistenttable", $link);
echo mysql_errno($link) . ": " . mysql_error($link) . "\n";
?>
The indelible lord of tl;dr
jwoolman0
Posts: 10
Joined: Sun Feb 03, 2013 2:51 am

Re: Having a lot of Query issues...

Post by jwoolman0 »

Not sure where to put that... :?
Any file? Connect? Does it matter?
And in regards to the username and pass? (if those haven't been filled out yet)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Having a lot of Query issues...

Post by Jackolantern »

The important part is this:

Code: Select all

echo mysql_errno($link) . ": " . mysql_error($link) . "\n"; 
Remove the "or die()" clause from any query that is dying, and then add that line directly below it. That will give you the MySQL error info.
The indelible lord of tl;dr
jwoolman0
Posts: 10
Joined: Sun Feb 03, 2013 2:51 am

Re: Having a lot of Query issues...

Post by jwoolman0 »

Thank you very much =)
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Having a lot of Query issues...

Post by Jackolantern »

No problem! If you are still having problems with it, let us know what the error was, and at which query :)
The indelible lord of tl;dr
jwoolman0
Posts: 10
Joined: Sun Feb 03, 2013 2:51 am

Re: Multiple Questions php, html & mysql related

Post by jwoolman0 »

Not sure if bumping is allowed...but edits don't change who last posted so....*nudge*
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Multiple Questions php, html & mysql related

Post by Jackolantern »

The best thing to do is to post any new issues at the bottom of the thread in new responses. The original post is very unlikely to be re-read as the thread goes on.

Tables in PHP are the exact same thing as HTML tables (you are just generating the code for them in PHP). Can you post your code that is generating the tables, and we can try to spot any errors in it!
The indelible lord of tl;dr
jwoolman0
Posts: 10
Joined: Sun Feb 03, 2013 2:51 am

Re: Multiple Questions php, html & mysql related

Post by jwoolman0 »

I listed all the code and information that pertained to each individual error I had. The error is not outside of the information I provided. That is certain.
For example the spacing issue in the PHP table (which due to the coding is heavily error prone compared to html..not even going to bother with the comparison)
The spacing issue can only be resolved by placing something inbetween the variables of playerinfo3 etc and gold...As the only issue is a linebreak of space.
Visual Aid: Username=Vlad Gold=0 Vlad0
I've solved the issue by switching back to html and placing the php coding within it.

Only other issue is that when the variable listing an integer is present (In any table) only the first digit is shown. Which currently doesn't make sense but I'll figure it out.

If you are unable to help that is fine as explained in the initial post. There is simply no more information to provide.

Edit:
Just to reference what I was saying:
$playerinfo3['username'] . $gold['gold'];
I've already provided the line that needs the space. I've already explained that I don't know how to space it. No further information is necessary.
It shows as: usernamegold
Obviously after variable translation but the fact remains...it just needs a space or line break.
User avatar
Jackolantern
Posts: 10891
Joined: Wed Jul 01, 2009 11:00 pm

Re: Multiple Questions php, html & mysql related

Post by Jackolantern »

PHP concatenation (adding text together) will do exactly what you ask it to, almost to a fault. For example:

Code: Select all

$first = "Bob";
$last = "Jackson";

echo $first.$last;  //  <----will echo "BobJackson" with no space  
What you want to do is just throw in a space in the middle like this:

Code: Select all

$first = "Bob";
$last = "Jackson";

echo $first." ".$last;  //  <---will now correctly echo "Bob Jackson" with a space  
You are just adding in a string with one space between the two values you are concatenating.
The indelible lord of tl;dr
Post Reply

Return to “Beginner Help and Support”