Jump to content


Photo

Wierd things happening


  • Please log in to reply
3 replies to this topic

#1 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 29 August 2006 - 01:21 AM

Hello,

I designed this little php page to add edit or delete colors(table 1) and keywords( table 2) to or from a databse a database. The color and keywords are then assigned to shirts in a third and fourth table.

I just added dumped my databse to to do some testing and when I add in data to the color and keyword tables using this page for some reason they don't show up where they are supposed to be listed unless I refresh my page. But when I refesh sometimes it will add a duplicate entry to my database.

I know there is some wierdness going on...but I'm not good enough at this yet to nail it down...

any glaring problems...Thanks in advance!!!!

JW

<html>
<link href="style.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" type="text/css" href="ds.css">

<head>
<title>LiquidCotton.com Admin - Add Edit Delete Colors/Keywords</title>
</head>
<body bgcolor="#FFFFFF">
<a href='admin.php'><img src='images/logo.gif' border='0'></a><br>
<p><b>ADD EDIT OR DELETE COLORS AND KEYWORDS</b></p>


<?php

include 'library/config.php';
include 'library/opendb.php';
error_reporting(0);

if(isset($_POST['keyupdate'])) {

$keyword_id=$_POST['keyword_id'];
$newkeyword=$_POST['newkeyword'];


   $query="UPDATE keywords SET keyword='$newkeyword' WHERE keyword_id ='$keyword_id'";
   $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);


}

elseif(isset($_POST['keydelete'])) {

$keyword_id=$_POST['keyword_id'];


   $query = "DELETE from keywords WHERE keyword_id='$keyword_id'";
   $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

   mysql_query("DELETE FROM shirtkeywords WHERE keyword_id = '$keyword_id'") or die (mysql_query());

}


if(isset($_POST['update'])) {

$color_id=$_POST['color_id'];
$newcolor=$_POST['newcolor'];


   $query="UPDATE colors SET color='$newcolor' WHERE color_id ='$color_id'";
   $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);


}

elseif(isset($_POST['delete'])) {

$color_id=$_POST['color_id'];


   $query = "DELETE from colors WHERE color_id='$color_id'";
   $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query);

   mysql_query("DELETE FROM shirtcolors WHERE color_id = '$color_id'") or die (mysql_query());

}


if(isset($_POST['submitcolor'])) {

   $color=$_POST['color'];

   $query="INSERT INTO colors (color)  VALUES ('$color')";

    $result = mysql_query($query) or die("Eror: ". mysql_error(). " with query ". $query);
    }

elseif (isset($_POST['submitkeyword'])) {


   $keyword=$_POST['keyword'];

   $query="INSERT INTO keywords (keyword)  VALUES ('$keyword')";

    $result = mysql_query($query) or die("Eror: ". mysql_error(). " with query ". $query);
    }

echo
 "<form method='post' action='addcf.php']'>
<TABLE>
<TR>
   <TD><INPUT TYPE='text' NAME='color' class='cartForm'  size=30></TD>
   <td align='left'><INPUT TYPE='submit' name='submitcolor' class='cartForm'  value='Add this Color' size='30'></td>
</TR>
<TR>
   <TD><INPUT TYPE='TEXT' NAME='keyword' class='cartForm'   size=30></TD>
   <td align='left'><INPUT TYPE='submit' name='submitkeyword' class='cartForm'  value='Add this Keyword' size='30'></td>
</TR>
<tr><td colspan='2'><hr></td></tr>
<tr><td colspan='2'>
<table>
<tr><td valign='top'>
<table>
<tr><td colspan='3' align='center' width=150><b>COLORS</b></td></tr>";

$data = mysql_query('SELECT * FROM colors ORDER BY color ASC') or die(mysql_error());
$info = mysql_fetch_array( $data );

while($info = mysql_fetch_array( $data )) {

echo

"<form method='post' action =\"$PHP_SELF\">
<tr><td><input type=text name ='newcolor' class='cartForm' value='".$info['color']."' size='15'></td>
<td><input type='submit' class='cartForm' name='update' value='update'></td>
<td><input type='submit' class='cartForm' name='delete' value='delete'></td>
    <input type='hidden' name ='color_id' value='".$info['color_id']."'
</tr>
</form>";

}
echo
"</table>
</td>
<td valign='top'><table>
<tr><td colspan='3' align='center' width=150><b>KEYWORDS</b></td></tr>";

$keydata = mysql_query('SELECT * FROM keywords ORDER BY keyword ASC') or die(mysql_error());
$keyinfo = mysql_fetch_array( $keydata );

while($keyinfo = mysql_fetch_array( $keydata )) {

echo

"<form method='post' action =\"$PHP_SELF\">
<tr><td><input type=text name ='newkeyword' class='cartForm' value='".$keyinfo['keyword']."' size='15'></td>
<td><input type='submit' class='cartForm' name='keyupdate' value='update'></td>
<td><input type='submit' class='cartForm' name='keydelete' value='delete'></td>
    <input type='hidden' name ='keyword_id' value='".$keyinfo['keyword_id']."'
</tr>
</form>";

}

echo

"</table>

</td>
</tr>
</table>
</tr>
</TABLE>
</form>";



?>

</body>
</html>


#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 29 August 2006 - 02:13 AM

Would you mind using the CODE buttons to wrap your code so that it uses the coloring and syntax highlighting that makes it so much easier to follow (and doesn't take up so much space).
Legend has it that reading the manual never killed anyone.
My site

#3 DarkendSoul

DarkendSoul
  • Members
  • PipPipPip
  • Advanced Member
  • 121 posts

Posted 29 August 2006 - 02:24 AM

i dont follow your question... could you show us the page... or explain better... or a screen shot...

and you can edit your post you know -_-

#4 jwwceo

jwwceo
  • Members
  • PipPipPip
  • Advanced Member
  • 212 posts

Posted 29 August 2006 - 02:28 AM

I will put my page online and post again in a few hours...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users