| Author |
mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
I know I'm going to get flamed for this, but what the heck I like spyware anyway ^^
I've just started learning mysql & php and as a first impression I might say that things seems rather easy to understand, yet when I try to connect to my MySQL server using php, nothing happens O.o
I'm using one.com as host
<?php
mysql_connect("dbadmin.one.com", "username goes here", "password goes here") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("database goes here") or die(mysql_error());
echo "Connected to Database";
?>
what the heck am I doing wrong? x_x
edit: dbadmin.one.com --> is the MyPhpAdmin address, there is no other address to connect to, so... where do I go from here? :P
Edited by Demons Halo on 20-07-09 10:16 |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
|
MoshBat wrote:
For starters, "localhost".
come on.. how stupid am I :'( ofc it's localhost since the freaking file is already on the host server -__________-
anyway keep tune, more stupid questions will show up eventually 
thnx pikabat (L)
|
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
|
MoshBat wrote:
No.
No.
Rather than "blah.one.com", "localhost".
And let me take another look at that scblockedript.
ah I got that, stupid noob mistake by me not to put localhost from the start
<?php
mysql_connect("localhost", "username", "pass") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("demonshalo_com") or die(mysql_error());
echo "Connected to Database";
$query = "SELECT * FROM test"
$result = mysql_query($query) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());
echo $row['id']. " - ". $row['testare'];
?>
in MyPhpAdmin I've created a table called test with 2 fields (id, testare). So far I can connect and select a database, but I can't seem to show the content of the table. :/
edit: I'm probably going to get pawned for posting the code here...
Edited by Demons Halo on 20-07-09 10:37 |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
awesome, I got it working as well but I hate how you guys make the code seem so clean and professional -_-
$row = mysql_fetch_array($result) or die(mysql_error());
the little "or die(mysql_error())" messed everything up, once I removed it everything worked.
hmm a while loop to print out all the rows =O nice! thnx =D
edit: I'm not here to copy/paste... I'm hear to learn from you holy one! *_'
Edited by Demons Halo on 20-07-09 10:46 |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
as long as I understand the concept I don't care if you color or use black text & black background -_- what idea? O.o
haha that's some "sexy" code right there... NOT
"EDIT#2: Whilst we're here, and I'm bored, any more PHP issues?"
they will eventually pop-up If you've got some advice for a beginner don't hesitate to post them xD
Edited by Demons Halo on 20-07-09 10:55 |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
MoshBat wrote:
Demons Halo wrote:
If you've got some advice for a beginner don't hesitate to post them xD
Don't be scared to post your problems.
I was nice, was I not?
Also, you can contact me in any way you wish, (except perhaps sending your problem via traditional mail, written in your own faeces) and I'll be more than happy to help you.
you're always nice =D and just for the record: I like getting flamed XD
haha thnx a lot, I really appreciate it.
I have a security question though. A lot of the exploits/hacks done on the web are SQL based, how do I avoid those security issues?
Edited by Demons Halo on 20-07-09 11:41 |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
I'll check that out asap!
here is my first project using php/mysql:
I'm going to build a photo gallery using a table with the fields: id, picture, comment and date.
correct me if I'm wrong but this is how a table should look like:
--------------------------------------------------
| id | picture | comment | date |
--------------------------------------------------
| 1 | images/lal.jpg | rofl lmao wtf? | CURDATE() |
---------------------------------------------------
now using php I should do something like:
$result = mysql_query("SELECT * FROM gallery");
while($row = mysql_fetch_array($result)){
$picture= $row['picture'];
$comment = $row['comment'];
$date = $row['date'];
print "<img src=$picture>- comment: $comment - date: $date <br />";
}
This doesn't work, so I need to know how to load an image to the browser using php. I've found a lot using google, but unfortunately the shortest code I could understand was half a page long -_- is there any easy way to do this?
Edit: I got it working. Minor problem with the quote marks xD
Edited by Demons Halo on 20-07-09 12:51 |
|
| Author |
RE: mysql/php |
SySTeM
-=[TheOutlaw]=-
Posts: 1524
Location: England, UK
Joined: 27.07.05 Rank: The Overlord |
|
MoshBat wrote:
Demons Halo wrote:
I'll check that out asap!
here is my first project using php/mysql:
I'm going to build a photo gallery using a table with the fields: id, picture, comment and date.
correct me if I'm wrong but this is how a table should look like:
--------------------------------------------------
| id | picture | comment | date |
--------------------------------------------------
| 1 | images/lal.jpg | rofl lmao wtf? | CURDATE() |
---------------------------------------------------
now using php I should do something like:
$result = mysql_query("SELECT * FROM gallery");
while($row = mysql_fetch_array($result)){
$picture= $row['picture'];
$comment = $row['comment'];
$date = $row['date'];
print "<img src=$picture>- comment: $comment - date: $date <br />";
}
Edit: I got it working. Minor problem with the quote marks xD
For the benefit of those who may suffer similar problems:
$result = mysql_query("SELECT * FROM gallery ORDER BY id ASC");
while($row = mysql_fetch_array($result)){
$picture= $row['picture'];
$comment = $row['comment'];
$date = $row['date'];
print "<img src='$picture' /> - comment: $comment - date: $date<br />";
}
Note the added apostrophes ('), and the / in the img tag :)
If memory serves, not closing the img tag can cause fuckups in IE6.
Self-closing tags are needed for XHTML, however they aren't for standard HTML, so it won't cause fuckups in IE6.
Also, use "echo" instead of "print", it's faster.

|
|
| Author |
RE: mysql/php |
spyware
Member

Posts: 4190
Location: The Netherlands
Joined: 14.04.07 Rank: God Warn Level: 90
|
|
|
MoshBat wrote:
At his level, mere milliseconds don't really matter.
It doesn't matter whether it matters now. It could matter in the future.
Suboptimal programming is stupid.

"The chowner of property." - Zeph Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term. - Carl Sagan Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor? - Ebert |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
emm print returns boolean as well right? while echo just "writes" stuff 
edit: another question:
what alternatives are there for loading a page inside of another page? php include / Iframe / jQuery are the ones I know of, any other methods?
using php includes would make the entire site reload, which I actually don't mind, but I'm just wondering what the best method is 
Edited by Demons Halo on 20-07-09 14:27 |
|
| Author |
RE: mysql/php |
spyware
Member

Posts: 4190
Location: The Netherlands
Joined: 14.04.07 Rank: God Warn Level: 90
|
|
Demons Halo wrote:
I'm just wondering what the best method is 
Depends what you want to use it for/how you want to use it.

"The chowner of property." - Zeph Widespread intellectual and moral docility may be convenient for leaders in the short term,
but it is suicidal for nations in the long term. - Carl Sagan Since the grid is inescapable, what were the earlier lasers about? Does the corridor have a sense of humor? - Ebert |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
spyware wrote:
Demons Halo wrote:
I'm just wondering what the best method is :P
Depends what you want to use it for/how you want to use it.
currently i use the following in index.php:
<body>
<div id="Main" align="center">
<div id="top">
<?php include 'top.php'; ?>
</div>
<div id="Body" align="left">
<iframe align="left" id="Iframe" name="Iframe" src="home.php" width="100%" height="100%" style="background-color:transparent; border:none;" scrolling="yes">
</iframe>
</div>
</div>
</body>
I want to get rid of the Iframe by using another method like php include. The idea is when a user clicks on a button (inside top.php), the "body div" in the index.php should change and show the content of a new page depending on what button the user clicks.
|
|
| Author |
RE: mysql/php |
christian879
Member

Posts: 13
Location: Wales
Joined: 28.08.07 Rank: God |
|
|
<?php
$page = $_GET['page'];
?>
<body>
<div id="Main" align="center">
<div id="top">
<?php include 'top.php'; ?>
</div>
<div id="Body" align="left">
<?php include $page; ?>
</div>
</div>
</body>
The links within top.php should be like
<a href="index.php?page=lol.php">lol</a>
Obviously, you wil ned security measures :P

|
|
| Author |
RE: mysql/php |
christian879
Member

Posts: 13
Location: Wales
Joined: 28.08.07 Rank: God |
|
pm me if you need anymore help

|
|
| Author |
RE: mysql/php |
oasis
Member

Posts: 19
Location: Scotland
Joined: 23.06.07 Rank: Uber Elite |
|
quick question Demons Halo, is one.com a good host...i was going to go for it but i was unsure. it seems pretty good but i thought there would be a catch somewhere. cheers
|
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
christian879 wrote:
<?php
$page = $_GET['page'];
?>
<body>
<div id="Main" align="center">
<div id="top">
<?php include 'top.php'; ?>
</div>
<div id="Body" align="left">
<?php include $page; ?>
</div>
</div>
</body>
The links within top.php should be like
<a href="index.php?page=lol.php">lol</a>
Obviously, you wil ned security measures :P
ahaaaaaa so that's how the ?page... works, this is indeed handy. What security measures do you have in mind? I'm still a noob remember xD I can't work with complicated 14 page scblockedript stuff (yet).
quick question Demons Halo, is one.com a good host...i was going to go for it but i was unsure. it seems pretty good but i thought there would be a catch somewhere. cheers
Yes they are.
+
24/7 support
cheap registration
100% secure when it comes to credit card number etc.
Easy access MySQL DB + latest version of PHP
3000MB for 1.25 / month --> lol?
Lots of features for admins using IE
Google Adwords coupon
-
No CGI support.
Note:
pretty decent connection.
Total: 9/10 so go for it ;)
Edited by Demons Halo on 20-07-09 17:16 |
|
| Author |
RE: mysql/php |
ranma
Member

