Jump to content

Recommended Posts

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

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.

 

 

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";
					}
				}
			}

?>

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.

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.