Jump to content

sql query


proning

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/52574-sql-query/
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259409
Share on other sites

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;

?>

Link to comment
https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259414
Share on other sites

"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).

Link to comment
https://forums.phpfreaks.com/topic/52574-sql-query/#findComment-259418
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.