User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MySQL section within the Web Development category of DaniWeb, a massive community of 427,849 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,801 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MySQL advertiser: Programming Forums
Views: 737 | Replies: 19 | Solved
Reply
Join Date: Jul 2006
Posts: 158
Reputation: tefflox is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Please help

  #1  
May 13th, 2008
Please tell me what I'm doing wrong. The sql query is in bold.

<?php 
////////////////////////////////////////////////////////////////////////////////
//
// SECRET PAGE
//
//   Invokes require_authentication() to ensure that the user is authenticated
//     
//////////////////////////////////////////////////////////////////////////////// 
require("common.php");
require_authentication();
session_start(); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr' xml:lang="en">
  <head>
    <title>Preview Update</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta name="description" content="Superior Mini Trucks" />
    <meta name="keywords"    content="Wichita, Superior, mini, trucks, 'Mini Trucks'" />
    <link href="" rel="shortcut icon" />    
    
    <link href="../site.css"        media="screen" rel="stylesheet" type="text/css" />
    <link href="../smoothbox.css"   media="screen" rel="stylesheet" type="text/css" />

    <script type="text/javascript" src="../moo.js">                    </script>
    <script type="text/javascript" src="../inventory/index.js">        </script>
    <script type="text/javascript" src="../inventory/smoothbox.js">    </script>
  </head>
<body>

<div id="whole_page">
      <div id="header">
        &nbsp;
      </div>
      <div style="opacity: 0.7; filter: alpha(opacity: 70);" id="nav">
		&nbsp;
      </div>

  <div style="clear: both;"></div>  
    <div style="opacity: 0.95;" class="content">
      <div style="background-color: #fffff0;" id="log">  
 
		<?php
       
	    $data = $_SESSION['data'];

	
		  $year    = $_POST['year'];
		  $make    = $_POST['make'];
		  $model   = $_POST['model'];
		  
		  $miles   = $_POST['miles'];
		  $comment = $_POST['comment'];
		  
		  
		  $option1 = $_POST['option1'];
		  $option2 = $_POST['option2'];
		  $option3 = $_POST['option3'];

		  $option4 = $_POST['option4'];		  
		  $option5 = $_POST['option5'];		  
		  $option6 = $_POST['option6'];		  
		  $option7 = $_POST['option7'];		  
		  $option8 = $_POST['option8'];		  


	$update = array(0 => $data[0], $data[1], $data[2], $data[3], $data[4], $data[5], $data[6], $data[7], $year, $make, $model, $miles, $comment, $option1, $option2, $option3, $option4, $option5, $option6, $option7, $option8);
		  

		echo '<table class="pictured photo_data">';       
        echo '    ';
        echo ' <tr> ';
        echo '   <td width="320"> ';
        echo '     <a href="/inventory/trucks/'.$data[0].'" title="" class="smoothbox" rel="inventory/trucks"><img src="../inventory/trucks/'.$data[4].'" alt="1" /></a></td> ';
        echo '     <td width="320">'.$year.' '.$make.' '.$model.'<br/><br/>'.$miles.'<br/>'.$comment.'<br/><br/> ';
        echo '       <a href="../inventory/trucks/'.$data[1].'" title="" class="smoothbox" rel="inventory/trucks"><img style="float:left" src="../inventory/trucks/'.$data[5].'" alt="2" /></a> ';
        echo '       <a href="../inventory/trucks/'.$data[2].'" title="" class="smoothbox" rel="inventory/trucks"><img style="float:left" src="../inventory/trucks/'.$data[6].'" alt="3" /></a> ';
        echo '       <a href="../inventory/trucks/'.$data[3].'" title="" class="smoothbox" rel="inventory/trucks"><img style="float:left" src="../inventory/trucks/'.$data[7].'" alt="4" /></a> ';        
        echo '     </td> ';
        echo '   <td>'.$option1.'<br/>'.$option2.'<br/>'.$option3.'<br/><br/>';
	if($option4 != "")
		echo $option4.'<br/>';
	if($option5 != null)
		echo $option5.'<br/>';
	if($option6 != null)
		echo $option6.'<br/>';
	if($option7 != null)
		echo $option7.'<br/>';
	if($option8 != null)
		echo $option8;							
		
		
		echo '</td> ';
	    echo ' </tr> ';
        
   
        
  
               
