Closed Thread Icon

Topic awaiting preservation: PHP and MySQL (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=12821" title="Pages that link to Topic awaiting preservation: PHP and MySQL (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: PHP and MySQL <span class="small">(Page 1 of 1)</span>\

 
FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-17-2003 21:07

Maybe I'm just thick, but I can't figure out how to write to my database. Followinf tutorials, I can connect to my database propperly, but I cannot figure out how to write to it. I am not sure if I can read from it because there's nothing in the database to read.

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-17-2003 22:12

FlagMan: If I understand right use something like:

code:
$sql = "INSERT INTO my_table (field1, field2)
VALUES ('data1', 'data2')";



If you don't actually have the table setup then it might be a good idea to use something like phpmyAdmin to create your table.

___________________
Emps

FAQs: Emperor

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-17-2003 23:41

No, the table was already created for me by the admin (just using some crappy free account to test stuff and learn php), and I can load it good, I just didn't know how to write to it.

*EDIT* or maybe I'm just not thinking here...


[This message has been edited by FlagMan (edited 07-17-2003).]

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-18-2003 00:08

I'm not really sure on this stuff, I can't find any solid doccumentation on it. This is what I have so far, it should create my table, but it just shows up like there's a syntax error (<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ect...). I know the login works, becuase I have done that before with no errors, so it must be something wrong with "CREATE TABLE". I have no clue on the syntax of "CREATE TABLE", I pretty much just copied that off a tutorial, so I'm 99% certain that's where the error is.

code:
<?php
$link = mysql_connect ("localhost", "Flag", "don't_think_i'd_say_it?")
or die("Unable to connect, please refresh your browser.");
$db = mysql_select_db ("Flag", $link)
or die ("Unable to select database, please refresh your browser.");
$res = mysql_query("CREATE TABLE users (id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT,
first varchar(20), last varchar(20), address varchar(255), position varchar(50),
PRIMARY KEY (id), UNIQUE id (id)))
or die("Table Creation Failed");
?>



[edit: Killed HSBoD]

[This message has been edited by Emperor (edited 07-18-2003).]

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-18-2003 01:20

FlagMan: Well if the table has already been created then you will fail when you try to create the table again.

You will need the following:

INSERT - will add a new record (row) to your database.

UPDATE - will allow you to edit an existing record.

___________________
Emps

FAQs: Emperor

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-18-2003 03:38

Now that I think about it, I don't think there is a table... Maybe I don't understand how this is setup, does this work like a spreadsheet with column and row names? or is there only one column with lots of rows? or neither?

Also, is there a way to check what my database looks like so far?

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-18-2003 10:50

http://www.mysql.com/doc .

About the second best documentation you'll get for anything on the net.

Of course, it is not an introductuory sql course... but it's a very sound documentation.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-18-2003 14:37
quote:
Of course, it is not an introductuory sql course...



This is - http://www.w3schools.com/sql/ =)

Might be helpful....


jiblet
Paranoid (IV) Inmate

From: Minneapolis, MN, USA
Insane since: May 2000

posted posted 07-18-2003 22:52

Well, if you copied and pasted, I see a problem right off the bat. You forgot to close out your query with a " right before the last parenthesis. That would definitely give you a syntax error (although I don't know what you mean by a doctype showing up on syntax error, usually it's a line # and an error type).

-jiblet

Emperor
Maniac (V) Mad Scientist with Finglongers

From: Cell 53, East Wing
Insane since: Jul 2001

posted posted 07-18-2003 23:17

I have noticed errors like that if there is an error (esp. with XHTML) - it seems to be a IE problem and if you view it in another browser you can see the actual error. Its a pain.

___________________
Emps

FAQs: Emperor

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-24-2003 01:08

yes, when there is a syntax error (eg. a missing semi-colon) it just shows a blank page, which always has the same source.

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-24-2003 01:38

Tyberius: I looked at that before, but it doesn't tell any PHP-mySQL related commands.

I tryed MyPHPAdmin, but my server wouldn't let me run it for some reason (??). I just got a new (and faster) mySQL database today, so I will try it on that.

DL-44
Maniac (V) Inmate

From: under the bed
Insane since: Feb 2000

posted posted 07-24-2003 02:39

Well, TP's link, my previous link, the PHP Manual, and this tutorial at the Gurus Network - http://www.gurusnetwork.com/tutorials/php/dynamic_php_mysql_1.html should give you everything you need to get going....


Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-24-2003 16:39

and there are not 'php-mysql-related' commands.

There's SQL, a language used to speak to the database.
And there's PHP, which has a couple dozen functions to send SQL to a database and make sense of it's result.
but there are no special commands for php in mysql. once you know sql, you could as well use it from perl. Or c. or about anything for that matter

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-25-2003 00:39

Ya, well the problem is, I don't know the PHP-SQL commands.

It turns out my new host does show error messages (unlike my old one).

DL-44: I will give that tutorial a look.

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-25-2003 01:32

Well, I can't get PHPmyAdmin to work, and I don't know what kind of shit I have done to my database (I think I have created a table?). Is there a PHP script that shows what's in your database (if that's even possible)?

All I wanted was a simple counter, I'm sure that plenty of guys here could make one in a minute, but I can't for the life of me figure it out.

If I created my table correctly, and am right in guessing how the table is formatted, my table is called "counter" and it has 2 columns; counter and number.

code:
mysql_query(" CREATE TABLE counter(
counter INT NOT NULL AUTO_INCREMENT,
number INT NOT NULL,
PRIMARY KEY (counter),
UNIQUE UC_id (counter))");



I tried "mysql_query(SELECT number FROM counter,$connection);" but I walays get a parse error because I don't know how it should be formatted... I'm all confused.

trib
Paranoid (IV) Inmate

From: Den Haag, Netherlands
Insane since: Sep 2002

posted posted 07-25-2003 09:57

The query is a STRING ... so ... mysql_select('SELECT number FROM counter', $connection); ... might have a better chance of working ...

Personally, I prefer to separate out the query from the query definition ... so

$sql_query = 'SELECT number FROM counter';
mysql_select($sql_query, $connection);

I dunno why, but for me it makes the code more self-documenting and esier to read/debug/alter in the distant future.

In your code higher up ...

$res = mysql_query("CREATE TABLE users (id tinyint(4) DEFAULT '0' NOT NULL AUTO_INCREMENT, first varchar(20), last varchar(20), address varchar(255), position varchar(50), PRIMARY KEY (id), UNIQUE id (id)) ***THERE IS A QUOTE MARK MISSING JUST HERE*** ) or die("Table Creation Failed");

... the query string starts with a " quote but does not end with one ...


Bug-free software only exisits in two places
A programmer's mind and a salesman's lips

[This message has been edited by trib (edited 07-25-2003).]

[This message has been edited by trib (edited 07-25-2003).]

FlagMan
Bipolar (III) Inmate

From: Calgary Alberta Canada
Insane since: Dec 2002

posted posted 07-28-2003 01:32

As I said, I copied that code from a tutorial, so they must have missed the quotation...

Please tell me if I am correct in assuming this is how my table is setup after going

code:
mysql_query("CREATE TABLE counter(    counter INT NOT NULL AUTO_INCREMENT,    number INT NOT NULL,    PRIMARY KEY (counter),    UNIQUE UC_id (counter))");



...

<BLOCKQUOTE><FONT face="Verdana, Arial">code:</font><HR><pre>
Table Name: Counter
-----------------------

« BackwardsOnwards »

Show Forum Drop Down Menu