Jump to content


Photo

First day of PHP, please help..


  • Please log in to reply
4 replies to this topic

#1 duncanhall

duncanhall
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 August 2006 - 03:46 PM

So today I decided to make "the switch" from .NET to PHP and, being very new, need a little help.

I have been following a simple tutorial to create a login/out page with a MySQL database. I have a "create_table.php" page which returns the following error:

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING  on line 6

the code is:

<?php
require_once('connect.php');
mysql_query('CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
`date_registered` int(10) NOT NULL default '0',
`last_seen` int(10) NOT NULL default '0',
PRIMARY KEY (`id`)
)');
echo 'Table created';
?>

Any help on this would be most appreciated.

#2 shocker-z

shocker-z
  • Members
  • PipPipPip
  • Advanced Member
  • 864 posts
  • LocationNottingham

Posted 11 August 2006 - 03:53 PM

<?php
require_once('connect.php');
mysql_query("CREATE TABLE `users` (
`id` int(11) NOT NULL auto_increment,
`username` varchar(20) NOT NULL default '',
`password` varchar(32) NOT NULL default '',
`date_registered` int(10) NOT NULL default '0',
`last_seen` int(10) NOT NULL default '0',
PRIMARY KEY (`id`)
)");
echo 'Table created';
?>


give that a blast mate :)

i just changed mysql_query('your statement') to mysql_query("'your statement")


Regards
Liam
www: www.ukchat.ws | irc: irc.ukchat.ws chan: #blufudge

#3 Ninjakreborn

Ninjakreborn
  • Members
  • PipPipPip
  • Information Technology Specialist
  • 3,922 posts
  • Age:33

Posted 11 August 2006 - 03:55 PM

You are starting off getting bad habits, it's ALWAYS safer to run your query's through a variable, and allows for easier changes and error handling.
Learning sql this way is good but you will NEVER have a purpose to use something like this in a live application, creating tables on the fly in an application can be dangerous, and after awhile you get enough tables it starts to kill the database.  If you are wanting to learn sql syntax, use a program, so it can tell you where your syntax errors are located when you are in sql prompt.

------

Business Website: http://www.infotechnologist.biz

Personal Website: http://www.joyelpuryear.com

Blog Site: http://www.realmofwriting.com
Services: Web development, application development, mobile development, and custom development. All services listed on my website.


#4 duncanhall

duncanhall
  • Members
  • PipPip
  • Member
  • 11 posts

Posted 11 August 2006 - 03:59 PM

Cheers Liam, that worked!

businessman, would you mind elaborating on "It's ALWAYS safer to run your query's through a variable"?
Would you suggest using phpMyAdmin to configure my tables?


#5 High_-_Tek

High_-_Tek
  • Members
  • PipPipPip
  • Advanced Member
  • 72 posts

Posted 11 August 2006 - 04:24 PM

No,

buisnessman in saying that you want to assign the query to a variable, and then set that variable as the mysql_query string as so:

$q = "SELECT * FROM table";
$result = mysql_query($q);





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users