ok here is my code:
I have two tables in database recipes and cookie. i am trying to copy id from recipes and add to cookie for each row.
<?php
//connect to datatbase
$connect = mysql_connect("localhost","kosterb_jamaltag","jamaltag") or die (mysql_error());
mysql_select_db("kosterb_jamaltag") or die ("Could not find db") or die (mysql_error());
$uname = $_POST['membername'];
$cname = $_POST['cookiename'];
$ingDis = str_replace("%&%","'",$_POST['inge']);
$dirDis = str_replace("%&%","'",$_POST['dire']);
//New order
if(!isset($_SESSION['id']))
{
$query = "SELECT MAX(id) FROM Recipes";
$result = mysql_query( $query );
if($result==0)
{
echo "<b>Error ".mysql_errno().": ".mysql_error()."</b>";
}
else
{
$row = mysql_fetch_array ($result);
$id= $row[0]+1;
$_SESSION['id'] = $id;
$_SESSION['ingrediants'] = $ingDis;
$query="SELECT From Recipes WHERE
id='$id'";
$result=mysql_query($query);
if($result==0)
{
echo "<b>Error ".mysql_errno().": ".mysql_error()."</b>";
}
}
}
$id= $_SESSION['id'];
//mysql_query("SELECT FROM Recipes WHERE id='$id'");
//mysql_query("INSERT INTO Cookie VALUES( '','$id','$dirDis')");
$query="insert into Cookie SET "
." id='$id',membername='$uname', cookiename='$cname'";
if ($bug)
{
echo "=$query";
}
$result = mysql_query($query);
if($result==0)
{
echo "<b>Error ".mysql_errno().": ".mysql_error()."</b>";
}
// Get user/cookie name from Cookie table
mysql_query("SELECT * FROM Cookie WHERE membername='$uname' AND cookiename='$cname'" );
echo "<h1 style=text-align:\"center\"><font color=\"darkbrown\">$cname by $uname<br /></h1></font><br /><br />" ;
//grap file
$file = $_FILES['image']['tmp_name'];
if(!isset($file))
echo "please select an image";
else
{
$image=addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name = addslashes($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size==FALSE)
echo "That is not an image";
else
{
if(!$insert = mysql_query("INSERT INTO Cookie VALUES ('','','$image_name','$image','','')"))
echo "There is a problem uploading the image.";
else
{
$lastid = mysql_insert_id();
echo "<img src=get.php?id=$lastid width=\"300\" \> <br>";
}
}
}
// Insert Ingeriadiants to database
mysql_query("INSERT INTO Recipes VALUES( '','$ingDis','$dirDis')");
//Get discriptions from Ingrediants table
mysql_query("SELECT * FROM Recipes WHERE ingrediants='$inge' AND directions='$dire'");
echo nl2br("<p><h1><font color= \"green\">Ingrediants</font></h1>
$ingDis<br /> </>
<p><h1><font color= \"green\">Directions</font></h1>
$dirDis<br /></p>") ;
?>