Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Starting out php/mysql

Explorer ,
Jul 03, 2008 Jul 03, 2008
Hello, i am new to php so be prepared for a idiots question,Hello, Do i need to run this on my localhost or can i run it on my virtual server as this allready has php mysql etc installed.




i am new to php so be prepared for a idiots question, i have been trying to copy a youtube tutorial to create a navbar using php mysql and dreamweaver " http://www.youtube.com/watch?v=habZHcnShfs" to do this i need to create a mysql tabel in dreamweaver, to do this i have been useing the following code;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$user="james1892";
$password="14011991";
$database="naviagation";
mysql_connect("localhost",$user,$password);
@MySQL_select_db($database) or die("unable to select database");
$query = 'CREATE TABLE 'menu' (
'mid' TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
'name' varchar(20) NOT NULL
'link' varchar(100) NOT NULL,
PRIMARY KEY ( 'mid' )
)';
mysql_query($query);
mysql_close();
?>
</body>
</html>

this then returns the following message "Parse error: syntax error, unexpected T_STRING in /var/www/vhosts/sickstudentgames.com/httpdocs/php attempt 1/first database midnamelink.php on line 15"

i then gave up on thsi as i couldnt work out what was the problem and started a new code to create a database using this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$con = mysql_connect("localhost","com1892","14011991");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);
?>

</body>
</html>
this then showed the folling message "Warning: mysql_connect(): Access denied for user 'com1892'@'localhost' (using password: YES) in /var/www/vhosts/sickstudentgames.com/httpdocs/php attempt 1/tableattempt2.php on line 10
Could not connect: Access denied for user 'com1892'@'localhost' (using password: YES)"

i have been uploading these to my website server as this has php and mysql installed could this be the problem do i need to run it on the coputers localhost>?

any help greatly appriciated
thanks you




i have been trying to copy a youtube tutorial to create a navbar using php mysql and dreamweaver " http://www.youtube.com/watch?v=habZHcnShfs" to do this i need to create a mysql tabel in dreamweaver, to do this i have been useing the following code;

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$user="james1892";
$password="14011991";
$database="naviagation";
mysql_connect("localhost",$user,$password);
@MySQL_select_db($database) or die("unable to select database");
$query = 'CREATE TABLE 'menu' (
'mid' TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
'name' varchar(20) NOT NULL
'link' varchar(100) NOT NULL,
PRIMARY KEY ( 'mid' )
)';
mysql_query($query);
mysql_close();
?>
</body>
</html>

this then returns the following message "Parse error: syntax error, unexpected T_STRING in /var/www/vhosts/sickstudentgames.com/httpdocs/php attempt 1/first database midnamelink.php on line 15"

i then gave up on thsi as i couldnt work out what was the problem and started a new code to create a database using this code

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" " http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns=" http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<?php
$con = mysql_connect("localhost","com1892","14011991");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}if (mysql_query("CREATE DATABASE my_db",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}mysql_close($con);
?>

</body>
</html>
this then showed the folling message "Warning: mysql_connect(): Access denied for user 'com1892'@'localhost' (using password: YES) in /var/www/vhosts/sickstudentgames.com/httpdocs/php attempt 1/tableattempt2.php on line 10
Could not connect: Access denied for user 'com1892'@'localhost' (using password: YES)"


any help greatly appriciated
thanks you
TOPICS
Server side applications
234
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jul 03, 2008 Jul 03, 2008
LATEST
james1892 wrote:
> Hello, i am new to php so be prepared for a idiots question,Hello, Do i need to
> run this on my localhost or can i run it on my virtual server as this allready
> has php mysql etc installed.

You don't need a local testing environment, but it's highly recommended
that you do. It's much more efficient and secure.

> i have been trying to
> copy a youtube tutorial to create a navbar using php mysql and dreamweaver
> " http://www.youtube.com/watch?v=habZHcnShfs"

I watched about four minutes of that "tutorial". It's totally useless.


> $query = 'CREATE TABLE 'menu' (
> 'mid' TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
> 'name' varchar(20) NOT NULL
> 'link' varchar(100) NOT NULL,
> PRIMARY KEY ( 'mid' )
> )';

The reason that doesn't work is because the creator of the "tutorial"
failed to explain the difference between quotation marks and backticks.
What actually appears on screen is not what you have typed, but this:

$query = 'CREATE TABLE `menu` (
`mid` TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
`name` varchar(20) NOT NULL
`link` varchar(100) NOT NULL,
PRIMARY KEY ( `mid` )
)';


Note the difference between ' and `. The second one is called backtick,
and is located above the tab key on most keyboards. In this case, you
don't need it. The following would be fine:

$query = 'CREATE TABLE menu (
mid TINYINT( 3 ) UNSIGNED NOT NULL AUTO_INCREMENT,
name varchar(20) NOT NULL
link varchar(100) NOT NULL,
PRIMARY KEY (mid)
)';

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines