Jump to content

mysql insert does not work


anocweb

Recommended Posts

i have a website that inserts an item into a database and then uploads the images for a catalog

 

up till recently it worked fine then the owner started having issues. the upload would work but the database wouldn't have the entry in it.

but it worked for me. then just shortly after it stopped working for me as well.

i dont get any errors from mysql, or php

 

im running apache 2.0.52,  php 4.3.9-3.22.5, and mysql 4.1.20-2.RHEL4.1.

 

the mysql variables are in this file:

mysql.inc.php

<?PHP

$servername="localhost"; # enter location of database server
$username="marty"; # enter your username for the database
$password="*******"; # enter you password for the database
$port="3306"; # default is always 3306
$database="content"; # database to connect to

?>

 

the rest of the code is here:

card_upload.php

<?PHP
include('header.inc.php');
include('../mysql.inc.php');
?>

<?php
# connect to database
$connect = $servername . ":" . $port;
$sql = mysql_connect($connect,$username,$password);
# check if connection succeeded
if (!$sql) {die('Could not connect: ' . mysql_error());}
# selects the database
mysql_select_db($database, $sql);


if ($_POST['step'] == "4") {
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "/var/www/vhosts/tradeart.no-ip.org/httpdocs/cards/" . $_POST['style'] . ".a.jpg");
       chmod("/var/www/vhosts/tradeart.no-ip.org/httpdocs/cards/" . $_POST['style'] . ".a.jpg", 0777);
       echo 'DONE UPLOADING ' . $_POST['style'] . '!';
} elseif ($_POST['step'] == "3") {
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "/var/www/vhosts/tradeart.no-ip.org/httpdocs/cards/" . $_POST['style'] . ".i.jpg");
       chmod("/var/www/vhosts/tradeart.no-ip.org/httpdocs/cards/" . $_POST['style'] . ".i.jpg", 0777);
       echo '<form method="post" enctype="multipart/form-data" url="card_upload.php"><table style="text-align: left; width: 80%;" border="0"
cellpadding="2" cellspacing="2">
  <tbody><input type="hidden" name="step" value="4"><input type="hidden" name="style" value="' . $_POST['style'] . '">
    <tr>
      <td>Inside Image:</td>
      <td><input name="uploadFile" type="file"></td>
    </tr>
    <tr>
      <td></td>
      <td><input value="step 4" type="submit"></form></td>
    </tr>
  </tbody>
</table>';
} elseif ($_POST['step'] == "2") {

$inset = 'cards/' . $_POST['style'] . '.a.jpg';
$location = 'cards/' . $_POST['style'] . '.i.jpg';
$check = mysql_query("INSERT INTO product (style, description, category, location, inset, wide) VALUES ('" . $_POST['style'] . "', '" . $_POST['desc'] . "', '" . $_POST['cat'] . "', '$location', '$inset', '" . $_POST['wide'] . "')")or die(mysql_error());
if ($check == "false")
{ echo "ERROR PLEASE GO BACK!<br />"; }
echo '<form method="post" enctype="multipart/form-data" url="card_upload.php"><table style="text-align: left; width: 80%;" border="0"
cellpadding="2" cellspacing="2">
  <tbody><input type="hidden" name="step" value="3"><input type="hidden" name="style" value="' . $_POST['style'] . '">
    <tr>
      <td>Outside Image:</td>
      <td><input name="uploadFile" type="file"></td>
    </tr>
    <tr>
      <td></td>
      <td><input value="step 3" type="submit"></form></td>
    </tr>
  </tbody>
</table>';

} else {
echo '<table style="text-align: left; width: 80%;" border="0"
cellpadding="2" cellspacing="2">
  <tbody>
    <tr>
      <td style="text-align: right;">Style</td>
      <td><form method="post" url="card_upload.php"><input type="hidden" name="step" value="2"><input name="style"></td>
    </tr>
    <tr>
      <td style="text-align: right;">Category</td>
      <td>
      <select size="1" name="cat">';
      $result = mysql_query("SELECT * FROM category");
      while($row = mysql_fetch_array($result)) {
      echo '<option>' . $row['cat'] . '</option>';
      }
echo '</select>
      </td>
    </tr>
        <tr>
      <td></td>
      <td>Horizontal<input checked="checked" name="wide" value="1" type="radio"> Vertical <input name="wide" value="0" type="radio">

</td>
    </tr>
    <tr>
      <td style="text-align: right;">Description</td>
      <td><textarea cols="35" rows="3"
name="desc"></textarea></td>
    </tr>
    <tr>
      <td></td>
      <td><input value="Step 2" type="submit"></form></td>
    </tr>
  </tbody>
</table>';

}
mysql_close($sql);
?>

<?PHP 
include('footer.inc.php');
?>

Link to comment
Share on other sites

i apologize.

 

query

 

mysql_query("INSERT INTO product (style, description, category, location, inset, wide) VALUES ('" . $_POST['style'] . "', '" . $_POST['desc'] . "', '" . $_POST['cat'] . "', '$location', '$inset', '" . $_POST['wide'] . "')")or die(mysql_error());

 

the structure is as follows as well

CREATE TABLE `product` (
  `key` int(255) unsigned NOT NULL auto_increment,
  `style` varchar( NOT NULL default '',
  `description` text,
  `category` varchar(30) NOT NULL default '',
  `location` varchar(45) NOT NULL default '',
  `inset` varchar(45) NOT NULL default '',
  `wide` char(1) default NULL,
  PRIMARY KEY  (`key`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8

Link to comment
Share on other sites

That's not echoing the query to the screen... that's copying and pasting php code, which I've already seen.  It doesn't help me.

 

Store that query in a variable, and echo that variable to the screen, then post it here -- just the sql, not the php.

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.