Jump to content

Wierd things happening


jwwceo

Recommended Posts

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

[code]<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>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.