nol 0 Report post Posted February 15, 2008 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: <?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://forums.xisto.com/no_longer_exists/;);http://forums.xisto.com/ } 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://forums.xisto.com/no_longer_exists/;);http://forums.xisto.com/ } ?> 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... Share this post Link to post Share on other sites
coolcat50 0 Report post Posted February 15, 2008 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: {$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 pageif ($pass != $info['password']){ header("Location linenums:0'><?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 inif(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 pageif ($pass != $info['password']){ header("Location: [url="http://forums.xisto.com/no_longer_exists/;);"]http://forums.xisto.com/no_longer_exists/;);[/url]}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: [url="http://forums.xisto.com/no_longer_exists/;);"]http://forums.xisto.com/no_longer_exists/;);[/url]}?> Share this post Link to post Share on other sites
rvalkass 5 Report post Posted February 15, 2008 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 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 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" 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. Share this post Link to post Share on other sites
nol 0 Report post Posted February 15, 2008 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 thank you for that, woulda taken me awhile to figure out how to do it like that, I was kinda guessing it, but didn't exactly know how. Thank you guys I'm testing it now.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) 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 17Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in /home/evolved/public_html/clans/create.php on line 17Access denied for user 'nobody'@'localhost' (using password: NO) anybodfy know how to fix it? Share this post Link to post Share on other sites
coolcat50 0 Report post Posted February 15, 2008 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. Share this post Link to post Share on other sites
truefusion 3 Report post Posted February 16, 2008 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. Share this post Link to post Share on other sites
nol 0 Report post Posted February 16, 2008 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. Share this post Link to post Share on other sites
jlhaslip 4 Report post Posted February 16, 2008 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 Xisto prefixes the database and the user-names with the cpanel user names... just a reminder... Share this post Link to post Share on other sites
nol 0 Report post Posted February 16, 2008 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 Xisto prefixes the database and the user-names with the cpanel user names... just a reminder...theres nothing wrong with my initial permissions I set up. The account I set up for this database is, evolved_creation (i ended up just using this database for everything). However, when I login, and view this page, it says theres no password for the user nobody? which confuses me. Share this post Link to post Share on other sites
rvalkass 5 Report post Posted February 16, 2008 Try swapping this line... $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); ...for this$check = mysql_query("SELECT * FROM users WHERE username = '$username'", $dbh)or die(mysql_error()); It shouldn't be strictly necessary, but it might help. Also, try hard-coding the database connection values into the mysql_connect statement and see it that helps (i.e. get rid of the variables $username, $hostname and $password). It is possible that, as you have two completely unrelated $username variables, the second one is overwriting the first, and therefore trying to use a value from a cookie as your database username. Rename one of the $username uses, or eliminate one (the database connection one is easiest, which is why I suggested it). Share this post Link to post Share on other sites
nol 0 Report post Posted February 16, 2008 i talked to alex, he said i need to connect to the database in the else statement. I'll try both when the cpanel works again for me, I just need to know about the leader thing though. Like the user who registers the clan, gets their username put into the database, without filling out a line for it: how can I do that? Share this post Link to post Share on other sites
truefusion 3 Report post Posted February 16, 2008 The problem with MySQL in your script is that you close the MySQL connection before you even do anything to access or modify the database. On, i would assume, line 11, you close the MySQL connection, but on line 18 you try to access the MySQL database with the mysql_query() function—this won't work. Although in PHP you don't have to use mysql_close(), but if you're going to use it, make sure it's at the end—after all other MySQL queries. Like the user who registers the clan, gets their username put into the database, without filling out a line for it: how can I do that?I don't think that's possible, unless you want to do the work for them. Share this post Link to post Share on other sites