Page 1 of 1

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

Posted: Tue Oct 21, 2003 8:43 pm
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.

Posted: Tue Oct 21, 2003 8:58 pm
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());

Posted: Wed Oct 22, 2003 3:16 am
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

Posted: Wed Oct 22, 2003 5:28 am
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...

>_<

Posted: Wed Oct 22, 2003 2:26 pm
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);
?>

Posted: Thu Oct 23, 2003 2:56 am
by twigletmac
There's no parse error in the code you posted - is there other code above this?

Mac

Posted: Thu Oct 23, 2003 2:14 pm
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.