/    Sign up×
Community /Pin to ProfileBookmark

php Mysql -begginer problem-

i try to create a mysql table but that dos not work
here is the code

[CODE]
$connec=mysql_connect(“localhost”,”root”,””);
if (!$connec)
{
die(‘could not connect: ‘ .mysql_error());
}
else
{
echo “connction etabli avec succee”;
}
echo “<br/>”;
$nom_bd=”base_test”;
if (mysql_query(“CREATE DATABASE $nom_bd”,$connec))
{
echo “base de donne $nom_bd est creer avec succee”;
}
else
{
echo “erreur dans la creation de la base de donne $nom_bd ou deja creer”;
}
echo “<br/>”;
$nom_bd=”base_test2″;
if (mysql_query(“CREATE DATABASE $nom_bd”,$connec))
{
echo “base de donnee $nom_bd a ete creer avc succee”;
}
else
{
echo “erreur de creation de la base de donne $nom_bd, ou deja creer”;
}
echo “<br/>”;
if (mysql_select_db(“base_test”,$connec))
{
echo “base de donne a ete selectionne avec succee”;
}
else
{
echo “erreur dans la selection de la base donne”;
}
echo “<br/>”;
$sql_tab1= “CREATE TABLE tableau1
(
personnal-id int NOT NULL AUTO_INCREMENT,
PRIMARY_KEY(personnal-id),
first-name varchar (20),
last-name varchar (20),

age int
)”;
mysql_query($sql_tab1,$connec);
[/CODE]

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@MarPloMay 02.2011 — Hy,

Try use this query to create the table:
$sql_tab1= "CREATE TABLE <span><code>tableau1</code></span>
(
<span><code>personnal-id</code></span> int NOT NULL AUTO_INCREMENT PRIMARY KEY,
<span><code>first-name</code></span> varchar(20),
<span><code>last-name</code></span> varchar(20),
<span><code>age</code></span> int
)";
Copy linkTweet thisAlerts:
@channarkauthorMay 02.2011 — thanks but whats the defirents becaus the query i used to create my table its the same in w3cschool
Copy linkTweet thisAlerts:
@NogDogMay 02.2011 — The hyphen is considered a special character in terms of MySQL identifiers (table names, database names, column names etc.), so if used in such a name, then it must be quoted with back-tick quotes. You could use underscores instead in this case and then not have to quote them, though it never hurts to quote them so many people just always quote their identifiers for consistency and to make sure there are no collisions with reserved words, too.

PS: For more info, see the manual on object names: http://dev.mysql.com/doc/refman/5.1/en/identifiers.html
Copy linkTweet thisAlerts:
@DariaMay 02.2011 — ...and to concur with NogDog: Overall it is a much better habit of enclosing the table/field names with ` it allows for much cleaner code and will save you a lot of grief in the long run, especially in cases when for whatever reasons you have named your columns (or what if there is a database someone else had set up and you may be taking over for your client in the future?) with words commonly used in php - such as "use" "month" "date" etc.etc. - this way the code will separate/understand the language better.
Copy linkTweet thisAlerts:
@channarkauthorMay 03.2011 — tank you so much
Copy linkTweet thisAlerts:
@FredTrewsaAug 10.2011 — Thanks!! found the necessary mistake in my code?
×

Success!

Help @channark spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...