MySQL:将数据写入表和列

发布于 2024-12-26 11:21:24 字数 488 浏览 1 评论 0原文

在大学学习网络开发课程时,我一直在浏览数据库时感到恶心。我已经阅读了大多数内容,例如连接到 mysql、选择数据库等等。但我无法弄清楚如何在表的列中添加数据。

我已经尝试了在网上可以找到的内容,但我没有找到任何有用的东西...所以我想知道这里是否有人能好心地向我展示如何将内容写入包含这些列的表中: http://imageshack.us/photo/my-images/851/sqla.png/

我不需要帮助来选择数据库等等,只是如何将这些数据写入数据库。或者像我这样的傻瓜指南的链接...我已经尝试了很多不同的方法

mysql_query(INSERT INTO *** VALUES ****)

但我无法让它工作..

任何帮助都会非常感激,感觉完全迷失了。

提前致谢!

Doing a university course in web development and I've been sick all the time we went thru databases. I've read up on most stuff, like connect to mysql, select DB and that. But something I can't figure out is how to add data in the columns of a table.

I've tried what i could find online but I haven't found anything useful really... So I was wondering if anyone here could be so kind to show me how write stuff to a table with these columns: http://imageshack.us/photo/my-images/851/sqla.png/

I don't need help to select DB etc, just how to write those data into the db. Or a link to a guide for dummies like myself... I've tried a lot of different ways with

mysql_query(INSERT INTO *** VALUES ****)

But I cannot get it to work..

Any help would be really appreciated, feeling totally lost.

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

猫卆 2025-01-02 11:21:24

我的猜测是 song_id 与其他一些表相关,因此您需要在插入请求中具有有效的 song_id ,但类似这样的操作应该有效:

 INSERT INTO `your_table` VALUES(NULL,'Your Text',song_id,CURRENT_TIMESTAMP);

请注意 <如果 code>song_id 与另一个表相关,则应将其替换为有效的 id:

 $song_id = 1;
 $text = "Sample text";
 mysql_query("INSERT INTO `your_table` VALUES(NULL,'$text',$song_id,CURRENT_TIMESTAMP)");

您还应该尝试检查 mysql 文档 此类的问题。

My guess is that song_id is related to some other table so you would need to have a valid song_id in your insert request, but something like this should work:

 INSERT INTO `your_table` VALUES(NULL,'Your Text',song_id,CURRENT_TIMESTAMP);

Notice that the song_id should be replaced with a valid id if it's related to another table:

 $song_id = 1;
 $text = "Sample text";
 mysql_query("INSERT INTO `your_table` VALUES(NULL,'$text',$song_id,CURRENT_TIMESTAMP)");

You should also try checking the mysql documentation for this kind of questions.

生死何惧 2025-01-02 11:21:24

类似的事情应该可以解决问题。

INSERT INTO TABLE_NAME (text, songid, insertdate) VALUES ('TEXT VALUE', 'SONG ID', CURRENT_TIMESTAMP)

这里有一个相当容易理解的参考

Something along the lines of this should do the trick.

INSERT INTO TABLE_NAME (text, songid, insertdate) VALUES ('TEXT VALUE', 'SONG ID', CURRENT_TIMESTAMP)

There's a fairly easy to understand reference here

地狱即天堂 2025-01-02 11:21:24

试试这个:

INSERT INTO <table_name> (text, songid, insertdate) VALUES ('your_text_here', 'your_song_id_here', now());

如果您想要这样的东西,一个有用的指南是 w3schools

Try this:

INSERT INTO <table_name> (text, songid, insertdate) VALUES ('your_text_here', 'your_song_id_here', now());

A useful guide if you want stuff like this is w3schools

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文