![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 | |
|
Programmer
Join Date: Jul 2005
Posts: 73
Rep Power: 4
![]() |
keep getting an error
when i go to a page called "sql_test.php". the file consists of this code:
[PHP]<?php if( !$userdata['session_logged_in'] ) { die("Please login to access this page."); } if ($user_data['user_level'] != ADMIN) { die("You must be an admin to access this page."); } else { // Connecting, selecting database $link = mysql_connect('host', 'username', 'password') die('Could not connect: ' . mysql_error()); echo 'Connected successfully'; mysql_select_db('my_database') or die('Could not select database'); // Performing SQL query $query = "CREATE TABLE sqltest ('' TYPE=default) ALTER TABLE sqltest ADD rowtest TINYINT(1) DEFAULT '1' NOT NULL SELCT * FROM sqltest"; $result = mysql_query($query) or die('Query failed: ' . mysql_error()); // Printing results in HTML echo "<table>\n"; while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) { echo "\t<tr>\n"; foreach ($line as $col_value) { echo "\t\t<td>$col_value\n"; } echo "\t</tr>\n"; } echo "</table>\n"; // Free resultset mysql_free_result($result); // Closing connection mysql_close($link); } ?>[/PHP] except, of course, the host, username, and password are the real ones. the error says Quote:
|
|
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
else {
// Connecting, selecting database
$link = mysql_connect('host', 'username', 'password')
die('Could not connect: ' . mysql_error());
echo 'Connected successfully';
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers Last edited by sykkn; Jul 27th, 2005 at 9:01 AM. |
|
|
|
|
|
#3 |
|
Programmer
Join Date: Jul 2005
Posts: 73
Rep Power: 4
![]() |
aww darnit im soo stupid. i just gave you all the info you need to connect to my sql database T_T
please edit that out of your post. thanks for the help. Last edited by theguy0000; Jul 26th, 2005 at 8:10 PM. |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
We don't edit it out of our post, you edit it out of YOUR post or get a moderator to do it. Yeah, lotsa people do that, you gotta catch it
.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Programmer
Join Date: Jul 2005
Posts: 73
Rep Power: 4
![]() |
lol yeah ill be more careful about that
![]() |
|
|
|
|
|
#6 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
check the following line ...
$link = mysql_connect('host', 'username', 'password')
die('Could not connect: ' . mysql_error());I think you probably meant ... $link = mysql_connect('host', 'username', 'password') or die('Could not connect: ' . mysql_error());or better yet .... $link = mysql_connect('host', 'username', 'password');
if(!$link) {
die('Could not connect: ' . mysql_error());
}He has edited his user information from his post. Would you do the same to yours?
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ]; /* Don't make me use it! */ |
|
|
|
|
|
#7 | |
|
Hobbyist Programmer
Join Date: Jun 2005
Location: MA, US
Posts: 204
Rep Power: 4
![]() |
Quote:
EDIT: sykkn pointed this out. I saw this when it was first posted and I was going to see if he used that same password for this site and, if so, I was going to log on as him and answer his question, but I got distracted. ![]()
__________________
"A stupid man's report of what a clever man says can never be accurate, because he unconciously translates what he hears into something he can understand." - B. Russell http://web.bryant.edu/~srk2 |
|
|
|
|
|
|
#8 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Oh, lol, the quote....I will get it
. Nope, edit time expired, mod will have to do it.....
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
Join Date: Apr 2004
Location: Texas
Posts: 106
Rep Power: 5
![]() |
DaWei, I got it. Thx.
__________________
[ [ SykkN alloc ] initWithThePowerTo: destroyYouAll ]; /* Don't make me use it! */ |
|
|
|
|
|
#10 | |||
|
Programmer
Join Date: Jul 2005
Posts: 73
Rep Power: 4
![]() |
Quote:
Quote:
this is the exact code from the php manual, except [php]if( !$userdata['session_logged_in'] ) { die("Please login to access this page."); } if ($user_data['user_level'] != ADMIN) { die("You must be an admin to access this page."); } else {[/php] and i dont think that would effect how the code works, would it? edit: now i get an error: Quote:
|
|||
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|