Inserting data into mysql with php

I need to alter the code below to add some ‘hidden’ data. The hidden data would be automatically pulled from a table based on the admin’s login. This data could be a store name, zip code, web address, etc. I don’t want the admin to have to add this every time he completes the html form that links to the code below. I want the data to be pulled from a table associated with the admin’s id number, for example.

How and where would I add the code for this ‘hidden’ data? Using the html form (auto-filled) or in the actual insert code below? Thanks in advance for process thoughts and code thoughts.

[php]<?php
$catid=$_POST[‘catid’];
$description=$_POST[‘description’];
$price=$_POST[‘price’];
$quantity=$_POST[‘quantity’];
$restname=$_POST[‘custname’];
$restphone=$_POST[‘custphone’];

if (get_magic_quotes_gpc())
{
$catid = stripslashes($catid);
$description = stripslashes($description);
$price = stripslashes($price);
$quantity = stripslashes($quantity);
$restname = stripslashes($custname);
$restname = stripslashes($custphone);

}
$catid = mysql_real_escape_string($catid);
$description = mysql_real_escape_string($description);
$price = mysql_real_escape_string($price);
$quantity = mysql_real_escape_string($quantity);
$restname = mysql_real_escape_string($custname);
$restphone = mysql_real_escape_string($custphone);

$thumbnail = getThumb($_FILES[‘picture’]);
$thumbnail = mysql_real_escape_string($thumbnail);

$query = “INSERT INTO products (catid, description, picture, price, quantity, custname, custphone) " .
" VALUES (’$catid’,’$description’,’$thumbnail’, ‘$price’, ‘$quantity’, ‘$custname’, '$custphone)”;

$result = mysql_query($query) or die(‘Unable to add product’);
if ($result)
echo “

New product added

\n”;
else
echo “

Problem adding new product

\n”;
?> [/php]

Inserted this code into the html form page but it does not pull the store name and autopopulate into the form…to give you an idea of what I’m trying to do.

[php] $query=“SELECT custid from admins where adminid=adminid”;
$result=mysql_query($query);
$custid = $row[‘custid’];

echo “

Store Name\n”;
echo “<select name=“custname”>\n”;

$query2=“SELECT custname from customers where custid=custid”;
$result=mysql_query($query2);

{
$custname = $row[‘custname’];
echo “<option value=”$custname">$custname\n";[/php]

Well, you are doing the query’s and they look okay.

You use the $row, but, did not set them up to pull the data from the query’s, so no data is available.

You should do something like this:

$query=“SELECT blah blah”
$result=mysql_query($query);
$row = mysql_fetch_row($result)
OR
$row = mysql_fetch_array($result)

Depends weather you want to use $row[1],$row[2]… or $row[‘custid’],$row[‘custname’]…
Good luck…

I’ll give it a try. Thanks ErnieAlex.

Sponsor our Newsletter | Privacy Policy | Terms of Service