GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 25-Oct-2005, 12:02
djd@n djd@n is offline
Awaiting Email Confirmation
 
Join Date: Oct 2005
Posts: 21
djd@n is on a distinguished road

Trouble connecting to MySQL


i have tried to make a login code and members area that i found in a teach php book but everytime i upload it it comes up with unexpected T_STRING on either line 13 or 14 this is the code i am using
PHP Code:

<html>
<p>create a new user
<?php
  $dbhost = "hab-globe.com";
  $dbname = "userdetails";
  $dbuser = "user";
  $dbpass = "habbo250";
  $username = $_POST['newusername'];
  $userpass = $POST_['newpassword'];
  $useremail = $_POST['email'];
  $today = date("y-m-d");
  if ($username = "" $userpass = "" or $useremail = "")
   die ("<p>sorry you left a field empty please click the back butto to check your details")
   $query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
  $connection  mysql_connect(dbhost, $dbuser, $dbpass)
   or die ("<br>sorry couldnt connect to hab-globe.com");
  $db = mysql_select_db($dbname, $dbconnection)
    or die("<br>sorry the hab-globe database is offline, please check back later!");
  $result = mysql_query($query)
   or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html> 

  #2  
Old 25-Oct-2005, 19:49
Paramesh's Avatar
Paramesh Paramesh is offline
Regular Member
 
Join Date: Sep 2005
Location: The Milky Way
Posts: 929
Paramesh is a jewel in the roughParamesh is a jewel in the roughParamesh is a jewel in the rough

Re: Please Help!!!!!!!


Hi,

Use an appropriate title for your post.
Dont post new threads for the same question.

I dont know anything about PHP but here is my guess:
PHP Code:

$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')"; 



the error is that there is an extra single quote ' after the email.

In this line,
PHP Code:

die ("<p>sorry you left a field empty please click the back butto to check your details") 


You missed a semicolon in the end.

so,
Add a semicolon at the end of the statement.
and remove that single quote.
I hope this helps a little bit.
Here is the updated one:
PHP Code:

die ("<p>sorry you left a field empty please click the back butto to check your details");
 $query = "INSERT INTO user (username, password, joindate, email) VALUES ('$username', '$userpass', '$today', '$useremail')"; 



Regards,
Paramesh.
__________________

Don't walk in front of me, I may not follow.
Don't walk behind me, I may not lead.
Just walk beside me and be my friend.
  #3  
Old 26-Oct-2005, 09:39
djd@n djd@n is offline
Awaiting Email Confirmation
 
Join Date: Oct 2005
Posts: 21
djd@n is on a distinguished road

Re: Please Help!!!!!!!


I have done that but now when i go to register a new user it says sorry you left a field blank when i havent
  #4  
Old 27-Oct-2005, 07:13
Imatate Imatate is offline
New Member
 
Join Date: Oct 2005
Posts: 5
Imatate is on a distinguished road

Re: Please Help!!!!!!!


well, im no genius but i have edited a new one and i have forund this


<html>
<p>create a new user
<?php
$dbhost = "hab-globe.com";
$dbname = "userdetails";
$dbuser = "user";
$dbpass = "habbo250";
$username = $_POST['newusername'];
$userpass = $POST_['newpassword'];
$useremail = $_POST['email'];
$today = date("y-m-d");
if ($username = "" $userpass = " or $useremail = ")
die ("<p>sorry you left a field empty please click the back butto to check your details")
$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
$connection mysql_connect(dbhost, $dbuser, $dbpass)
or die ("<br>sorry couldnt connect to hab-globe.com");
$db = mysql_select_db($dbname, $dbconnection)
or die("<br>Sorry http://www.hab-globe.com Is Not Allowing Logins Today!!");
$result = mysql_query($query)
or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html>
  #5  
Old 27-Oct-2005, 07:14
Imatate Imatate is offline
New Member
 
Join Date: Oct 2005
Posts: 5
Imatate is on a distinguished road

Re: Please Help!!!!!!!


