What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Skype & Technology » Tech Talk » PHP and MySQL noob

2 votes - 3 average   PHP and MySQL noob
Author: Message:
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. Huh?  PHP and MySQL noob
I'm trying to make a webpage, that loads the info from my database, that works fine, and putting info in the database with my self made php works too. But i only want one row, so if i put new info in the database it overwrites the old info.

I read on the mysql page i have to use this:
code:
mysql> INSERT INTO table (a,b,c) VALUES (1,2,3)
    -> ON DUPLICATE KEY UPDATE c=c+1;
mysql> UPDATE table SET c=c+1 WHERE a=1;

But i don't undertand it :S, can someone help me?

TIA
[Image: 1-0.png]
             
01-22-2005 07:47 PM
Profile PM Web Find Quote Report
RaceProUK
Elite Member
*****

Avatar

Posts: 6073
Reputation: 57
39 / Male / Flag
Joined: Oct 2003
RE: PHP and MySQL noob
INSERT is just adding a new record into the table.
UPDATE refreshes the table in the database file.
Then again, I'm not overly familiar with MySQL...
[Image: spartaafk.png]
01-22-2005 08:49 PM
Profile PM Web Find Quote Report
Dempsey
Scripting Contest Winner
*****

Avatar
http://AdamDempsey.net

Posts: 2395
Reputation: 53
37 / Male / Flag
Joined: Jul 2003
RE: PHP and MySQL noob
i think you just need to use UPDATE instead of INSERT, as INSERT makes a new record each time
SoundPacks   -   Scripts   -   Skins

that's not a bug, thats an unexpected feature
01-22-2005 09:14 PM
Profile E-Mail PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: PHP and MySQL noob
u mean i just use this?:

code:
UPDATE INTO table (a,b,c) VALUES ('$1','$2','$3')

Or am i just making a fool of myselve :-P
[Image: 1-0.png]
             
01-22-2005 09:19 PM
Profile PM Web Find Quote Report
saralk
Veteran Member
*****

Avatar

Posts: 2598
Reputation: 38
34 / Male / Flag
Joined: Feb 2003
RE: PHP and MySQL noob
code:
UPDATE `table name` SET `column 1` = 'value 1',
`column 2` = 'value 2',
`value 3` = 'value 3' WHERE `id` = '1' LIMIT 1 ;

basically make a table with all the data you want to store, and have a column called id, put one record in it, with the ID as 1, and then just run that script every time you want to update it

This post was edited on 01-22-2005 at 09:37 PM by saralk.
The Artist Formerly Known As saralk
London · New York · Paris
Est. 1989
01-22-2005 09:36 PM
Profile PM Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP and MySQL noob
quote:
Originally posted by saralk
have a column called id, put one record in it, with the ID as 1, and then just run that script every time you want to update it
If there's only one row in the table, you don't need a WHERE statement in your query, because MySQL will update all the rows by default. Since there's only one row, "all" = "one." :p
01-23-2005 12:44 AM
Profile PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: PHP and MySQL noob
I want to post info from a form am i doing it right like this?

code:
$sql= "UPDATE molly SET inhoud = $_POST['inhoud']";
mysql_query($sql) or die (mysql_error());

EDIT: I'm using this but it gives an error, sorry i'm a real n00b :-p, and yes i know i should read some books first, but i'm lazy :-D...
code:
<?

include_once('connection.inc.php');
opendb();

$sql= "UPDATE 'molly' SET 'inhoud' = '$_POST['inhoud']'";
mysql_query($sql) or die (mysql_error());

?>

This post was edited on 01-23-2005 at 01:06 AM by Ezra.
[Image: 1-0.png]
             
01-23-2005 12:59 AM
Profile PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP and MySQL noob
code:
<?

include_once('connection.inc.php');
opendb();

$_POST['inhoud'] = addslashes($_POST['inhoud']);
$sql= "UPDATE molly SET inhoud = '{$_POST['inhoud']}'";
mysql_query($sql) or die (mysql_error());

?>
01-23-2005 01:11 AM
Profile PM Web Find Quote Report
Ezra
Veteran Member
*****

Avatar
Forgiveness is between them and God

Posts: 1960
Reputation: 31
37 / Male / Flag
Joined: Mar 2003
O.P. RE: PHP and MySQL noob
It works, thank you very much :-D

But when I show this on a page things with a ' in them show like this: \'things'\, how do I correct this?

EDIT: Nevermind, i found the stripslashes function :-D

This post was edited on 01-23-2005 at 01:37 AM by Ezra.
[Image: 1-0.png]
             
01-23-2005 01:33 AM
Profile PM Web Find Quote Report
WDZ
Former Admin
*****

Avatar

Posts: 7106
Reputation: 107
– / Male / Flag
Joined: Mar 2002
RE: PHP and MySQL noob
quote:
Originally posted by Ezra
But when I show this on a page things with a ' in them show like this: \'things\'
Oh, sorry... the addslashes() function should always be used on user-inputted data before it's placed in a query, just in case your copy of PHP isn't configured to add slashes automatically. I guess they are added automatically for you. What you could do is change that line of code above to...

if(!get_magic_quotes_gpc()) $_POST['inhoud'] = addslashes($_POST['inhoud']);

Then you won't need stripslashes.
01-23-2005 05:25 AM
Profile PM Web Find Quote Report
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On