Page 1 of 1

mysql_db_query and how to ... trigger it :)

Posted: Wed Apr 07, 2004 5:11 pm
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

Posted: Wed Apr 07, 2004 5:36 pm
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);
?>

Posted: Thu Apr 08, 2004 9:07 am
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