<html>
<p>create a new user
<?php
$dbhost = "hab-globe.com";
$dbname = "userdetails";
$dbuser = "user";
$dbpass = "habbo250";
$username = $_POST['newusername'];
$userpass = $POST_['newpassword'];
$useremail = $_POST['email'];
$today = date("y-m-d");
if ($username = "" $userpass = " or $useremail = ")
die ("<p>sorry you left a field empty please click the back butto to check your details")
$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
$connection mysql_connect(dbhost, $dbuser, $dbpass)
or die ("<br>sorry couldnt connect to hab-globe.com");
$db = mysql_select_db($dbname, $dbconnection)
or die("<br>Sorry http://www.hab-globe.com Is Not Allowing Logins Today!!");
$result = mysql_query($query)
or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html>






<html>
<p>create a new user
<?php
$dbhost = "hab-globe.com";
$dbname = "userdetails";
$dbuser = "user";
$dbpass = "habbo250";
$username = $_POST['newusername'];
$userpass = $POST_['newpassword'];
$useremail = $_POST['email'];
$today = date("y-m-d");
if ($username = "" $userpass = " or $useremail = ")
die ("<p>sorry you left a field empty please click the back butto to check your details")
$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
$connection mysql_connect(dbhost, $dbuser, $dbpass)
or die ("<br>sorry couldnt connect to hab-globe.com");
$db = mysql_select_db($dbname, $dbconnection)
or die("<br>Sorry http://www.hab-globe.com Is Not Allowing Logins Today!!");
$result = mysql_query($query)
or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html>







<html>
<p>create a new user
<?php
$dbhost = "hab-globe.com";
$dbname = "userdetails";
$dbuser = "user";
$dbpass = "habbo250";
$username = $_POST['newusername'];
$userpass = $POST_['newpassword'];
$useremail = $_POST['email'];
$today = date("y-m-d");
if ($username = "" $userpass = " or $useremail = ")
die ("<p>sorry you left a field empty please click the back butto to check your details")
$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
$connection mysql_connect(dbhost, $dbuser, $dbpass)
or die ("<br>sorry couldnt connect to hab-globe.com");
$db = mysql_select_db($dbname, $dbconnection)
or die("<br>Sorry http://www.hab-globe.com Is Not Allowing Logins Today!!");
$result = mysql_query($query)
or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html>







<html>
<p>create a new user
<?php
$dbhost = "hab-globe.com";
$dbname = "userdetails";
$dbuser = "user";
$dbpass = "habbo250";
$username = $_POST['newusername'];
$userpass = $POST_['newpassword'];
$useremail = $_POST['email'];
$today = date("y-m-d");
if ($username = "" $userpass = " or $useremail = ")
die ("<p>sorry you left a field empty please click the back butto to check your details")
$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
$connection mysql_connect(dbhost, $dbuser, $dbpass)
or die ("<br>sorry couldnt connect to hab-globe.com");
$db = mysql_select_db($dbname, $dbconnection)
or die("<br>Sorry http://www.hab-globe.com Is Not Allowing Logins Today!!");
$result = mysql_query($query)
or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html>
  #6  
Old 27-Oct-2005, 07:15
Imatate Imatate is offline
New Member
 
Join Date: Oct 2005
Posts: 5
Imatate is on a distinguished road

Re: Please Help!!!!!!!


Quote:
Originally Posted by Imatate
well, im no genius but i have edited a new one and i have forund this


<html>
<p>create a new user
<?php
$dbhost = "hab-globe.com";
$dbname = "userdetails";
$dbuser = "user";
$dbpass = "habbo250";
$username = $_POST['newusername'];
$userpass = $POST_['newpassword'];
$useremail = $_POST['email'];
$today = date("y-m-d");
if ($username = "" $userpass = " or $useremail = ")
die ("<p>sorry you left a field empty please click the back butto to check your details")
$query = "INSERT INTO user (username, password, joindate, email') VALUES ('$username', '$userpass', '$today', '$useremail')";
$connection mysql_connect(dbhost, $dbuser, $dbpass)
or die ("<br>sorry couldnt connect to hab-globe.com");
$db = mysql_select_db($dbname, $dbconnection)
or die("<br>Sorry http://www.hab-globe.com Is Not Allowing Logins Today!!");
$result = mysql_query($query)
or die ("sorry that user has been taken");