echo '</table>';
echo '<br/><br/><br/>';

			
			echo '<blockquote><blockquote><blockquote>';	
			echo '<form method="post" action="/inventory/">';
			echo '<input type="submit" name="validated_confirmed_update" value="&bull; &bull; &bull; Update Inventory &bull; &bull; &bull;"> (not yet operational)</form>';	
			echo '</blockquote></blockquote></blockquote>';	
				
			



	$db_connection = @mysql_connect("-----------.--------.net", "--------", "---------");
	if (!$db_connection) {
	  echo( "<P>Unable to connect to the database server at this time.</P>" );
	  exit();
	}	
	
	$db = @mysql_select_db("-----------", $db_connection);
	
	if(!$db) {
	  echo( "<P>Unable to locate the database at this time.</P>" );
      exit();
	}
	
	
    if ("SUBMIT" == $validated_confirmed_update) {
      $sql = "INSERT INTO trucks (relpath-box1, relpath-box2, relpath-box3, relpath-primary, relpath-gallery1, relpath-gallery2, relpath-gallery3, year, make, model, miles, comment, option1, option2, option3, option4, option5, option6, option7, option8) VALUES (".$data[0].", ".$data[1].", ".$data[2].", ".$data[3].", ".$data[4].", ".$data[5].", ".$data[6].", ".$data[7].", ".$year.", ".$make.", ".$model.", ".$miles.", ".$comment.", ".$option1.", ".$option2.", ".$option3.", ".$option4.", ".$option5.", ".$option6.", ".$option7.", ".$option8.")"; 
			 
					 
    mysql_query($sql);
 }
?>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Please help

  #2  
May 14th, 2008
Are you getting any error ? The only thing that might be wrong with the query is, not using ' ' while inserting a value to the varchar field. ie.,
  1. $query = "insert into table (col1,col2) values ('test', 'test2')";
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jul 2006
Posts: 158
Reputation: tefflox is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Please help

  #3  
