proning Posted May 22, 2007 Share Posted May 22, 2007 ok well i got to make this site for my dad and it needs an admin pannel im not the best php coder in the world actualy i kinda sux so im asking for some advise i need to push the submit button and it actualy update the sql data base using insert but its not insrtinh any data hers my code hope you can help <fieldset> <legend>Add New Product</legend> <form action="" method="post" enctype="multipart/form-data"> <table width="814" border="0"> <tr> <td colspan="3"></td> </tr> <tr > <td>Name :</td> <td colspan="2">Price :</td> </tr> <tr > <td width="350"> <label> <input type="text" name="product_name" id="product_name" /> </label></td> <td colspan="2"><input type="text" name="product_price" id="product_price" /></td> </tr> <tr> <td>Description :</td> <td height="21" colspan="2"> <label> <textarea name="product_desc" id="product_desc" cols="45" rows="5"></textarea> </label></td> </tr> <tr> <td>Picture :</td> <td width="350" height="21"><input type="file" name="upload" /></td> <td width="100"><input type="submit" name="submit" value="submit" /></td> </tr> <tr> <td colspan="3"></td> </tr> </table> </form> <? if(isset($_POST['submit'])) { $product_name = $_POST['product_name']; $product_price = $_POST['product_price']; $product_desc = $_POST['product_desc']; $query = $db->query("INSERT INTO small (name, price, desc) VALUES ('$product_name', '$product_price', '$product_desc')"); } else { } ?> </fieldset> Quote Link to comment https://forums.phpfreaks.com/topic/52574-sql-query/ Share on other sites More sharing options...
corbin Posted May 22, 2007 Share Posted May 22, 2007 Add INSERT INTO small (name, price, desc) VALUES ('$product_name', '$product_price', '$product_desc') Right after $query = $db->query("INSERT INTO small (name, price, desc) VALUES ('$product_name', '$product_price', '$product_desc')"); And post what it says please. Without seeing your $db class, I have no idea how the error handling works, but some how you need to do mysql_error and see what it's throwing at you (assuming you're using mysql). That's why I want you to echo out the insert.... That way I can see if one of the variables is incorrect or something. ;p Quote Link to comment https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259409 Share on other sites More sharing options...
proning Posted May 22, 2007 Author Share Posted May 22, 2007 ok code now like this <? if(isset($_POST['submit'])) { $product_name = $_POST['product_name']; $product_price = $_POST['product_price']; $product_desc = $_POST['product_desc']; $query = $db->query("INSERT INTO small (name, price, desc) VALUES ('$product_name', '$product_price', '$product_desc')"); INSERT INTO small (name, price, desc) VALUES ('$product_name', '$product_price', '$product_desc'); } else { } ?> and error was Parse error: syntax error, unexpected T_STRING in /home/spamoom/public_html/patrice/admin/inc/small.php on line 43 my $db class is from this not wrote by me i dont understand half of it <? /* +--------------------------------------------------+ | sql.php +--------------------------------------------------+ | Written by Sam 'SpamooM' Jordan | Copyright (c) 2005-2007 SpamooM.net | www.SpamooM.net +--------------------------------------------------+ */ if (strstr($_SERVER['SCRIPT_NAME'], "sql.php")) { echo "Access Denied!"; die; } // This file is full of functions to make the sql work class db { function start ($server, $user, $pass, $db) { global $config; $connect = @mysql_connect($server, $user, $pass); if (!$connect) { echo "Error: Db->start Sql cannot connect"; die(); } $dbconnect = @mysql_select_db($db); if (!$dbconnect) { echo "Error: Db->start Sql cannot find db"; die(); } } function query ($sql) { if (!isset($sql)) { echo "Error: Db->query No sql set"; } else { $query = mysql_query($sql); RETURN $query; } } function fetch ($query) { if (!isset($query)) { echo "Error: Db->query No query given"; } else { $result = mysql_fetch_array($query); RETURN $result; } } function count ($query) { if (!isset($query)) { echo "Error: Db->cnt No query given"; } else { $result = mysql_num_rows($query); RETURN $result; } } } $db = new db; ?> Quote Link to comment https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259414 Share on other sites More sharing options...
corbin Posted May 22, 2007 Share Posted May 22, 2007 "and error was Parse error: syntax error, unexpected T_STRING in /home/spamoom/public_html/patrice/admin/inc/small.php on line 43" That error means that it's a parsing error for PHP (entirely unrelated to MySQL).... I would look around 43 for anything that could create a syntax error (an unclosed quote string, a missing ';', etc). Quote Link to comment https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259418 Share on other sites More sharing options...
proning Posted May 22, 2007 Author Share Posted May 22, 2007 ......i want to cry i cant find any thing lol it all runs fune just wont put it in the db btw forgot to say aearly sql script was given to me by my freind spam he alloud me to use it before any copy write stuff is an issue Quote Link to comment https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259422 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.