$_SESSION['login'] = 'yes';
?>
<p>thank you, your new user has been created. Please click <ahref="login.php"> here</a> to log into your hab-globe user account.<p>
</html>

Also The Datbase Connection String Should Be Formatted in a way which it is easy to view
  #7  
Old 27-Oct-2005, 11:10
phrygianphreak phrygianphreak is offline
New Member
 
Join Date: Oct 2005
Posts: 9
phrygianphreak is on a distinguished road

Re: Please Help!!!!!!!


You haven't gotten there yet, but on line 15:
$connection mysql_connect(dbhost, $dbuser, $dbpass)
the 'dbhost' needs a '$' in front of it to be a valid variable.

Here's the corrected code:
$connection mysql_connect($dbhost, $dbuser, $dbpass)

Hope that helps.
  #8  
Old 28-Oct-2005, 08:10
admin's Avatar
admin admin is offline
Administrator
 
Join Date: Sep 2002
Posts: 858
admin will become famous soon enough

Re: Please Help!!!!!!!


There are so many syntax errors, I don't know where to start

PHP Code:

// if ($username = "" $userpass = " or $useremail = ")
// can be replaced with... 
if( !$username or !$userpass or !$useremail ) 



When user-supplied data/input is inserted within your SQL statement, you really should screen the data first.
PHP Code:

// a really simple (but unrelated to your script) example...
if( !$username=trim($_POST['username']) ) // trim to remove whitespace...
{
  die( "Please fill-in your username." );
}
else
{ // the field was filled-in (with something)...
 
  // escape special characters in the SQL statement.
  $sql .= " WHERE `username`= '" . mysql_escape_string( $username ) . "'";
} 



From your example code:
PHP Code:

$connection  mysql_connect(dbhost, $dbuser, $dbpass)
   or die ("<br>sorry couldnt connect to hab-globe.com");
  $db = mysql_select_db($dbname, $dbconnection) 


Line 1 : where is the assignment (=) operator in this line? Somebody already mentioned the missing $ in dbhost.
Line 3 : Where did $dbconnection come from? I thought it was $connection?

PHP Code:

// possible fix...
$connection =  mysql_connect( $dbhost, $dbuser, $dbpass );
   or die ("<br>sorry couldnt connect to hab-globe.com");
if( !@mysql_select_db($dbname, $connection) )
 trigger_error( "Cannot select database: $dbname", E_USER_ERROR ); 



I appreciate that you're experimenting (and learning) but you'll understand new PHP stuff (like connecting to MySQL) a lot faster if you revisit a page like: basic PHP syntax (Expressions) and understand the basics about the language. Really, it's not complicated at all.

While I am replying to this post of yours, may I suggest that you do NOT use titles like "Please Help!!!!!!!" in forums. It's considered bad form.
__________________
Custom BB codes you can use here:
[HTML] | [C++] | [CSS] | [JAVA] | [PY] | [VB]
 
 

Recent GIDBlogVista ?Widgets? on Windows XP by LocalTech

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
php and mysql vladimy MySQL / PHP Forum 2 28-May-2005 05:17
Error connecting to MySQL Kilgayne MySQL / PHP Forum 4 27-May-2005 13:45
Trouble connecting to most of the internet jrobbio Web Hosting Forum 7 18-Jan-2004 10:11
Windows: From only £20p/y,Linux: from $10p/m. ASP, ASP.NET, PHP, Free MySQL, +More EyotaHosts Web Hosting Advertisements & Offers 0 28-Jun-2003 13:54

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:06.


vBulletin, Copyright © 2000 - 2010, Jelsoft Enterprises Ltd.