|
|
|
|
![]() ![]() |
Feb 15 2008, 01:28 AM
Post
#1
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 259 Joined: 27-May 07 Member No.: 43,758 |
ok when i try and access the page i want, iget the following error:
Parse error: syntax error, unexpected '<' in /home/evolved/public_html/clans/create.php on line 29 however, my page looks like this: QUOTE <?php // Connects to your Database $username = "evolved_creation"; $password = "mypasswordishere"; $hostname = "localhost"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("evolved_clancreation",$dbh) or die("Could not connect to DB"); mysql_close($dbh); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: http://www.360evolved.trap17.com/login.php"); } else { <form action="insert.php" method="post"> Clan Name: <input type="text" name="name" /><br> Description: <input type="text" name="description" /> <input type="submit" /> } } } else //if the cookie does not exist, they are taken to the login screen { header("Location: http://www.360evolved.trap17.com/login.php"); } ?> does anybody know what could be wrong? Basically this page is trying to create a clan, but you must be logged in, so it checks to make sure you are logged in. For some reason, it works with echo and text between the things, but doesn't work when i put the form in there.....the form works without the other code too... |
|
|
|
Feb 15 2008, 01:42 AM
Post
#2
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 290 Joined: 5-October 07 From: Random Places Member No.: 51,171 ![]() |
You cannot use HTML in a regular PHP basis. You must break it off of PHP for the HTML or parse the HTML through echo.
Try this: CODE <?php // Connects to your Database $username = "evolved_creation"; $password = "mypasswordishere"; $hostname = "localhost"; $dbh = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("evolved_clancreation",$dbh) or die("Could not connect to DB"); mysql_close($dbh); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )) { //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']) { header("Location: http://www.360evolved.trap17.com/login.php"); } else { ?> <form action="insert.php" method="post"> Clan Name: <input type="text" name="name" /><br> Description: <input type="text" name="description" /> <input type="submit" /> <?php } } } else //if the cookie does not exist, they are taken to the login screen { header("Location: http://www.360evolved.trap17.com/login.php"); } ?> |
|
|
|
Feb 15 2008, 09:25 AM
Post
#3
|
|
|
apt-get moo ![]() Group: [MODERATOR] Posts: 2,153 Joined: 28-May 05 From: Devon, England Member No.: 7,593 ![]() |
As coolcat50 has said, you can't just stick HTML into PHP code. The PHP parser will still try to treat it as PHP, and it therefore makes no sense to it, so it spews out an error. Breaking out of PHP, typing the HTML, then going back into PHP is one method (shown above). However, there are a few others you can use, depending on which one you like best really
Separate Echos CODE else { echo '<form action="insert.php" method="post">'; echo 'Clan Name: <input type="text" name="name" /><br>'; echo 'Description: <input type="text" name="description" />'; echo '<input type="submit" />'; } } } One Large Echo CODE else { echo "<form action=\"insert.php\" method=\"post\">\nClan Name: <input type=\"text\" name=\"name\" /><br>\nDescription: <input type=\"text\" name=\"description\" />\n<input type=\"submit\" />"; } } } Using "Here Document" CODE else { echo <<<EOF <form action="insert.php" method="post"> Clan Name: <input type="text" name="name" /><br> Description: <input type="text" name="description" /> <input type="submit" /> EOF; } } } Take your pick. They will all work the same, so it depends on which one fits best with your coding style. |
|
|
|
Feb 15 2008, 09:33 PM
Post
#4
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 259 Joined: 27-May 07 Member No.: 43,758 |
o ok. i guess i was just expecting that since you can usually (at least from what ive usesd in the past) php in html, or something to that extent. Oh well
now last thing i need to know, how would i take note of who is creating the clan (leader name). Would it be in insert.php? (this is the function page for the forms), since it should insert the name into the database? if so how can i do this? if you need me to post the code i can. ok, i did all the things and things to try etc, but i get the following error (note im logged in, when im not logged in, it works fine, as in it takes you to the login page) QUOTE Warning: mysql_query() [function.mysql-query]: Access denied for user 'nobody'@'localhost' (using password: NO) in /home/evolved/public_html/clans/create.php on line 17 Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/evolved/public_html/clans/create.php on line 17 Access denied for user 'nobody'@'localhost' (using password: NO) anybodfy know how to fix it? |
|
|
|
Feb 15 2008, 11:28 PM
Post
#5
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: Members Posts: 290 Joined: 5-October 07 From: Random Places Member No.: 51,171 ![]() |
The MySQL warnings are because you have an incorrect user or pass. It says nobody@localhost which apparently does not exist. You must include the MySQL database info and be sure you are connecting to it. Your errors can help you debug your program if you read them carefully.
|
|
|
|
Feb 16 2008, 02:50 AM
Post
#6
|
|
|
Ephesians 6:10-17 ![]() Group: [MODERATOR] Posts: 1,917 Joined: 22-June 05 From: The World of Gentoo Member No.: 8,528 |
anybodfy know how to fix it? That error may be because the database information was not included in the PHP script that was trying to execute a MySQL query. |
|
|
|
Feb 16 2008, 03:16 AM
Post
#7
|
|
|
Super Member ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Group: [HOSTED] Posts: 259 Joined: 27-May 07 Member No.: 43,758 |
The MySQL warnings are because you have an incorrect user or pass. It says nobody@localhost which apparently does not exist. You must include the MySQL database info and be sure you are connecting to it. Your errors can help you debug your program if you read them carefully. I have no place where it says to connect with a nobody account :s which is weird, and what is confusing me. |
|
|
|
Feb 16 2008, 05:58 AM
Post
#8
|
|
|
A computer once beat me at chess, but it was no match for me at kick boxing. ![]() Group: [MODERATOR] Posts: 4,079 Joined: 24-July 05 From: Linix, DOS and Windows…the good, the bad and the ugly Member No.: 9,787 ![]() |
Go into your Cpanel and confirm that your Database user is "GRANTED" permissions on the Database in question.
Use mysqlAdmin to define and grant the permissions, I think, and phpmyadmin to confirm that the permissions are granted for the user on that Database. Also, the Trap17 prefixes the database and the user-names with the cpanel user names... just a reminder... |
|
|
|