...

View Full Version : php/mysql insert..not inserting



SweetG
05-11-2011, 07:59 PM
I just started having an issue with a script that was working before and now its not.. and I'm not so certain its the script that's not working. In the script I execute two insert statements (that insert into two different tables), which previously worked.. Now only one gets inserted while the other does not. I've thoroughly looked over the code and there is nothing wrong with it. Is there anything in my database that could be causing this to happen. I'm just very upset and lost on this, because I really dont understand why one insert statement is working and the other is not.


//gather user information
$query=mysql_query("SELECT * FROM users WHERE id='$_SESSION[id]'");
while($info= mysql_fetch_assoc($query)){
$name = $info['name'];
$pic = $info['propic'];
$realm = $info['realm'];

}

if(empty($detail)){
header('Location:error9.php');
}
elseif(isset($detail)){
//this is the one not inserting
mysql_query("INSERT INTO classifieds VALUES ('','$_SESSION[id]','$name','$pic','$realm','$topic','$detail',now())");
//this one inserts
mysql_query("INSERT INTO activity VALUES ('$_SESSION[id]','$name','$txt',now())");
}
header('Location:edit.php');

I completely redid the form associated with the script and i completely redid the form associated with this script and made the appropriate changes in my code and redid the table in my database.

SweetG
05-11-2011, 09:54 PM
I added the code, I forgot to put it in when I posted.. sorry :)

Old Pedant
05-11-2011, 10:35 PM
So did you *TRY* that query in a MySQL tool? Without using PHP?

And why don't you have any error detection in your PHP code? Or debugging capability, either?

At a minimum, you could do this:



$sql = "INSERT INTO classifieds VALUES ('','$_SESSION[id]','$name','$pic','$realm','$topic','$detail',now())";

// echo the sql so you can try it via some tool, instead of in PHP
echo "DEBUG SQL: " . $sql . "<hr>"; // you can comment this out after it starts working

mysql_query( $sql ) or die( ... );

Put something in the die() that tells you what the error was.

The first thing that occurs to me is that, because you do *NOT* give a list of field names in you INSERT, you may have changed your classifieds table (added or removed a field?) so that you have the wrong number of fields being inserted. But there are other possible errors and until you debug you won't know.

SweetG
05-11-2011, 11:20 PM
So did you *TRY* that query in a MySQL tool? Without using PHP?

And why don't you have any error detection in your PHP code? Or debugging capability, either?

At a minimum, you could do this:



$sql = "INSERT INTO classifieds VALUES ('','$_SESSION[id]','$name','$pic','$realm','$topic','$detail',now())";

// echo the sql so you can try it via some tool, instead of in PHP
echo "DEBUG SQL: " . $sql . "<hr>"; // you can comment this out after it starts working

mysql_query( $sql ) or die( ... );

Put something in the die() that tells you what the error was.

The first thing that occurs to me is that, because you do *NOT* give a list of field names in you INSERT, you may have changed your classifieds table (added or removed a field?) so that you have the wrong number of fields being inserted. But there are other possible errors and until you debug you won't know.

thanks for the debugging thing, i found out exactly what is was.. it was a user submitted ' that was screwing it all up. i think I can fix that :)

Old Pedant
05-11-2011, 11:28 PM
mysql_real_escape_string()



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum