lonebyrd
Apr 26 2006, 04:26 AM
| | I have a question about making a database. I recently downloaded a registration/login script and tried to use it, but then decided to go through a tutorial and make my own. Now, I made a config.php file which contains this:
CODE <? php $username = "username"; $password = "password"; $database = "database"; $server = "localhost";
mysql_connect {$server, $username, $password} or die [mysql_error]}}; mysql_connect_db{$database} or die [mysql error]}}; ?>
I made the database as written out in the tutorial, then typed in my website and it read:
'Parse error: parse error, unexpected T_VARIABLE in /home/lonebyrd/public_html/config.php on line 2'
My question is, is there somewhere that I have to enter my username, password, and email in the database so the registration page will come up? |
Reply
miCRoSCoPiC^eaRthLinG
Apr 26 2006, 05:22 AM
See that T_VARIABLE error is usually produced due to mismatched quotation marks.. single or double quotes - which i don't find in here. But there's one thing you've to take note. The CONFIG file is to solely act as a configuration variable container. There shouldn't be any other code like the MySQL connection code you've included. This is a standard design model. For example - your config.php should only look like: CODE <?php $username = "username"; $password = "password"; $database = "database"; $server = "localhost"; ?>
And then in another file - which does the actual MySQL connection and data transactions, you have to INCLUDE the config file, so these variables become available... Say your file is login.phpCODE <?php
mysql_connect ( $server, $username, $password ) or die ( mysql_error() ); mysql_connect_db ( $database ) or die ( mysql error() );
?>
BTW - you've got some weird stuff going on.. For example.. when you start your code block with the <?php statement, you've put a SPACE between the ? and php word. That might be the cause of your error. Also in your mysql_connect and mysql_connect_db statements you've got a whole bunch of weird paranthesis going on - WHAT ARE THEY FOR ?? You're supposed to use ONLY the rounded paranthesis.. i.e. ( and ) ... !! How come the {} and [] ??
Reply
Hercco
May 1 2006, 12:15 PM
Your code syntax seems to be completely wrong. In PHP arguments to functions are give in normal parenthesis (). For example: mysql_connect(params). And like M_E said, [mysql_error] is not a PHP statement. [ ] are used to indicate elements of an array (e.g. myArray[1] would point to second element of an array called myArray). And M_E is right about <? php causing errors. If short tags is enabled, <? is considered beginning of PHP code block, thus the 'php' would be parsed as a program code token, or actually it would just cause parse error as its not a valid token. If shottags is not enabled, then the block will not be considered as PHP at all and won't go through the parser at all.
Reply
Houdini
May 1 2006, 01:09 PM
There is no PHP native function QUOTE mysql_connect_db() there is one that you would use instead which is CODE mysql_select_db($database) Also let it be noted QUOTE And like M_E said, [mysql_error]s not a PHP statement. I did not take that from his post and there most certainly is a mysql_error() function read from the manual about that function PHP: mysql_error-Manual I use it all the time when first testing scripts I use it a little differently than they did but this is some of my code CODE $connect = mysql_connect($host,$user,$pass) //Now connect to the server or die("Could not connect to server".mysql_error()); $db = mysql_select_db($Db,$connect) or die("Could not select database $Db".mysql_error()); He just need to get his syntax correct, but hey we all learn from our mistakes. Also there shoul be no space between <? and php and it is a good practice to always use <?php instead of short tags like <? because not all servers have them turned on and when XML became in use it confuses the XML as well as PHP future version of PHP will come with short tags turned off as a default. In the forums at PHP Builder where I answer question about failing scripts occasionally one of the most common errors is using short tags with a test server then the code does not work on the live web server, or they put the code on a different server and it doesn't work anymore. Another common problem is usage of checkboxes which to process with PHP should be written as an array by simply adding [] to the checkbox name. Given more time lonebyrdwill learn from these errors and know in the future how to properly query the database. lonebyrd I would make a practice of using <?php to ensure that you code will work. A great online resource for learning PHP is a book called Practical PHP Programming
Reply
AVEX
May 7 2006, 06:26 AM
CODE <?php
mysql_connect("localhost", "username", "pass"); mysql_select_db("database") or die(mysql_error());
$sql = "SELECT * FROM password WHERE ww = '" . $_POST['password']. "' AND nickname = '" . $_POST['nickname']. "' LIMIT 1"; $query = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($query) == 1){ $name = ucfirst($_POST[nickname]); $_SESSION['WNP'] = "$naam"; echo "You are logged in"; echo $_SESSION['WNP']; echo "!<br>click <a href=\"index.php\">here</a> for admin."; }elseif (mysql_num_rows($query) == 0){ $text = "Not logged in!<br><a href=\"inloggen.php\">try</a> again!"; echo "$text"; }} ?>
Call the database for password this can also an txt or php extension Calls every page with this code CODE <?php include('variabel.php'); if($_SESSION['WNP'] == "") { echo "Je bent niet ingelogd!<br>Klik <a href=\"inloggen.php\">hier</a> om in te loggen!";} elseif($_SESSION['WNP'] != "") { Here the whole code }
this is it. Its simple but handy for unauthorized people
Reply
lonebyrd
May 7 2006, 04:45 PM
Houdini, in your response to my code, when you use $Db or any $database, am I supposed to type the name of my database or just leave it as it is. I'm just a little confused. I know I'm still learning and I'm sure I'll pick up more as I go along. I've already learned alot (albeit probably not as fast as most people around here).
Reply
Houdini
May 7 2006, 05:22 PM
Alright lets take the code you have posted so far and make it understandable. CODE <? php // This must not have a space as it does currently $username = "username"; // You are assigning a literal name as a variable here $password = "password"; // You are assinging a literal password name to a variable here $database = "database";// You are assigning the name of a literal database name to a variable here $server = "localhost"; // You are assinging the literal name of the host to a variable her
mysql_connect {$server, $username, $password} or die [mysql_error]}};//This is valid to connect to the server but the error handling is wrong mysql_connect_db{$database} or die [mysql error]}};// This is not it should be mysql_select_db($database) and same as above ?> Now lets fix the error CODE <?php $username = "username"; $password = "password"; $database = "database"; $server = "localhost"; mysql_connect {$server, $username, $password} or die ("Could not connect to server".mysql_error()); mysql_select_db{$database} or die ("Database select failed".mysql error()); ?> Then lets actually do something with the selected database CODE $query = "SELECT * FROM tablename";// The tablname is the table you want to query in the selected database. $result = mysql_query($query);//Execute the query Usually the second part of the code merely assigns values to variables and then uses them to FIRST connect to the Database then to SECOND select a database to work with and then you send a query to the database concerning a specific table but what has been shown will do that and produce an error if encountered whilst conducting either the connection to the database server (mysql in this case) or selecting a database on that server.
Reply
lonebyrd
May 7 2006, 09:46 PM
So, if I have this clear, my script would look like this: CODE <?php $nickname = "myCpanelname"; $password = "myCpanelpassword"; $database = "lonebyrd_FTV"; $server = "localhost"; mysql_connect {$server, $nickname, $password} or die ("Could not connect to server".mysql_error()); mysql_select_db{$database} or die ("Database select failed".mysql error());
$query = "SELECT name; email; nickname; password; location; gender; date_of_birth; is_activated; activation_code; FROM registration"; $result = mysql_query($query); ?> If I'm way off again, I might as well just give up. I'm reading the online book Practical PHP Programming, but that is taking some time (which is hard to get all in one shot)
Reply
Houdini
May 7 2006, 10:14 PM
Yes that looks correct the SELECT * FROM tablename would just take all fields from the tablename whatever it is. After getting the result set or $result then you would display it or do something else with it. If you will read just the database section of book which is a great resource and always there.
Reply
Similar Topics
Keywords : php mysql connection code login- Important: Basics Of Using PHP And MySQL
- (10)
I generally notice confusion with new users to PHP and or MySQL and first of all I believe that
unlike HTML which is automatically associated with a IE browser in a Microsoft system. HTML is
automatically rendered with whatever browser is the default browser, be it Internet Expolrer Firefox
Netscape or any other browser that has been set. PHP is a different matter to view the output of a
PHP file it must be run on a webserver, and if you do not have one set up on your local PC it simply
will not work. (Note serverside langauge requies a server) HTML is client side and ...
[PHP + MySQL] Encrypting Data
- To protect the password of your DB, for example. (11)
Hi! This is my 2nd code of PHP + MySQL. This code is VERY simple: it encript the data in the MySQL
DB. Here we go! ------------------------------------------------------------------------ CODE
$password = "abc"; $new_password = md5($password); echo $new_password; ?> The password "abc"
was codfied using md5() This will be: 900150983cd24fb0d6963f7d28e17f72 CODE $normal_pass =
"abc"; $encripted_pass = "900150983cd24fb0d6963f7d28e17f72"; if(md5($normal_pass) ==
$encripted_pass) echo "Login Sucessful!"; else echo "Incorrect password."; ?> This c...
Activation Code
- (7)
PHP & MySQL: Displaying Content From A Given ID
- (6)
Okay so I got this sample link (not working): http://www.acosta.com/joo.asp?id=654 Now suppose
I have a PHP file that would use MySql in order to get all values in the row where id 654 is found.
Here's a sample DB: Table: demnyc ______________________________________ | id |
Name | Age | Email | *----------------------------------------------------* | 1
| Albert | 17 | no email |
*----------------------------------------------------* | 2 | YaPow | 888 |
no email | |__________...
Php Random Selector
- whats the code (2)
Is there a PHP script that randomly selects a string from a list? example, the list is: 1-Pie
2-Balls 3-eggs The script would view a random
word from those 3 every time i run it. Also is there a function that gives a random number between
0 and a number i select?...
Need Help With A PHP - MySQL Registration Script
- Wont INSERT into the database (13)
hey well can some one helpme make this code work it won't INSERT INTO THE DATABSE CODE #
register1.php # common include file to MySQL include("DB.PHP"); $Username=$_POST ; $Password=$_POST
; $Name=$_POST ; $Last=$_POST ; $Sex=$_POST ; $Month=$_POST ; $Day=$_POST ; $Year=$_POST ;
$Adresse=$_POST ; $City=$_POST ; $State=$_POST ; $Zipcode=$_POST ; $Country=$_POST ; $Phone=$_POST ;
$Email=$_POST ; $Father_Name=$_POST ; $Mother_Name=$_POST ; $Parent_Phone=$_POST ;
$Parent_Email=$_POST ; $Level=$_POST ; $Academic=$_POST ; $Image_Link=$_POST ; $sql9="INSERT INTO
U...
Dynamic Php Image And Better Php Code Question
- (10)
Im working on a dynamic image, can i put 2 images in same dynamic image, and can i make this code
shorter? if ( $goal == 31 ) { $xp2 = ('14833'); } elseif ( $goal == 32 ) { $xp2 =
('16456'); } elseif ( $goal == 33 ) { $xp2 = ('18247'); } elseif ( $goal == 34 ) {
$xp2 = ('20224'); } elseif ( $goal == 35 ) { $xp2 = ('22406'); } elseif ( $goal ==
36 ) { $xp2 = ('24815'); } elseif ( $goal == 37 ) { $xp2 = ('27473'); } elseif (
$goal == 38 ) { $xp2 = ('30408'); } elseif ( $goal == 39 ) { $xp2 = ('33648')...
Php Login Script
- (0)
login script click the link to get your free php login script installer just follow the
instuctions the exe gives you and it will give you the script just place the code in the sever and
open index.html and follow on from there. what it has: it has reg page, login protection code ect.
it is simple to use and i think quite fun but im BORN TO BE WEIRD,you will need at least one working
mysql data base /biggrin.gif" style="vertical-align:middle" emoid=":D" border="0" alt="biggrin.gif"
/> hope you enjoy it. iknow i did from the alexmedia crew...
Letting Users Add Mysql Data With Php
- (1)
I'm curious as to the best methods of letting users submit data to a MySQL database, displaying
that data, and removing any unwanted tags etc. from it. Currently, there's a handful of PHP
functions that I know of to help with this: mysql_real_escape_string() - perhaps the best known
and most commonly used function, it should be used in pretty much any MySQL query. It escapes
characters that have SQL significance. QUOTE(php.net) ...which prepends backslashes to the
following characters: \x00, \n, \r, \, ', " and \x1a I like to think I made a pretty...
Mysql Question(inserting Number From A Textfield)
- (3)
Hey! I am trying to do a "Admin give EXP script". But I can't make it work. The value is not
updating, but the update query is correct.( I think:P) I think the fault is here: CODE
$expcomp=$givexpp += $givexp; The $givexp is the variable for the amount of Xp the admin wants
to give. the $givexpp is the variable for the user info (in this case, the experince he already
have). The datatype for the XP in the database is INT. So I have no idea if it can take data from a
normal textfield. If you need to see all the code, here you go: CODE session_start();...
Making A Link = Mysql_query
- (8)
Hey! I will try to make this as clear as possible. how can I make the following. I have a list,
of all members on my site. If I press on a members name(link), I will come to his profile. To come
to his profile, I need to get out some vaule from the database, but to get out some value from the
database, I must tell the code, how it should know who the user is (hard to understand?). To do
that, I must add a mysql_query in the code ( I think), like "SELECT user FROM dbname WHERE
user=link".. This is just how I think it works. I know it is kinda wrong.. but I don't k...
Writing And Testing My Own Login Script [solved]
- (20)
i have this error QUOTE Warning: session_start() : Cannot send session cache limiter - headers
already sent (output started at /home/eggie/public_html/race.php:2) in
/home/eggie/public_html/race.php on line 5 in every page i have with session start...what's
the problem?? CODE Race include("style.css"); include("config.php"); session_start();
if(!session_is_registered(myusername)){ echo 'Your Session has Expired!'; exit;} //If you
click race... if ($_GET =='race') { $asa=$_POST ; if(!isset($asa)) { echo 'You
didn\'t select an...
Making Something In Mysql Happen Only Once
- (10)
Hey! I know I am asking alot. But much is happening theese days. Sorry if I disturb with my
questions. The thing I am trying to do is: Ex. If the user becomes level 2, he should get 5 skill
points. I can't do this: CODE if($userlevel=5){ mysql_query("UPDATE user SET skillpoints
=$points+5");} because then it would update everytime the code was loaded. I hope you understand
what I am trying to do. If not, tell me /smile.gif" style="vertical-align:middle" emoid=":)"
border="0" alt="smile.gif" /> and i'll try to explain better. Thanks //Feelay...
Login Script
- (8)
I have another question--- i downloaded script of a game and it worked until my server changed to
newer version of php after which it didn't work... the most probable reason is that globals are
not enabled... now i need someone who can tell me what to put instead of what to make it work...
this is my login.php script CODE if (!$user || !$pass) { include("head.php"); print
"Please fill out all fields."; include("foot.php"); exit; } include("head.php"); $password =
md5($pass); $password2 = md5($password); $password3 = md5($password2); $password4 =...
Warning: Mysql_result(): Supplied Argument Is Not A Valid Mysql Result Resource In ...
- This Is for My attack Script. (4)
Hey. I am making a "Version 2.0" For my attack script, but I can't make it work. This is the
error I am gettin: Warning: mysql_result(): supplied argument is not a valid MySQL result resource
in And here is the code: CODE $dbQueryHealth = mysql_query("SELECT temphealth FROM
characters WHERE user =". $_POST .""); $currentHealth = mysql_result($dbQueryHealth, 0);
$dbQueryExp = mysql_query("SELECT exp FROM characters WHERE user = ".$_POST ."");
$currentExp = mysql_result($dbQueryExp, 0); I have checked the PHP Manual,...
Warning: Mysql_num_rows()
- What is the error :S (1)
Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I changed
something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied argument
is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31 Here is
the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM user WHERE username
= '". $username ."'"; if( mysql_num_rows( mysql_query(
$sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO ...
What's Wrong With My Php Webpage?
- there may be something wrong in my php code. (2)
This is the first time I use the functions fopen() and preg_replace() . It seems that there's
somthing wrong. Where did I write by mistake? CODE include('data/workinfo/0.php');
$viewwork = substr($work ,0,249); /* HERE CAN'T WORK WELL! */ $newthread =
fopen("http://c8s2007.freetzi.com/bbs/new.php?action=article&digest=0&postdate=0&author=1&fname=0&hi
ts=0&replies=1&pre=6&num=10&length=35&order=1", "rb"); if(!$newthread){ $newthread =
"无法调用信息!"; }else{ $ad = "
"; ...
Anyone Know Of A Really Good Mysql Class?
- Looking for something easy but full featured. (4)
Generally speaking, when I write a script, it either utilizes the MySQL class of the parent system
(like Mambo or Joomla) or I use basic functions and snippets to perform the database queries I need.
I really like the Joomla database class as it allows you to simply pass a regular query string to
it and the data is returned without the need for extra work! The Invision Power Board (IPB)
database class which is what is used for this forum is kind of a pain to use since it wants the
query string in a non-MySQL standard format. Nonetheless, it does work and I could use i...
Extracting Mysql Maths Using Php
- (2)
Right, this is a really simple thing and it has me completely stumped. I'm working on this mini
maths function and for some reason i cannot seem to do some simple math process using mysql. This is
the code: (php btw), now assume that $date is actually a defined mysql date variable already
successfully extracted. $sql = mysql_query("SELECT TO_DAYS('CURDATE()') -
TO_DAYS('$date')"); while ($row = mysql_fetch_array($sql)){ $diff = $row ; } Can
anyone spot what im doing wrong becuase im just thrown by it....
Too Many Connections?
- mysql_connect() (4)
I uploaded my PHP game yesterday, and most of my friends tried it out. After a while, I tried to
play as well but it said that mysql_connect() had too many connections already. Can anyone tell me
how to increase the amount of connections or maybe the total amount of connections allowed?...
Sql Injection Prevention (passing Numerical Data Across Pages).
- PHP/mySQL (9)
Even if your building something as simple as a basic news page for your website, if your passing
along url variable strings like (mysite/index.php?page=1), you may be vulnerable to SQL injection
attacks. For cases like these (passing numerical data in url strings), I have a handy dandy little
function to thwart these attempts silly: CODE // For checking if value is a number, if not
return 1. function isNum($val) { if (!is_numeric($val)) { $val = 1; } return ($val); } I
have this function, within my functions.php file, which I use as an include in files w...
Php/mysql And Manual Page Caching?
- (4)
I am hopefully about to attempt this on the news page of my new site. Every bit counts as far as
I'm concerned and not having "news" portion of my news page re-php and re-mysql everything where
there is no chance seems like a waste. I'm looking for good articles, information or tips on
the process (if I fail to find any good information as I'm looking through now). The way I see
it right now, I have most of my page split up in header, content (some static html in here before
dynamic contend and then a little more static html to close it off) and then a foo...
Login Script
- PHP Help #3 - Need help creating one (5)
It turns out that the authentication script that I copied from
http://www.php-mysql-tutorial.com/user-aut...on/database.php doesn't work even when it is left
unchanged. What a crappy piece of code. Now I am trying to build by own login script from scratch.
I already have a little knowledge on how to do this (connecting, echoing, retrieving) but I need
some more examples and/or tips. I know what I need and maybe this could help you out: Note: Green
items are fixed. No duplicate username in MySQL Database Authorized users only. I have to
authorize each...
Php Mysql Errors
- Fetching arrays (2)
I am deciding to make a Multiplayer Online RPG type game. I will be building it off of PHP and MySQL
to ensure makimum compatibility with Astahost's services (and it makes it easier /wink.gif"
style="vertical-align:middle" emoid=";)" border="0" alt="wink.gif" />). I have a database setup with
1 table to hold user data and I have the login system setup properly as well as the registration
form (obviously). All games of course have something similar to gold, units and points. Because
this is a turn-based game, I have turns. Now for the problem: I am trying to echo ...
How Can I Write PHP Code By This Formmail Html
- (5)
purpose is i want the information in the web page sent into my email. i just know that i need to use
php script to operate this action ,but i have no idea about this php code. so anyone can help me
please... thank you very much. ชื่อ
....................... ....... นามสกุล
....... ชื่อเล่น
วันเกิด 1 2 3 4 5 6 7 8 9 10 11
12 13 14 15 16 ...
How To Show Serial Nums In PHP Table For Contents Of MySQL DB
- Serial Numbering for output contents of mysql in php table (4)
Hello there, I'm looking for some education. How would you show the serial numbering for
outputted contents of mysql database. I used a table created in PHP to output content (i.e. an
alumni database) and I created a column for S/N, so that at a glance anyone can tell how many
members have registered. Thanks house. Neyoo...
Re-order MySQL Table
- (11)
Hello you all, I've got a question /smile.gif" style="vertical-align:middle" emoid=":)"
border="0" alt="smile.gif" /> Let's say I have a database width the table "news". It contains
about 10 items which is ordered by the field "id". Now from my admin page i do this: CODE
mysql_query("DELETE FROM news WHERE id=4"); ?> And a few days later i do: CODE
mysql_query("DELETE FROM news WHERE id=7"); ?> Now there are two gaps in the table => 1, 2, 3,
5, 6, 8, 9, 10 (no 4 and 7). It want to reallocate the whole table to fill the gaps like this => 1,
2,...
Need MySQL Alternative To The Syntax "or die()"
- (8)
Hello again /smile.gif" style="vertical-align:middle" emoid=":)" border="0" alt="smile.gif" />
I'm facing a problem with PHP and MySQL... I want, when a MySQL error occurs, to let the script
continue. Here's the script: CODE $query = "SELECT * FROM menus ORDER BY id ASC";
$menus_result = mysql_query($query) or die("Error!"); while( $menu=mysql_fetch_array($menus_result)
) { echo $menu ." "; } Now if the table "menus" doesn't exist, this would echo "Error!"
where it's placed and terminate the whole script. But I want it to echo "Error!" and...
Code Snippets Repository
- (0)
Well as everybody know in these forums people posts a lot of code snippets that could be organized
in a simple page or whatever, my question is if someone is interested to do it or if exists
something like that here at astahost. I think it would be very helpful for everybody as well to
keep things more organized. Best regards,...
Login
- (5)
Hey I need a Log in System for my site, What I want to do is where they have there own profiles for
members only to view. Then Have it where they see pages which Non members don't see.. Also I
want it where I can Only add Usernames or Passwords. Basicly its going to be like this Guest Page:
No Log is needed Any one can See Members Page: Log in Needed to see, May only log in from Admin
adding there name, Can Delete there name if they quit member ship, or change there password to
banned them. Also The Members pages cannot be viewed Even if U type in the link to the ...
Looking for PHP:, Need, Help, With, MySQL, Connection, Code, (Login, Form)
|
*SIMILAR VIDEOS*
Searching Video's for PHP:, Need, Help, With, MySQL, Connection, Code, (Login, Form)
|
advertisement
|
|