lill77 Posted November 24, 2008 Share Posted November 24, 2008 Hello i'm trying to teach myself PHP I have the following error code when trying to add a product into mysql database form new-product.php 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 ') VALUES ( '', '', 'size', '' , 'noimage.png', 'noimage_big.png', )' at line 1 Any ideas please my code is below?? Thanks <?php include 'db.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "INSERT INTO `products` (`category_id` , `title` , `size` , `description` , `image` , `imageenlarge` ,) VALUES ( '', '', 'size', '' , 'noimage.png', 'noimage_big.png', );"; $sql_query = mysql_query($sql) or die (mysql_error()); $sql = "SELECT LAST_INSERT_ID()"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $product_id = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?page=edit-product.php&product=<? echo $product_id; ?>'> <p align="center" class="smalltext style2 style1">Saving Changes</p> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 first, next time you post something, please try to use a more descriptive title. second, when posting code, use code tags. it's the button on the toolbar with the # symbol That error is from the extra comas in the SQL query. Try this instead: $sql = "INSERT INTO `products` (`category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ( '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Ok I will do totally new to the forum . . . Thanks ps that seems to of worked apart form i now have the below Error in query: SELECT * FROM `Products` WHERE `ID` = '2'. Table 'characte_characterworld.Products' doesn't exist Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 Are you sure there is a table named Products in your database? How do you manage your database...phpMyAdmin? Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Hello yes i use phpMyAdmin an have MYSQL table called products . . . does case sensitive matter ??? it s lowercase as below products. i have attached a jpg Thanks [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
chrissie18 Posted November 24, 2008 Share Posted November 24, 2008 maybe you can try this: $sql = "INSERT INTO `products` (``, `category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ('', '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 the capital P shouldn't matter, but i would try with all lower case just to make sure. the following won't work...you can't have an empty field like that in the list of fields to insert into. maybe you can try this: $sql = "INSERT INTO `products` (``, `category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ('', '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; Quote Link to comment Share on other sites More sharing options...
chrissie18 Posted November 24, 2008 Share Posted November 24, 2008 i know it was bit wrong but i noticed something with the VALUES it was ( '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; think that`s not good space before the ( ? think it need to be: ('', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 24, 2008 Share Posted November 24, 2008 If your operating system is case-sensitive for file names, then database and table names are case-sensitive. Also, be consistent, you were using products in your INSERT query, use the same in your SELECT query. Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 24, 2008 Share Posted November 24, 2008 The OP got the INSERT query working and is current having a problem with an SELECT query and the table name. Stop guessing about how an INSERT query should be if you don't know. Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Hello thanks I used the below and go the message Unknown column '' in 'field list' im guessing that its the info between the '' ?? My first line in products is ID should that hav a default number give ?? Rich Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 24, 2008 Share Posted November 24, 2008 Posting the code that corresponds to the error would help someone to be able to help you. Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Sorry am new to this here you go ? Thanks <?php include 'db.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "INSERT INTO `products` (``, `category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ( '' , '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; $sql_query = mysql_query($sql) or die (mysql_error()); $sql = "SELECT LAST_INSERT_ID()"; $result = mysql_query($sql); $row = mysql_fetch_row($result); $product_id = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?page=edit-product.php&product=<? echo $product_id; ?>'> <p align="center" class="smalltext style2 style1">Saving Changes</p> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 again, please use CODE tags try this: <?php include 'db.php'; // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql = "INSERT INTO `products` (`category_id` , `title` , `size` , `description` , `image` , `imageenlarge`) VALUES ( '', '', 'size', '' , 'noimage.png', 'noimage_big.png');"; $reult = mysql_query($sql) or die (mysql_error()); $product_id = mysql_insert_id(); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT='0; URL=index.php?page=edit-product.php&product=<? echo $product_id; ?>'> <p align="center" class="smalltext style2 style1">Saving Changes</p> Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Hello getting this error Error in query: SELECT * FROM `Products` WHERE `ID` = '3'. Table 'characte_characterworld.Products' doesn't exist Could it because of the code on my products.php page as below <? include 'db.php' ?> <?php // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); if ($sort ==""){ $sort = "title"; } // create query $query = "SELECT * FROM products, category WHERE category_id = category.ID ORDER BY $sort ASC"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another echo "<table align =center border=1 width=800 id=table1 cellspacing=2 cellpadding=2 style=border-collapse: collapse >"; echo "<tr>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'> <a href='index.php?sort=productID'>ID</a> </font></b></td>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'> <a href='index.php?sort=category_id'> Category </a></font></b></td>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'> <a href='index.php?sort=title'> title </a></font></b></td>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'> <a href='index.php?sort=size'> size </a></font></b></td>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'> <a href='index.php?sort=description'> description </a> </font></b></td>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'></font></b></td>"; echo "<td bgcolor='#6699FF'><b><font face='Arial' color='#FFFFFF'></font></b></td>"; echo "</tr>"; while($row = mysql_fetch_row($result)) { echo "<tr border=0>"; echo "<td>".$row[0]."</td>"; // id echo "<td>".$row[2]."</td>"; // title echo "<td>".$row[1]."</td>"; // title echo "<td>".$row[3]."</td>"; // size echo "<td>".substr($row[3], 0, 30)."...</td>"; // description echo "<td>".$row[7]."</td>"; // echo "<td><a href='?page=edit-product.php&product=$row[0]'>Edit</a></td>"; // echo "<td align = 'centre'><a href='delete-product.php?id=$row[0]' onclick='return log_out()'>Delete</a></td>"; echo "</tr>"; } echo "</table>"; } else { // no // print status message echo "<p align='center'><font color='#808080' face='Arial'>No records found.</font></p>"; } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 can you post the full error, with the filename and line number the error is occurring on Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Hello sorry do you mean form mysql the error im getting is when im trying to add a product into my database using admin/index.php?page=edit-product.php&product=3 the error is http://www.characterworld.uk.com/test/admin/index.php?page=edit-product.php&product=3 Regards Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 Your INSERT page seems to work fine. It then forwards them to the 'edit-product' page. Is this the expected result? What is the contents of edit-product.php? Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Here you go, yes i think so !! <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <? include 'db.php' ?> <script language="javascript" type="text/javascript"><!-- function popupWindow(url, width, height) { if(width == null){ width =450; } if(height == null){height =150;} window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,copyhistory=no,width='+width+',height='+height+',screenX=150,screenY=150,top=150,left=100') } //--></script> <script> function log_out() { return confirm('Are you sure you want to Delete this article?'); } </script> <?php // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `Products` WHERE `ID` = '".$_REQUEST['product']."'"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); $row = mysql_fetch_row($result); $CurrentProduct = $row[0]; // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> <body> <form method="GET" action="update-product.php"> <div align="center"> <table width="505" border="0" cellpadding="2" cellspacing="2" bordercolor="#FFFFFF" bordercolorlight="#C0C0C0" bordercolordark="#C0C0C0" id="table1"> <tr> <td width="130" align="right"><b> <font face="Arial" size="2" color="#808080">Product ID:</font></b></td> <td width="228" align="center"> <p align="left"> <? echo "$row[0]" ?> <input name="ID" type="hidden" id="ID" value="<? echo "$row[0]" ?>" /> </p> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b> <font face="Arial" size="2" color="#808080">Title:</font></b></td> <td align="center"> <div align="left"> <input type="text" name="title" size="36" value="<? echo "$row[2]" ?>" ?> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"><div align="right"><b><font face="Arial" size="2" color="#808080">Sizes </font></b></div></td> <td align="center"><div align="left"> <input type="text" name="size" size="36" value="<? echo "$row[3]" ?>" ? /><br /> (Format: <b>Small/Medium/Large</b>) </div></td> <td width="127"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Description:</font></b></td> <td align="center"><div align="left"> <textarea name="description" cols="50" rows="10" id="description"><? echo "$row[4]" ?></textarea> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Category:</font></b></td> <td align="center"><div align="left"> <p> </p> <p><select name="category_id" id="category_id"> <?php $currentcat = $row[4]; // set database server access variables: // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); // create query $query = "SELECT * FROM `Category`;"; // execute query $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); // see if any rows were returned if (mysql_num_rows($result) > 0) { // yes // print them one after another while($row = mysql_fetch_row($result)) { echo "<option value=\"".$row[0]."\""; if ($row[0]==$currentcat) {echo " Selected";}; echo ">$row[1]</option>"; } } // free result set memory mysql_free_result($result); // close connection mysql_close($connection); ?> </select> </p> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"><b><font face="Arial" size="2" color="#808080">Image:</font></b></td> <td align="center"><div align="left"> <select name="image" id="image"> <option value="noimage.png">No Image</option> <?php if ($handle = opendir('../productimages/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $page_name = $file; //$page_name=substr($file, 0, strpos($file, ".")); echo "<option"; if($page_name==$row[4]){echo ' selected';}; echo ">$page_name</option>"; } } } closedir($handle); ?> </select> </div></td> <td width="127" align="right"> </td> </tr> <tr> <td align="right"><b><font face="Arial" size="2" color="#808080">Enlarge Image:</font></b></td> <td align="center"><div align="left"> <select name="imageenlarge" id="imageenlarge"> <option value="noimage.png">No Image</option> <?php if ($handle = opendir('../productimages/')) { while (false !== ($file = readdir($handle))) { if ($file != "." && $file != "..") { $page_name = $file; //$page_name=substr($file, 0, strpos($file, ".")); echo "<option"; if($page_name==$row[5]){echo ' selected';}; echo ">$page_name</option>"; } } } closedir($handle); ?> </select> </div></td> <td align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"><div align="left"></div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"> </td> <td align="center"><div align="left"></div></td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130" align="right"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td width="130"> </td> <td align="center"> </td> <td width="127" align="right"> </td> </tr> <tr> <td> </td> <td align="center"> </td> <td> </td> </tr> </table> </div> <p align="center"><input type="submit" value="Save" name="B1"> <input type="reset" value="Close" name="B2" onclick="history.back()"> </p> </form> </p> <p align="center"> </p> </body> </html> Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted November 24, 2008 Share Posted November 24, 2008 You already had that error a couple of hours ago and were told to use all lowercase products for your table name because it will be case-sensitive if your operating system is case-sensitive (which given the error, likely is.) Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 You already had that error a couple of hours ago and were told to use all lowercase products for your table name because it will be case-sensitive if your operating system is case-sensitive. yeah, change $query = "SELECT * FROM `Products` WHERE `ID` = '".$_REQUEST['product']."'"; to $query = "SELECT * FROM `products` WHERE `ID` = '".$_REQUEST['product']."'"; p.s. - thanks for using code tags Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Great thanks for your help im on my way now. Thanks Rich Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 Hello not quite there yet ? Im getting the follwoing error on page when I save the product Parse error: syntax error, unexpected ')', expecting ']' in /home/characte/public_html/test/admin/update-product.php on line 15 code below on update product page <? include 'db.php' ?> <? // open connection $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!"); // select database mysql_select_db($db) or die ("Unable to select database!"); $sql_query = mysql_query("UPDATE `products` SET `title` = '".$_REQUEST['title']."', `size` = '".$_REQUEST['size']."', `description` = '".$_REQUEST['description']."', `category_id` = ".$_REQUEST['category_id'].", `Image` = '".$_REQUEST['image']."', `Imageenlarge` = '".$_REQUEST['imageenlarge') or die (mysql_error()); // close connection mysql_close($connection); ?> <META HTTP-EQUIV=Refresh CONTENT="0; URL=index.php?page=products.php"> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted November 24, 2008 Share Posted November 24, 2008 `Imageenlarge` = '".$_REQUEST['imageenlarge') or die (mysql_error()); should be `Imageenlarge` = '".$_REQUEST['imageenlarge']."'") or die (mysql_error()); Quote Link to comment Share on other sites More sharing options...
lill77 Posted November 24, 2008 Author Share Posted November 24, 2008 thanks for your help ! Rich Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.