Posts: 269
Location: Behind a sphere
Joined: 27.08.05 Rank: HBH Guru |
|
And here I thought DH was some quite experienced guy 
I would suggest GoDaddy hosting. Their customer service is AMAZING and they have tons and tons of features.
Wisdom spared is wisdom squared. |
|
| Author |
RE: mysql/php |
COM
Banned

Posts: 800
Location:
Joined: 31.08.07 Rank: God |
|
|
ranma wrote:
And here I thought DH was some quite experienced guy
You best be jokin, nigga! 
Demons Halo wrote:
ahaaaaaa so that's how the ?page... works
Please man, for the love of chocolate, look into some basic http before you delve into PHP. You don't hate chocolate... do you? 
K'aem'nhi kh'rn, K'aem'nhi kh'r, K'aem'nhi kh'rmnu.
I'a Y'gs-Othoth! |
|
| Author |
RE: mysql/php |
ranma
Member

Posts: 269
Location: Behind a sphere
Joined: 27.08.05 Rank: HBH Guru |
|
But seriously, some of those question could have been easily answered by looking at w3schools's php/mysql tutorials.
Wisdom spared is wisdom squared. |
|
| Author |
RE: mysql/php |
Demons Halo
Member

Posts: 261
Location: Sweden
Joined: 26.03.09 Rank: Hacker Level 1 |
|
COM wrote:
ranma wrote:
And here I thought DH was some quite experienced guy
You best be jokin, nigga!
Demons Halo wrote:
ahaaaaaa so that's how the ?page... works
Please man, for the love of chocolate, look into some basic http before you delve into PHP. You don't hate chocolate... do you? 
HEY HEY HEY!!!!
hey I'm a noob I admit that much and thnx for believing in my hidden power ranma! (L)
haha I love chocolate, I even married it once!
Just to be 100% clear... I HATE BUILDING WEBB BASED PROGRAMMING. I joined this community so that I could learn a bit about computer languages (and thnx to ynouri7 I started with python).
yesterday I got bored so I thought that maybe it's time to start with something else like PHP/MySQL and so fast everything seems easy and fun =D
and yes ranma W3school is great, although I'm googling most of the questions I've got. Having stuff explained on the spot is so much better than reading through 16 pages just so that you notice the FREAKING ; you need to put at the end of each line -_-
Edited by Demons Halo on 20-07-09 18:51 |
|