mysql_db_query and how to ... trigger it :)

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
User avatar
robster
Forum Contributor
Posts: 360
Joined: Wed Jul 16, 2003 8:28 am
Location: Sunshine Coast, Australia

mysql_db_query and how to ... trigger it :)

Post by robster »

Code: Select all

//Database initialisation
$connection = mysql_connect($dbhost, $dbusername, $dbpassword);

//Add prelimenary data into the temp artwork table		

$Add = mysql_db_query ($dbname, "INSERT INTO artwork_info_tmp VALUES ('','$gallery_userid','$todays_date','$newfile_name','nullthumb','nullwire','nullwirethumb','temptitle','nullcategory1','nullcategory2','nullcategory3','','','','','','','','','','','','','','','')");
That's my code. Now will that work, assuming that my variables are all correct etc. Or is there something I have to do after mysql_db_query to get it to actually ... trigger.

btw, the '','','' bits are all NULL data being added into the fields.

:)

Thanks a ton,

Rob
eto_na
Forum Newbie
Posts: 2
Joined: Wed Apr 07, 2004 1:07 pm

Post by eto_na »

If your script doesn't work to check your MySQL syntax try:

$Add = mysql_db_query ($dbname, "INSERT INTO artwork_info_tmp VALUES ('','$gallery_userid','$todays_date','$newfile_name','nullthumb','nullwire','nullwirethumb','temptitle','nullcategory1','nullcategory2','nullcategory3','','','','','','','','','','','','','','','')") or die(mysql_error());

it will report you if there're any problems in the query. I suggest you also to some other syntax like:

Code: Select all

<?php
$conn = mysql_connect($host, $user, $pass);
mysql_select_db($db);

$q = "select * from table";
$get = mysql_query($q);
$result = mysql_result($get, 0, 0);

mysql_close($conn);
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You should not be using mysql_db_query() it is deprecated and the manual specifically guides against using it. Instead try adding error handling as eto_na suggested and using mysql_select_db() and mysql_query():

Code: Select all

<?php

// add some error handling to database function
@mysql_connect($dbhost, $dbusername, $dbpassword) or die(mysql_error());
@mysql_select_db($dbname) or die(mysql_error());

// now set the query to its own variable so it can be echoed and 
// checked
$sql = "INSERT INTO artwork_info_tmp VALUES ('','$gallery_userid','$todays_date','$newfile_name','nullthumb','nullwire','nullwirethumb','temptitle','nullcategory1','nullcategory2','nullcategory3','','','','','','','','','','','','','','','')";

// run the query and use error handling to see if any errors are
// occuring

@mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');

// now check if anything was added by using mysql_affected_rows()
echo '<p>There was '.mysql_affected_rows().' record added.</p>';

?>
Mac
Post Reply