Jump to content


Check out our Community Blogs

Register and join over 40,000 other developers!


Recent Status Updates

View All Updates

Photo
- - - - -

MySQL - checkbox that overlays "sold" png.

align mysql

  • Please log in to reply
1 reply to this topic

#1 Julien Duponte

Julien Duponte

    CC Newcomer

  • Just Joined
  • PipPip
  • 19 posts

Posted 14 April 2011 - 04:53 PM

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.
  • 0

#2 Alexander

Alexander

    YOL9

  • Moderator
  • 3963 posts
  • Location:Vancouver, Eh! Cleverness: 200
  • Programming Language:C, C++, PHP, Assembly

Posted 14 April 2011 - 10:04 PM

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)
  • 0

All new problems require investigation, and so if errors are problems, try to learn as much as you can and report back.






Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download