coolcam262 Posted August 21, 2010 Share Posted August 21, 2010 I am verry new to MySql but I am following a set of tutorials to make a blog, when I use the code to connect to the mysql database: <?php session_start(); //opens connection to mysql server $dbc = mysql_connect('***.com','*******','****'); if (!$dbc) { die('Not Connected' : . mysql_error()); } //select database $db_selected = mysql_select_db("blog", $dbc); if (!$db_selected) { die ("Can't connect : " . mysql_error); } $session_name = $_SESSION['uid']; ?> I get returned this in firefox: Parse error: syntax error, unexpected ':' in C:\XAMPP\xampplite\htdocs\Blog\4D\index.php on line 8 I am using XXAMP and the mysql database from 000webhost.com Please help! Thanks coolcam262 Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/ Share on other sites More sharing options...
Pikachu2000 Posted August 21, 2010 Share Posted August 21, 2010 Move the colon inside the quotes. die('Not Connected : ' . mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102163 Share on other sites More sharing options...
coolcam262 Posted August 21, 2010 Author Share Posted August 21, 2010 I thought I had tried everything!! I got so fustrated that I took the error code out!! Better put it back in now... Sorry for asking such an obvious question but I would never have got it without help! Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102167 Share on other sites More sharing options...
coolcam262 Posted August 21, 2010 Author Share Posted August 21, 2010 OK then this might not have such a simple solution but I am supposed to get told if the username and password are incorrect but if i click submit it doesn't do anything! Does anyone know how to fix this? Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102178 Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2010 Share Posted August 21, 2010 if i click submit it doesn't do anything! Does anyone know how to fix this? No one can directly answer that question without seeing the form and/or the php code responsible for the symptom. 1,013 different people could have written some code that produces that same symptom and there could be something different wrong in each of their programs and your code could be the 1,014th different thing. If you want help with the problem in your code, you must post the code responsible for the symptom. Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102179 Share on other sites More sharing options...
coolcam262 Posted August 21, 2010 Author Share Posted August 21, 2010 Oh yes.. sorry about that I copied the code and got distracted, when I came back to my computer i forgot i hadn't sent the link so i posted it Here it is: <?php include "global.php"; if($session_name){ echo "You are already logged in!\n"; } else { if(!$_post['submit']){ echo "<table border=0 cellspacing=3 cellpadding=3>\n"; echo "<form name=\"login\" method=\"post\" action=\"login.php\">\n"; echo "<tr><td>Username</td><td><input type\"text\" name=\"username\"></td></tr>\n"; echo "<tr><td>Password</td><td><input type=\"password\" name\"password\"></td></tr>\n"; echo "<tr><td colspan=2 align=right><input type=\"submit\" name=\"submit\" value=\"login\"></td></tr>\n"; echo "</form></table>\n"; }else { $user = $_POST['username']; $pass = $_POST['password']; if($user && $pass){ $sql = "SELECT * FROM 'users' WHERE 'username'='$user'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 1){ $epass = md5($pass); $sql2 = "SELECT * FROM 'users' WHERE 'username'='$user' AND 'password'='$epass'"; $res2 = mysql_query($sql2) or die(mysql_error()); if(mysql_num_rows($res2) == 1){ //success $row = mysql_fetch_assoc($res2); $_SESSION['uid'] = $row['id']; echo "You Have Successfully logged in as <b>$user</b> please click any link to continue!\n"; }else { echo "Incorrect Username or Password!\n"; } }else { echo "The Username doesn't exist!\n"; } }else { echo "You need to fill in all the valid fields!\n"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102181 Share on other sites More sharing options...
PFMaBiSmAd Posted August 21, 2010 Share Posted August 21, 2010 Your form has at least two missing = signs in it. The first is in the type= statement for the Username and the second is in the name= statement for the Password. Your code, which I assume you 'interpreted' from what you saw in some book or tutorial contains a number of incorrect elements. I see at least two more problems with single-quotes around the table name and column names in your query (single-quotes go around strings, not table/column names.) Computers only do exactly what their code tells them and each character making up the code has significance. You cannot move, leave out, or change things and expect code to work. Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102185 Share on other sites More sharing options...
fenway Posted August 22, 2010 Share Posted August 22, 2010 You've also just given everyone your DB credentials -- so change them. Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102217 Share on other sites More sharing options...
coolcam262 Posted August 22, 2010 Author Share Posted August 22, 2010 Do you think someone could help me out... i am sure you were all at this stage once unless you where born with php knoledge! Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102321 Share on other sites More sharing options...
Pikachu2000 Posted August 22, 2010 Share Posted August 22, 2010 Did you make the changes PFMaBiSmAd suggested? What's happening now when you run the script? Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102339 Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2010 Share Posted August 22, 2010 You have also got another basic error - $_post should be $_POST As has already been stated, everything (except for comments) is significant in a programming language. It does matter if something is supposed to be capitalized. If you are getting stuck at these basic errors - a semi-colon not inside of a quoted string, when 7 lines later in the code there is a similar string done correctly; missing = signs in a HTML form, the second one of which prevents that value from being submitted; queries that have single-quotes around table/column identifiers; a built-in php variable name not capitalized correctly, then you must go out and get a basic php/mysql/html book and learn the basics first before you can attempt to do anything useful using php/mysql/html. The purpose of a tutorial about building a blog is that it shows how to go about building a blog application. It assumes that you have the basic programming skills and knowledge needed to do so and you are only looking for ideas specific to building the application. Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102357 Share on other sites More sharing options...
PFMaBiSmAd Posted August 22, 2010 Share Posted August 22, 2010 Actually, I'm kind of hoping that code is not from a tutorial printed or posted somewhere. The code that displays the form is before the form validation logic, so it is not directly possible to re-display the form when there is an error, the code is performing two queries when only one is needed, and the first query tests just the username and reports if it was not found (which allows a hacker to keep trying usernames until he finds a valid one.) But the good news is, if you correct the errors that have been pointed out so far in the replies, the code functions as expected. Quote Link to comment https://forums.phpfreaks.com/topic/211381-i-am-trying-to-make-a-blog-but-i-get-a-syntax-error/#findComment-1102358 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.