Click here to Skip to main content
14,420,861 members
Rate this:
Please Sign up or sign in to vote.
See more:
I have a little problem. I found a picture upload script and edited it. But mysql query_insert_id() is not work.


main_db have 5 table.

a - b - Jant - d - e

i need table Jant's last id. How can make it ?




<pre lang="xml"><?php<br />
<br />
<br />
 ini_set("memory_limit", "200000000"); // for large images so that we do not get "Allowed memory exhausted"?><br />
<?php<br />
// upload the file<br />
if ((isset($_POST["submitted_form"])) && ($_POST["submitted_form"] == "image_upload_form")) {<br />
<br />
    // file needs to be jpg,gif,bmp,x-png and 4 MB max<br />
    if (($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg" || $_FILES["image_upload_box"]["type"] == "image/gif" || $_FILES["image_upload_box"]["type"] == "image/x-png") && ($_FILES["image_upload_box"]["size"] < 4000000))<br />
    {<br />
<br />
<br />
        // some settings<br />
        $max_upload_width = 4000;<br />
        $max_upload_height = 3000;<br />
<br />
        // if user chosed properly then scale down the image according to user preferances<br />
        if(isset($_REQUEST['max_width_box']) and $_REQUEST['max_width_box']!='' and $_REQUEST['max_width_box']<=$max_upload_width){<br />
            $max_upload_width = $_REQUEST['max_width_box'];<br />
        }<br />
        if(isset($_REQUEST['max_height_box']) and $_REQUEST['max_height_box']!='' and $_REQUEST['max_height_box']<=$max_upload_height){<br />
            $max_upload_height = $_REQUEST['max_height_box'];<br />
        }<br />
<br />
<br />
        // if uploaded image was JPG/JPEG<br />
        if($_FILES["image_upload_box"]["type"] == "image/jpeg" || $_FILES["image_upload_box"]["type"] == "image/pjpeg"){<br />
            $image_source = imagecreatefromjpeg($_FILES["image_upload_box"]["tmp_name"]);<br />
        }<br />
        // if uploaded image was GIF<br />
        if($_FILES["image_upload_box"]["type"] == "image/gif"){<br />
            $image_source = imagecreatefromgif($_FILES["image_upload_box"]["tmp_name"]);<br />
        }<br />
        // BMP doesn't seem to be supported so remove it form above image type test (reject bmps)<br />
        // if uploaded image was BMP<br />
        if($_FILES["image_upload_box"]["type"] == "image/bmp"){<br />
            $image_source = imagecreatefromwbmp($_FILES["image_upload_box"]["tmp_name"]);<br />
        }<br />
        // if uploaded image was PNG<br />
        if($_FILES["image_upload_box"]["type"] == "image/x-png"){<br />
            $image_source = imagecreatefrompng($_FILES["image_upload_box"]["tmp_name"]);<br />
        }<br />
<br />
<br />
        $deger=rand(10000,99999);<br />
$remote_file = "image_files/".$deger.$_FILES["image_upload_box"]["name"];<br />
<br />
<br />
        imagejpeg($image_source,$remote_file,100);<br />
        chmod($remote_file,0644);<br />
<br />
<br />
<br />
        // get width and height of original image<br />
        list($image_width, $image_height) = getimagesize($remote_file);<br />
<br />
        if($image_width>$max_upload_width || $image_height >$max_upload_height){<br />
            $proportions = $image_width/$image_height;<br />
<br />
            if($image_width>$image_height){<br />
                $new_width = $max_upload_width;<br />
                $new_height = round($max_upload_width/$proportions);<br />
            }<br />
            else{<br />
                $new_height = $max_upload_height;<br />
                $new_width = round($max_upload_height*$proportions);<br />
            }<br />
<br />
<br />
            $new_image = imagecreatetruecolor($new_width , $new_height);<br />
            $image_source = imagecreatefromjpeg($remote_file);<br />
<br />
            imagecopyresampled($new_image, $image_source, 0, 0, 0, 0, $new_width, $new_height, $image_width, $image_height);<br />
            imagejpeg($new_image,$remote_file,100);<br />
<br />
            imagedestroy($new_image);<br />
        }<br />
<br />
        imagedestroy($image_source);<br />
<br />
<br />
        header("Location: submit.php?upload_message=image uploaded&upload_message_type=success&show_image=".$deger.$_FILES["image_upload_box"]["name"]);<br />
        exit;<br />
    }<br />
    else{<br />
        header("Location: submit.php?upload_message=make sure the file is jpg, gif or png and that is smaller than 4MB&upload_message_type=error");<br />
        exit;<br />
    }<br />
}<br />
?><br />
<br />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><br />
<html xmlns="http://www.w3.org/1999/xhtml"><br />
<head><br />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><br />
<title>Image Upload with resize</title><br />
<style type="text/css"><br />
<!--<br />
body,td,th {<br />
    font-family: Arial, Helvetica, sans-serif;<br />
    color: #333333;<br />
    font-size: 12px;<br />
}<br />
<br />
.upload_message_success {<br />
    padding:4px;<br />
    background-color:#009900;<br />
    border:1px solid #006600;<br />
    color:#FFFFFF;<br />
    margin-top:10px;<br />
    margin-bottom:10px;<br />
}<br />
<br />
.upload_message_error {<br />
    padding:4px;<br />
    background-color:#CE0000;<br />
    border:1px solid #990000;<br />
    color:#FFFFFF;<br />
    margin-top:10px;<br />
    margin-bottom:10px;<br />
}<br />
<br />
--><br />
</style></head><br />
<br />
<body><br />
<br />
<h1 style="margin-bottom: 0px">Resim ekleme</h1><br />
<br />
<br />
        <?php if(isset($_REQUEST['upload_message'])){?><br />
            <div class="upload_message_<?php echo $_REQUEST['upload_message_type'];?>"><br />
            <?php echo htmlentities($_REQUEST['upload_message']);?><br />
            </div><br />
        <?php }?><br />
<br />
<br />
<form action="submit.php" method="post" enctype="multipart/form-data" name="image_upload_form" id="image_upload_form" style="margin-bottom:0px;"><br />
<label>Image file, maximum 4MB. it can be jpg, gif,  png:</label><br /><br />
          <input name="image_upload_box" type="file" id="image_upload_box" size="40" /><br />
          <input type="submit" name="submit" value="Upload image" /><br />
<br />
     <br /><br />
    <br /><br />
<br /><br />
      <input name="max_width_box" type="text" id="max_width_box" value="130" size="4"><br />
      x<br />
<br />
      <input name="max_height_box" type="text" id="max_height_box" value="130" size="4"><br />
      px.<br />
       // Bu kısmı gerekmediği sürece 130 x 130 olarak bırakınız !<br /><br />
  <br /><br />
<input name="submitted_form" type="hidden" id="submitted_form" value="image_upload_form" /><br />
          </form><br />
<br />
<br />
<br />
<br />
<?php if(isset($_REQUEST['show_image']) and $_REQUEST['show_image']!=''){?><br />
<p><br />
    <img src="image_files/<?php echo $_REQUEST['show_image'];?>" /><br />
</p><br />
<?php }<br />
<br />
 echo $_REQUEST['show_image'];<br />
<br />
mysql_connect('localhost','admin','password');<br />
mysql_select_db('main_db');<br />
<br />
<br />
<br />
$sql = mysql_query("SHOW TABLE STATUS LIKE 'Jant'");<br />
<br />
echo mysql_query_insert_id();<br />
<br />
?><br />
<br />
<br />
<br />
<br />
</body><br />
</html></pre><br />
Posted

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

mysql_insert_id[^] only works with INSERT statement and auto inc on table column.

And the only SQL statement is SHOW TABLE.
   
v2
Comments
kozmikadam 5-Jun-11 14:49pm
   
i understand. But i need last id.How can i find it ?
Kim Togo 6-Jun-11 3:10am
   
You can do a "SELECT MAX(id) FROM tbl", this way MySql will find the maximum value in the table "tbl"
kozmikadam 6-Jun-11 6:27am
   
$last_id = mysql_query("SELECT MAX(ID) FROM Jant"
echo $last_id

always return me "Resource id #3"
Kim Togo 6-Jun-11 6:28am
   
Can you please describe the table "Jant" ?
Kim Togo 6-Jun-11 6:48am
   
You are accessing the result incorrect.
Check this link
http://www.w3schools.com/php/func_mysql_fetch_array.asp
kozmikadam 6-Jun-11 7:14am
   
$sql = mysql_query("SELECT * from Jant ORDER BY ID DESC LIMIT 1;");

$goster=mysql_fetch_array($sql);
echo $goster['ID'];


Problem solved ! Thanks for your help.
Kim Togo 6-Jun-11 7:17am
   
You are welcome :-)
Please use "Accept Answer" and vote the solution. This will help other CP members to find answers to problems.
kozmikadam 6-Jun-11 6:32am
   
Table Jant :

ID - Name - type - marka

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100