MySQL&PHP newbie problem : /> </span> </td

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

MySQL&PHP newbie problem : /> </span> </td

Post by pb2ya »

I used to be able to use MySQL better, guess all these free scripts I used made me lazy :) anyways, I've been coding and searching for an hour, and cant seem to find out how to do the simplest thing: add a record into a table.
can someone please help me do this?

$connect is the select database function

Code: Select all

@mysql_query("INSERT INTO soda_sodas(image, imageb, title, company, categories, information, review, rating)", "VALUES ('blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah',)", $connect) or die(mysql_error());
thanks in advance.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Code: Select all

@mysql_query("INSERT INTO soda_sodas(image, imageb, title, company, categories, information, review, rating) VALUES ('blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah')", $connect) or die(mysql_error());
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Just to state the difference in markl999's code (as it may not be immediately obvious), the ", " needed to be deleted from:

Code: Select all

review, rating)", "VALUES ('blah', 'blah',
as the SQL statement should be all in one string.

You will probably find that debugging will be made easier in the long run if you separate your SQL statements from the mysql_query() function so that you have things like:

Code: Select all

$sql = "INSERT INTO soda_sodas(image, imageb, title, company, categories, information, review, rating) VALUES ('blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah')";
@mysql_query($sql, $connect) or die(mysql_error().'<p>'.$sql.'</p>');
It makes it easier to echo out the SQL for testing.

Mac
User avatar
devork
Forum Contributor
Posts: 213
Joined: Fri Aug 08, 2003 6:44 am
Location: p(h) developer's network

Post by devork »

yes twig is right along with the mysql_error it is good habit to echo also the query also that you are running...
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

>_<

Post by pb2ya »

:( I keep getting a parse error :?:

Code: Select all

<?php
require("includes/connect.php");
$sql = "INSERT INTO soda_sodas(image, imageb, title, company, categories, information, review, rating) VALUES ('blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah', 'blah')"; 
mysql_query($sql, $connect) or die (mysql_error().'<p>'.$sql.'</p>');
mysql_close($connect);
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

There's no parse error in the code you posted - is there other code above this?

Mac
pb2ya
Forum Commoner
Posts: 42
Joined: Sat Jul 06, 2002 5:20 pm
Location: ATL
Contact:

Post by pb2ya »

:| there was an errors in the include file... sorry.
the strange thing is, the include file "connect.php" includes another file, which didnt exist... but I got a parse error instead of the normal include file error.
hmm... probably a bug in php.
thanks a lot :mrgreen:

btw- nice sig devork, im on linux right now.
Post Reply