May 14th, 2008
this may be of more help.. I'm desperate to get this working. I've got to finish my current (first) project with this query.

  1. $db_connection = @mysql_connect("----------.------------.net", "----------", "---------------");
  2. if (!$db_connection) {
  3. echo( "<P>Unable to connect to the database server at this time.</P>" );
  4. exit();
  5. }
  6.  
  7. $db = @mysql_select_db("----------", $db_connection);
  8.  
  9. if(!$db) {
  10. echo( "<P>Unable to locate the database at this time.</P>" );
  11. exit();
  12. }
  13.  
  14.  
  15. $sql = "INSERT INTO trucks (relpath-box1, relpath-box2, relpath-box3, relpath-primary, relpath-gallery1, relpath-gallery2, relpath-gallery3, year, make, model, miles, comment, option1, option2, option3, option4, option5, option6, option7, option8) VALUES (".$data[0].", ".$data[1].", ".$data[2].", ".$data[3].", ".$data[4].", ".$data[5].", ".$data[6].", ".$data[7].", ".$year.", ".$make.", ".$model.", ".$miles.", ".$comment.", ".$option1.", ".$option2.", ".$option3.", ".$option4.", ".$option5.", ".$option6.", ".$option7.", ".$option8.")";
  16.  
  17.  
  18. mysql_query($sql);


  1. -- phpMyAdmin SQL Dump
  2. -- version 2.9.1.1
  3. -- [url]http://www.phpmyadmin.net[/url]
  4. --
  5. -- Host: ------------
  6. -- Generation Time: May 13, 2008 at 08:48 PM
  7. -- Server version: 5.0.45
  8. -- PHP Version: 4.4.4
  9. --
  10. -- Database: `--------`
  11. --
  12.  
  13. -- --------------------------------------------------------
  14.  
  15. --
  16. -- Table structure for table `trucks`
  17. --
  18.  
  19. CREATE TABLE `trucks` (
  20. `id` int(4) NOT NULL AUTO_INCREMENT,
  21. `relpath-box1` varchar(255) NOT NULL,
  22. `relpath-box2` varchar(255) NOT NULL,
  23. `relpath-box3` varchar(255) NOT NULL,
  24. `relpath-box4` varchar(255) NOT NULL,
  25. `relpath-primary` varchar(255) NOT NULL,
  26. `relpath-gallery1` varchar(255) NOT NULL,
  27. `relpath-gallery2` varchar(255) NOT NULL,
  28. `relpath-gallery3` varchar(255) NOT NULL,
  29. `year` int(4) NOT NULL,
  30. `make` varchar(255) NOT NULL,
  31. `model` varchar(255) NOT NULL,
  32. `miles` varchar(255) NOT NULL,
  33. `comment` varchar(255) NOT NULL,
  34. `option1` varchar(255) NOT NULL,
  35. `option2` varchar(255) NOT NULL,
  36. `option3` varchar(255) NOT NULL,
  37. `option4` varchar(255) NOT NULL,
  38. `option5` varchar(255) NOT NULL,
  39. `option6` varchar(255) NOT NULL,
  40. `option7` varchar(255) NOT NULL,
  41. `option8` varchar(255) NOT NULL,
  42. PRIMARY KEY (`id`),
  43. KEY `id` (`id`)
  44. ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;
Last edited by peter_budo : May 14th, 2008 at 1:25 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Please help

  #4  
May 14th, 2008
Umm.. I think you didn't get what I said.. Try wrapping the values in single quote.
  1. $sql = "insert into table (column1,column2) values ('test1',''test2')";
Notice the values within quotes.
Last edited by nav33n : May 14th, 2008 at 5:29 am.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jul 2006
Posts: 158
Reputation: tefflox is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Please help

  #5  
May 14th, 2008
So the db schema looks right? No offense, but I worked on that sql string for hours. If your suggestions works, I will make sure to come back and make you king.
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Please help

  #6  
May 14th, 2008
Yep. The whole structure is fine.. Well, If you want, you can try out this simple example. Print $sql and execute it in mysql console. Also, try with mysql_query($query) or die (mysql_error()); You will know why the query failed.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Jul 2006
Posts: 158
Reputation: tefflox is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Please help

  #7  
May 14th, 2008
This....

  1. $sql = "INSERT INTO trucks (relpath-box1, relpath-box2, relpath-box3, relpath-primary, relpath-gallery1, relpath-gallery2, relpath-gallery3, year, make, model, miles, comment, option1, option2, option3, option4, option5, option6, option7, option8) VALUES ('data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$year', '$make', '$model', '$miles', '$comment', '$option1', '$option2', '$option3', '$option4', '$option5', '$option6', '$option7', '$option8')"; mysql_query($sql);


Does not work. Please note that I'm not doing anything with `id`

I will try your timely suggestions. you've saved me from farther anger......
Last edited by peter_budo : May 14th, 2008 at 1:26 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Jul 2006
Posts: 158
Reputation: tefflox is an unknown quantity at this point 
Rep Power: 3
Solved Threads: 0
tefflox's Avatar
tefflox tefflox is offline Offline
Junior Poster

Re: Please help

  #8  
May 14th, 2008
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-box1, relpath-box2, relpath-box3, relpath-primary, relpath-gallery1, relpath-ga' at line 1


I appreciate your patience. Again, the query..

  1. $sql = "INSERT INTO trucks (relpath-box1, relpath-box2, relpath-box3, relpath-primary, relpath-gallery1, relpath-gallery2, relpath-gallery3, year, make, model, miles, comment, option1, option2, option3, option4, option5, option6, option7, option8) VALUES ('data[0]', '$data[1]', '$data[2]', '$data[3]', '$data[4]', '$data[5]', '$data[6]', '$data[7]', '$year', '$make', '$model', '$miles', '$comment', '$option1', '$option2', '$option3', '$option4', '$option5', '$option6', '$option7', '$option8')";
Last edited by peter_budo : May 14th, 2008 at 1:27 pm. Reason: Keep It Organized - please use [code] tags
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Please help

  #9  
May 14th, 2008
umm.. It has to.. I could see few errors. First one is, the column count is 20 and the values you are trying to insert is 21. second error is, first value should be $data[0] instead of data[0]
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,098
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 240
nav33n's Avatar
nav33n nav33n is offline Offline
Posting Sensei

Re: Please help

  #10  
May 14th, 2008
Oh, and one more thing.. As far as I know, Its not a good practice to use - (hyphen) with names of the columns. Use underscore instead. You can use `` to mention the column name. For example,
  1. $sql = "INSERT INTO trucks (`relpath-box1`, `relpath-box2`, `relpath-box3`, `relpath-primary`) values ('$value1','$value2','$value3','$value4')";
This has to work..
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb MySQL Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Other Threads in the MySQL Forum

All times are GMT -4. The time now is 3:20 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC