Changed to mysqli, and with some messages to put out debugging info, try this (set up the database connection fields to suit your db):-
<div class="adjust">
<?php
$link = new mysqli("hostname", "username", "password", "databasename");
if ($link->connect_errno)
{
printf("Connect failed: %s\n", $link->connect_error);
exit();
}
?>
<center><form class="greatForm" method="post" action="#">
<?php
$sql = "SELECT price, item_name, item_label, item_img FROM extra_item WHERE theme_name = '$title'";
if ( ($read_extra = $link->query($sql)===false )
{
echo "Invalid query: ".$link->error."\r\n $sql\r\n";
exit();
}
while($show_extra = $read_extra->fetch_array(MYSQLI_ASSOC))
{
$_SESSION['getextraprice'] = $show_extra['price'];
$_SESSION['getextraname'] = $show_extra['item_name'];
?>
<input type="checkbox" name="<?php echo $show_extra['price']; ?>" id="<?php echo $show_extra['item_label']; ?>" value="<?php echo $show_extra['item_label']; ?>"/>
<label for="<?php echo $show_extra['item_label']; ?>" >
<img style="height:150px;width:150px;" src="<?php echo 'themeinfo/extra/'.$show_extra['item_img']; ?>"/><?php echo $show_extra['item_name']; ?></label>
<?php
}
?>
<center><br><br><input type="submit" class="button" style="width:10%;" value="SAVE" name="choose_extra"></center></br>
</form></center>
<?php
if(isset($_POST['choose_extra']))
{
$getextraprice = $_SESSION['getextraprice'];
$getextraname = $_SESSION['getextraname'];
$sql = "INSERT INTO selectextra(user,title,extraitem,price) VALUES('$username','$title','$getextraname,'$getextraprice')";
if ( ($insert = $link->query($sql)===false )
{
echo "failed: ".$link->error."\r\n $sql\r\n";
}
else
{
echo "Order SAVE.";
}
}
?>
</div>
</div>
EDIT - if you really want to use mysql_* calls then try this, which will at least let you know what the errors are:-
<div class="adjust">
<center><form class="greatForm" method="post" action="#">
<?php
$read_extra = mysql_query("SELECT price, item_name, item_label, item_img FROM extra_item where theme_name = '".mysql_real_escape_string($title)."'") or die(mysql_error());
while($show_extra = mysql_fetch_array($read_extra))
{
$_SESSION['getextraprice'] = $show_extra['price'];
$_SESSION['getextraname'] = $show_extra['item_name'];
?>
<input type="checkbox" name="<?php echo $show_extra['price']; ?>" id="<?php echo $show_extra['item_label']; ?>" value="<?php echo $show_extra['item_label']; ?>"/>
<label for="<?php echo $show_extra['item_label']; ?>" >
<img style="height:150px;width:150px;" src="<?php echo 'themeinfo/extra/'.$show_extra['item_img']; ?>"/><?php echo $show_extra['item_name']; ?></label>
<?php
}
?>
<center><br><br><input type="submit" class="button" style="width:10%;" value="SAVE" name="choose_extra"></center></br>
</form></center>
<?php
if(isset($_POST['choose_extra']))
{
$getextraprice = mysql_real_escape_string($_SESSION['getextraprice']);
$getextraname = mysql_real_escape_string($_SESSION['getextraname']);
$takeextra = mysql_query("INSERT INTO selectextra(user,title,extraitem,price) VALUES('".mysql_real_escape_string($username)."','".mysql_real_escape_string($title)."','$getextraname,'$getextraprice')") or die(mysql_error());
if($takeextra)
{
echo "Order SAVE.";
}
else{
echo "failed";
}
}
?>
</div>
</div>
If you want to get the checkboxes that have been ticked then something like this would do it:-
<div class="adjust">
<center><form class="greatForm" method="post" action="#">
<?php
$read_extra = mysql_query("SELECT price, item_name, item_label, item_img FROM extra_item where theme_name = '".mysql_real_escape_string($title)."'") or die(mysql_error());
while($show_extra = mysql_fetch_array($read_extra))
{
$_SESSION['getextraprice'] = $show_extra['price'];
$_SESSION['getextraname'] = $show_extra['item_name'];
?>
<input type="checkbox" name="<?php echo $show_extra['price']; ?>" id="<?php echo $show_extra['item_label']; ?>" value="<?php echo $show_extra['item_label']; ?>"/>
<label for="<?php echo $show_extra['item_label']; ?>" >
<img style="height:150px;width:150px;" src="<?php echo 'themeinfo/extra/'.$show_extra['item_img']; ?>"/><?php echo $show_extra['item_name']; ?></label>
<?php
if(isset($_POST['choose_extra']) and array_key_exists($show_extra['price'], $_POST) and $_POST[$show_extra['price']] != '')
{
$takeextra = mysql_query("INSERT INTO selectextra(user, title, extraitem, price)
VALUES('".mysql_real_escape_string($username)."',
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($show_extra['item_name'])."',
'".mysql_real_escape_string($_POST[$show_extra['price']])."')") or die(mysql_error());
}
}
?>
<center><br><br><input type="submit" class="button" style="width:10%;" value="SAVE" name="choose_extra"></center></br>
</form></center>
</div>
</div>
Note this is very much a guess as it seems very strange to have fields on which the field name is a numeric price.
EDIT - further update based on guesses:-
<div class="adjust">
<center><form class="greatForm" method="post" action="#">
<?php
$read_extra = mysql_query("select id, item_label, price, item_name, item_img from extra_item where theme_name = '$title'");
while($show_extra = mysql_fetch_array($read_extra))
{
echo "<input type='checkbox' name='checkextra[".$show_extra['id']."]' id='".$show_extra['item_label']."' value='".$show_extra['price']."'/>";
echo "<label for='".$show_extra['item_label']."' >";
echo "<img style='height:150px;width:150px;' src='themeinfo/extra/'".$show_extra['item_img']."'/>".$show_extra['item_name']."</label>";
echo "<input type='hidden' name='item_name[".$show_extra['id']."]' value='".$show_extra['item_name']."'/>";
}
echo "<center><br><br><input type='submit' class='button' style='width:10%;' value='SAVE' name='choose_extra'></center></br>";
echo "</form></center>";
if(isset($_POST['choose_extra']))
{
foreach($_POST['checkextra'] as $getextraprice_id=>$getextraprice)
{
$takeextra = mysql_query("INSERT INTO selectextra(user,title,extraitem,price)
VALUES('".mysql_real_escape_string($username)."',
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($_POST['item_name'][$getextraprice_id])."',
'".mysql_real_escape_string($getextraprice)."')") or die(mysql_error());
}
if($takeextra)
{
echo "<center>Extra item order SAVE.</center>";
}
else
{
echo "failed";
}
}
?>
</div>
Put out the checkbox with a value of the price, and a hidden field containing the item_name. Both as arrays. The index of these arrays should match. When you process the form you loop through the checkboxes you get the index of each checkbox array item and use that as the index to access the item_name field.
EDIT again. Used a sequence number to force the index of the arrays of form elements (probably should be necessary, but I prefer to force things) rather than using a field from the table.
<div class="adjust">
<center><form class="greatForm" method="post" action="#">
<?php
$conn = mysql_connect('localhost', 'root', '');
mysql_select_db('test', $conn);
$title = 'fred';
$username = 'jo';
$read_extra = mysql_query("SELECT item_label, price, item_name, item_img FROM extra_item WHERE theme_name = '$title'");
$row_cnt = 0;
while($show_extra = mysql_fetch_array($read_extra))
{
echo "<input type='checkbox' name='checkextra[$row_cnt]' id='".$show_extra['item_label']."' value='".$show_extra['price']."'/>";
echo "<label for='".$show_extra['item_label']."' >";
echo "<img style='height:150px;width:150px;' src='themeinfo/extra/'".$show_extra['item_img']."'/>".$show_extra['item_name']."</label>";
echo "<input type='hidden' name='item_name[$row_cnt]' value='".$show_extra['item_name']."'/>";
$row_cnt++;
}
echo "<center><br><br><input type='submit' class='button' style='width:10%;' value='SAVE' name='choose_extra'></center></br>";
echo "</form></center>";
if(isset($_POST['choose_extra']))
{
foreach($_POST['checkextra'] as $getextraprice_id=>$getextraprice)
{
$takeextra = mysql_query("INSERT INTO selectextra(user,title,extraitem,price)
VALUES('".mysql_real_escape_string($username)."',
'".mysql_real_escape_string($title)."',
'".mysql_real_escape_string($_POST['item_name'][$getextraprice_id])."',
'".mysql_real_escape_string($getextraprice)."')") or die(mysql_error());
}
if($takeextra)
{
echo "<center>Extra item order SAVE.</center>";
}
else
{
echo "failed";
}
}
?>
</div>
$title
out of the single quotes because the value in that variable won't be picked up. So it should read:"select * from theme where title = '" . $title . "'
– user1849060 May 19 '14 at 11:56