PHP not Inserting MySQL records.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Red Blaze
Forum Commoner
Posts: 40
Joined: Mon Mar 27, 2006 3:45 pm

PHP not Inserting MySQL records.

Post by Red Blaze »

Code: Select all

<?php require_once('../Connections/prophot.php'); ?>
<?php
if (!isset($_SESSION)) {
  session_start();
}
$userid = $_SESSION['MM_UserID'];
$aid = $_SESSION['Album_ID'];

$colname_callpack = "-1";
if (isset($_POST['packID'])) {
  $colname_callpack = (get_magic_quotes_gpc()) ? $_POST['packID'] : addslashes($_POST['packID']);
}
mysql_select_db($database_prophot, $prophot);
$query_callpack = sprintf("SELECT * FROM packages WHERE packID = %s", $colname_callpack);
$callpack = mysql_query($query_callpack, $prophot) or die(mysql_error());
$row_callpack = mysql_fetch_assoc($callpack);
$totalRows_callpack = mysql_num_rows($callpack);
$price = $row_callpack['packprice'];

mysql_select_db($database_prophot, $prophot);
$query_callalbum = sprintf("SELECT * FROM gallery_albums WHERE album_id = $aid", $colname_callalbum);
$callalbum = mysql_query($query_callalbum, $prophot) or die(mysql_error());
$row_callalbum = mysql_fetch_assoc($callalbum);
$totalRows_callalbum = mysql_num_rows($callalbum);
$albumname = $row_callalbum['album_name'];

	$sql2 = 'SELECT * FROM carts WHERE albumid = "'.$aid.'" AND userid = "'.$userid.'" AND locked = "'. 0 .'"';
	$query2 = mysql_query($sql2) or die(mysql_error());
if (mysql_num_rows($query2) != 0){
    //rows found
	}else{
$restrict = count(explode(" ", $row_callpack['packsize']));

mysql_query("INSERT INTO carts (itemname,userid,albumid,grandtotal,restrict,locked) VALUES ('$albumname','$userid','$aid','$price','$restrict','0')");
}

echo "albumname $albumname<br>";
echo "userid $userid<br>";
echo "aid $aid<br>";
echo "price $price<br>";
echo "restrict $restrict<br>";
?>
For some reason, it won't insert anything in the database. I tested all the variables and they all have values. It checks to see if a row with the same values alread exists, but this table "carts" is empty. Please help, I think I have a character thats messing things up, but I can't find it.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Re: PHP not Inserting MySQL records.

Post by feyd »

Red Blaze wrote:I think I have a character thats messing things up, but I can't find it.
What does mysql_error() have to say?
Post Reply