Trying to create an image URL using information from form...

So I am making an auto parts site. I have my database setup and am creating the php processes to create the data in a mySQL database. So far, my form sucessfully submits data into my columns and I am using that data to populate various things on my site. I am stuck on something though…

I have a product entry page where you enter the following values:

[ul][li]brand[/li]
[li]category[/li]
[li]subCategory[/li]
[li]details[/li]
[li]sku[/li]
[li]variant[/li]
[li]minYear[/li]
[li]maxYear[/li]
[li]make[/li]
[li]model[/li]
[li]description[/li]
[li]specs[/li]
[li]msrp[/li]
[li]jobber[/li]
[li]price[/li]
[li]cost[/li]
[li]weight[/li]
[li]warehouse[/li][/ul]

The form action is input_part_data.php

In input_part_data.php, the values above are entered into my database table.
I created a column in that mySQL table called image. What I’m trying to do is use the info above to create imge URLs and have the URLs enter into my database. Please notice the form DOES NOT have a field to enter a value for the image column. I need to generate the URLs to enter into the ‘images’ COLUMN of my database.

My products’ images are saved in directories like this: b/products/company/images/sku.jpg[/b]

What I need is to take the $brand and $sku and (upon form submission) use those variable values to construct and store image URLs (like the one above) into the ‘image’ column of my database.

For example, if I enter the following product:
Brand: Magnaflow
…other info…
SKU: 12345
I need the URL ‘/products/Magnaflow/images/12345.jpg’ to be entered into that product’s ROW in the ‘image’ COLUMN of my database table so that I can use [php]<? echo $image ?>[/php] in the pages that product displays in.

I know I have repeated myself three times, I just don’t know how to clearly communicate my question.

In short, how do you use variables to construct a URL, like the one above, then submit the URL into the database?

Here is my “input_part_data.php” code:
[php]<?
$username=“avantweb_hpf”;
$password=“m3turbo”;
$database=“avantweb_hpf”;

$brand=$_POST[‘brand’];
$category=$_POST[‘category’];
$subCategory=$_POST[‘subCategory’];
$details=$_POST[‘details’];
$sku=$_POST[‘sku’];
$variant=$_POST[‘variant’];
$minYear=$_POST[‘minYear’];
$maxYear=$_POST[‘maxYear’];
$make=$_POST[‘make’];
$model=$_POST[‘model’];
$description=$_POST[‘description’];
$specs=$_POST[‘specs’];
$msrp=$_POST[‘msrp’];
$jobber=$_POST[‘jobber’];
$price=$_POST[‘price’];
$cost=$_POST[‘cost’];
$weight=$_POST[‘weight’];
$warehouse=$_POST[‘warehouse’];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);

$query = “INSERT INTO products VALUES (’$brand’,’$category’,’$subCategory’,’$details’,’$sku’,’$variant’,’$minYear’,’$maxYear’,’$make’,’$model’,’’,’$description’,’$specs’,’$msrp’,’$jobber’,’$price’,’$cost’,’$weight’,’$warehouse’,’’)”;
mysql_query($query);

mysql_close();

echo “Product entered successfully…

<a href=“javascript:javascript:history.go(-1)”>Add Another”;

function imgUrl()
{
echo "/

?>[/php]

Thanks in advance!

Would I insert the following into the input_part_data.php:

Guess 1:
[php]$image=("/products/"."$brand"."/images/"."$sku".".jpg")[/php]
or Guess 2:
[php]$image = “/products/$brand/images/$sku.jpg”[/php]

:smiley: Got it eventually. Posting in-case someone comes across this in the future…

[php]$image = “products/”.$brand."/img/".$sku.".jpg";[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service