Jump to content

Simple mysql_query error, puzzlingly simple...


infantigniter

Recommended Posts

Call me crazy, but I cannot find out what's wrong with this script. Its function is to take the form values and post them to a database called 'games'. The pictures (two fields) both upload fine, onto the server. However nothing is being added to the database, even though no errors are showing. Here's the script:

 

function MySQLDB(){
      /* Make connection to database */
      $this->connection = mysql_connect(DB_SERVER, DB_USER, DB_PASS) or die(mysql_error());
      mysql_select_db(DB_NAME, $this->connection) or die(mysql_error());
  
$q1 = "SELECT MAX(G_ID) FROM ".TBL_GAMES."";
$result1 = mysql_query($q1);
$gid = $result1++;

if (!$q1) {
    $message0  = 'Invalid query: ' . mysql_error() . "\n";
    $message0 .= 'Whole query: ' . $query;
    die($message0);
}

if (!$result1) {
    $messagex  = 'Invalid query: ' . mysql_error() . "\n";
    $messagex .= 'Whole query: ' . $query . "Here's gid: $gid \n";
    die($messagex);
}

$q2 = "INSERT INTO zendscom_zendogames.games (G_ID, G_NAME, G_IMGURL, G_CAT, G_URL, G_YMAL, G_BASEQUICK, G_DESC, G_PUB)
VALUES ('$gid','$gametit','$addimg','$genre','$addswf','$ymal','$bq','$desc','$pub')";

$result2 = mysql_query($q2);


if (!$q2) {
    $message1  = 'Invalid query: ' . mysql_error() . "\n";
    $message1 .= 'Whole query: ' . $query . "\n";
    die($message1);
}

if (!$result2) {
    $message2  = 'Invalid query: ' . mysql_error() . "\n";
    $message2 .= 'Whole query: ' . $query;
    die($message2);
}}

 

That's where the errors are, I believe. Surplus code from above that:

 

$gametit=$_POST[gametit];
$genre=$_POST[genre];
$ymal=$_POST[ymal];
$desc=$_POST[desc];
$pub=$_POST[publisher];
$bq=$_POST[basequick];

//UPLOAD SCRIPT STUFF
/*for game*/
while(list($key,$value) = each($_FILES['games']['name']))
{
if(!empty($value)){
$fileswf = $gametit.$value;
$addswf = "kittens/siamese/$fileswf";
copy($_FILES[games][tmp_name][$key], $addswf);
chmod("$addswf",0777);
}}

//for image
while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value)){
$fileimg = $gametit.$value;
$addimg = "kittens/siamese/avaria/$fileimg";
copy($_FILES[images][tmp_name][$key], $addimg);
chmod("$addimg",0777);
}}

 

However that part seems to work fine. Can anybody figure out what's going wrong here??? (DB_USER, etc. are all defined in an "included" constants php file, which functions fine with the login/registration scripts I use. In fact the registration scripts are almost identical to this, and work!)

 

Thank you.

Well, for starters $result1 is a result resource as returned by mysql_query, no point try to increment it as you do here...

 

$gid = $result1++;

 

I can see plenty else wrong with this code. are you sure you have error_reporting turned on and display_errors enabled?

I removed the $gid part as you said, as well as it being called in the INSERT INTO script. I have the G_ID row on auto_increment so that column should work anyhow. Also, I removed all mention of $q1 and $result1.

 

Both things you mentioned are turned on. If it sheds any light, I was using a different error reporting method before and it printed errors for q2 and result2 but not anything else.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.