Jump to content

MySQL - checkbox that overlays "sold" png.

- - - - -

  • Please log in to reply
1 reply to this topic

#1
Julien Duponte

Julien Duponte

    Newbie

  • Members
  • PipPip
  • 19 posts
Hello!
I'm trying to create an script that updates an image that is displayed. Overlaying a "Sold" graphic, whenever the customer checks the "Sold" checkbox, on the update form.

Can I create a blank "sold" column in a table that can be used with a 1/0 IF statement. If the checkbox is checked, it tells the dynamic site to overlay the png file? If not, it doesn't do anything.

<?

$id=$_POST['id'];

$db="DB_name";

$link = mysql_connect('nwtillers', 'un', 'pw');

if (! $link)

die("Couldn't connect to MySQL");


mysql_select_db($db , $link)

or die("Couldn't open $db: ".mysql_error());


$query=" SELECT * FROM used_equip WHERE id='$id'";

$result=mysql_query($query);

$num=mysql_num_rows($result);


$i=0;

while ($i < $num) {

$model=mysql_result($result,$i,"model");

$serial=mysql_result($result,$i,"serial");

$application=mysql_result($result,$i,"application");

?>

<table width="600" cellpadding="10" cellspacing="0" border="2">

<tr align="center" valign="top">

<td align="center" colspan="1" rowspan="1" bgcolor="#64b1ff">

<h3>Edit and Submit</h3>

<form action="item_change_record.php" method="post">

<input type="hidden" name="ud_id" value="<? echo "$id" ?>">

Model #:<input type="text" name="ud_model" value="<? echo "$model"?>"><br />

Serial #: <input type="text" name="ud_serial" value="<? echo "$serial"?>"><br >

Application: <input type="text" name="ud_application" value="<? echo "$application"?>"><br />

<br>

<input type="checkbox" name="ud_sold" value="? idk" />  Item Sold<br />

<input type="Submit" value="Update">

</form>

 

 

<form action="item_remove.php" method="post">

<input type="Submit" value="Delete Item">

</form>

</td></tr></table>


<?

++$i;

}

?>


This is the update form.
Here is item_change_record.php:

<html><head><title></title></head>

<body>

<?

$ud_id=$_POST['ud_id'];

$ud_model=$_POST['ud_model'];

$ud_application=$_POST['ud_serial'];

$ud_application=$_POST['ud_application'];

$db="DB_name";

$link = mysql_connect("nwtwillers", "un", "pw");

if (! $link)

die("Couldn't connect to MySQL");

mysql_select_db($db , $link)

or die("Couldn't open $db: ".mysql_error());

mysql_query(" UPDATE used_equip SET firstname='$ud_model' , lastname='$ud_serial' , birthday='$ud_application' WHERE id='$ud_id'");

echo "Record Updated.";

mysql_close($link);

?>

</body>

</html>

I'm assuming I would use an IF statement here,
to update a $ud_sold to equal 1, if the checkbox was checked?

I know this isn't very well articulated. Thank you ahead of time. Let me know if you need more information.

#2
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,118 posts
  • Location:Vancouver, Eh! Cleverness: 200
Yes, if your checkbox looked like this in your form:
<input type="checkbox" name="sold"/>
You could verify if it is checked or not with this:
$ud_sold = 0;
if(isset($_POST['sold'])) {
     $ud_sold = 1;
}
And store this in a standard TINYINT column (there is no boolean data type for true/false in MySQL unfortunately, so we can use the smallest integer size TINYINT to save database room)
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users