Page 1 of 2

lil question

Posted: Mon Nov 03, 2008 6:40 pm
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

Re: lil question

Posted: Mon Nov 03, 2008 6:57 pm
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.

Re: lil question

Posted: Tue Nov 04, 2008 2:54 am
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.

Re: lil question

Posted: Tue Nov 04, 2008 4:36 am
by aceconcepts
What do you mean by "I don't know how to use the table"?

Re: lil question

Posted: Tue Nov 04, 2008 5:24 am
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.

Re: lil question

Posted: Tue Nov 04, 2008 6:14 am
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).

Re: lil question

Posted: Tue Nov 04, 2008 7:00 am
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?

Re: lil question

Posted: Tue Nov 04, 2008 8:02 am
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:

Re: lil question

Posted: Tue Nov 04, 2008 8:19 am
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.

Re: lil question

Posted: Tue Nov 04, 2008 8:27 am
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? \

Re: lil question

Posted: Tue Nov 04, 2008 10:11 am
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

Re: lil question

Posted: Tue Nov 04, 2008 2:00 pm
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

Re: lil question

Posted: Tue Nov 04, 2008 2:14 pm
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

Re: lil question

Posted: Tue Nov 04, 2008 4:41 pm
by Jade
Lol, why are we doing this kids homework for him?? Sounds like someone was sleeping in class -- my favorite pastime!

Re: lil question

Posted: Tue Nov 04, 2008 5:36 pm
by josh
exactly :wink: