Jump to content

absolute noob question


TEDSON

Recommended Posts

I'm really sorry if this has been answered (I assume it has) I'm unfamiliar with search terms of what I am trying to do.

 

I have this web page

 

<html>
<body>


<?php
$con = mysql_connect("localhost","user","pass");
if (!$con)
  {
  echo "Fail";
  die('Could not connect: ' . mysql_error());
  }

echo "Triumph";
?> 


</body>
</html>

 

Which I got from a snippet. I load the webpage expecting to see fail or triumph, but I see nothing.

 

My question is how to run the php script so I see something on the page (hopefully triumph.

 

I apoligise for my noobness, I'm a PHP know nothing at the moment.

Link to comment
Share on other sites

Sorry, seems I'm out of time to edit my post.

I've found that the page has to have a .php extension, rather than .htm

I changed it and I get what I expected..

"FailCould not connect: Access denied for user 'user'@'localhost' (using password: YES)"

My username and password are correct.

I notice in the snippet code, it dosent aske the database name, could this be the problem? if so how do I define it?

Link to comment
Share on other sites

so, you've set a variable $con to be mysql_connect, but you never actually tell it to connect.

 

What? What do you think mysql_connect() is for?

 

@TEDSON

As amplexus was showing, selecting the database is done after the connection. The problem must be with the host, username or password. Is MySQL definitely running?

Link to comment
Share on other sites

I'm unsure how to tell if its definately running

in cpanel

PHP: 5.2.14

MySQL: 5.0.91-community-log

 

I can create databases and add tables, so I am assuming that it is running.

 

I could be wrong though, its been known, I get the feeling I'm making some kind of schoolboy error.

 

EDIT:

 

I noticed there was no user associated with my db after manually creating it, so used the wizard, and the user was added, I temp gave user all access.

 

Although as you pointed out I'm not even connecting to Mysql never mind database.

Link to comment
Share on other sites

Thank you so much for your help and time, I really appreciate it.

 

I was using a database user and password, I tried my cpanel login credentiols and I get my Triumph message.

 

I'm a little woried about having those details on my website though, is this normal practice?

Link to comment
Share on other sites

Yeah there's no problem with having those details in your code; the PHP source isn't displayed to the user. Just be careful of who you give access to your file system. Also a good security measure though is to store them in a file outside of the publicly accessible directory, i.e. not within htdocs / public_html / www - which ever name for it your web server is using.

Link to comment
Share on other sites

Thanks, I'l have to look into that.

 

My end goal, is to have user and password authentication via my database in my application, which will be ran on a users local machine.

 

The app starts, the user enters user and pass, the app triggers the php script which in turn querys the data base, if its good, app continues, if not app exits.

 

So I dont want the mysql user and pass viewable from view sourcecode of page.

 

The help I recieved here has been fantastic, and I thank you kindly for it.

Link to comment
Share on other sites

So I dont want the mysql user and pass viewable from view sourcecode of page.

As I touched on before, the source of the PHP is never shown to the user. When the user requests a PHP page, it's parsed by the PHP engine and the resulting HTML passed back; not the PHP code itself.

 

 

The help I recieved here has been fantastic, and I thank you kindly for it.

No problem ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.