lil question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Ivana
Forum Newbie
Posts: 10
Joined: Mon Nov 03, 2008 5:05 pm
Location: netherlands

lil question

Post by Ivana »

ok my teacher at school today told to do someting with creating table insert information select, update and delite. i got the first part done.. i have just got stuck at the insert part.
my teacher gave me a link to a website about to make it. i understand what it says i just have no idea how to actualy make it myself with the table i made.
http://www.php-mysql-tutorial.com/mysql-insert-php.php
this is how they tell me to do it just for some reason i can't figure out how to change that into the table i use :S


i don't know if it is needed but i'll but it here anyway
the names of the thingys i used in the table are:
Project_id
Project_description
Start_date
End_date
Last_modification_date
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: lil question

Post by requinix »

Code: Select all

<?php
// include 'library/config.php';
// include 'library/opendb.php';
 
// mysql_select_db($mysql);
$query = "INSERT INTO user (host, user, password, select_priv, insert_priv, update_ priv) VALUES ('localhost', 'phpcake', PASSWORD('mypass'), 'Y', 'Y', 'Y')";
 
mysql_query($query) or die('Error, insert query failed');
 
// $query = "FLUSH PRIVILEGES";
// mysql_query($query) or die('Error, insert query failed');
 
// include 'library/closedb.php';
?>
The bits that are commented out aren't relevant.

Line 6 is the query - the thing you want to change.
The basic syntax for an INSERT query is

Code: Select all

INSERT INTO table (field1, field2, field3, ...) VALUES (value1, value2, value3, ...)
Just fill in the table, fieldX, and valueX parts and that's it.
Ivana
Forum Newbie
Posts: 10
Joined: Mon Nov 03, 2008 5:05 pm
Location: netherlands

Re: lil question

Post by Ivana »

i knew that but i don't know how to use the table i made wel had to make and fill it in there.
like with the begin date end date etc. and then make it a form of it.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: lil question

Post by aceconcepts »

What do you mean by "I don't know how to use the table"?
Ivana
Forum Newbie
Posts: 10
Joined: Mon Nov 03, 2008 5:05 pm
Location: netherlands

Re: lil question

Post by Ivana »

it just confuses me all trying to fill it in can't seem to do it the right way and make it working.

Code: Select all

 
<?php
include 'config.php';
include 'opendb.php';
 
mysql_select_db($dbname);
$query = "INSERT INTO user (Project_name, Project_description, Start_date, End_date, Last Modification date, update_ priv) VALUES ('projectname', 'the discription',yyyy-mm-dd', 'yyyy-mm-dd', now())";
 
mysql_query($query) or die('Error, insert query failed');
 
$query = "FLUSH PRIVILEGES";
mysql_query($query) or die('Error, insert query failed');
 
?>
 
this is what i have till now but i got stuck there

i have the includes also because i did it step by step so i use difrent files to connect to the db etc.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: lil question

Post by aceconcepts »

You're missing ' from your start date in values() and the field counts don't match. update_ priv no value in values().

Also, MySQL will not like 'YYYY-m-d' if your field's datatype is date (which it should be).
Ivana
Forum Newbie
Posts: 10
Joined: Mon Nov 03, 2008 5:05 pm
Location: netherlands

Re: lil question

Post by Ivana »

Code: Select all

 
 <?php
 include 'config.php';
 include 'opendb.php';
  
 mysql_select_db($dbname);
 $query = "INSERT INTO user (Project_name, Project_description, Start_date, End_date, Last Modification date, update_ priv) VALUES ('projectname', 'the discription',date(), date(), now())";
  
 mysql_query($query) or die('Error, insert query failed');
  
 $query = "FLUSH PRIVILEGES";
 mysql_query($query) or die('Error, insert query failed');
  
 ?>
 
so like this?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: lil question

Post by josh »

Is your table named `user` ? Your teacher told you to program a site using SQL but didnt teach you concepts of tables and fields and how they go into queries? :roll:
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: lil question

Post by aceconcepts »

You also have blank spaces in your table's field names: "Last Modification date" use underscores "Last_Modification_date"

Also, the field count must also match the values count.
Ivana
Forum Newbie
Posts: 10
Joined: Mon Nov 03, 2008 5:05 pm
Location: netherlands

Re: lil question

Post by Ivana »

he did explain but the guy isn't really a teacher just beeing pulled out of the daylywork life and beeing put infront of a class and has to exlain it while he doesn't know how. i got the the exact lesson of what he explaint but he didn't really got into it much or told us how to use it.

the user has to be Projecten forgot to change that part hmm and i also for the _ in the last name for the rest is it alright like that? \
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: lil question

Post by josh »

In my opinion you should find some introductory tutorials, learn some of this stuff and savvy up, and teach the class for him :wink: A nother good starting point would be installing phpmyadmin, it provides a GUI and generates queries for you. You can either copy & paste their queries or learn from them as you use the UI tool to do the database operations for you
Ivana
Forum Newbie
Posts: 10
Joined: Mon Nov 03, 2008 5:05 pm
Location: netherlands

Re: lil question

Post by Ivana »

the database i use for it is an phpadmin db but my teacher is beeing an ass and make us do it this way to make the table etc. wel if i can't get it working i'll send the unfinished one to him and ask him next week how to do it. as i only see him on mondays :S
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: lil question

Post by josh »

If you use phpmyadmin it shows you the queries it runs, you could copy and paste those and modify them as need be
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: lil question

Post by Jade »

Lol, why are we doing this kids homework for him?? Sounds like someone was sleeping in class -- my favorite pastime!
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: lil question

Post by josh »

exactly :wink:
Post Reply