Laaveem Posted October 14, 2015 Share Posted October 14, 2015 Hello everyone, i have a problem I can't quite figure out. I have a php page where users can, via a form, register thier infos which are stored in a sql database. In order to easily keep track of every new submission, i've set up a system which mails me the data posted in the DB each time the form is sent. The problem comes when i want to obtain the link where is stored an image the users can add to the form. each time a new user adds the data to the DB, the image attached is stored in a newly created folder which gets as name the ID of the new DB entry. This piece of code is supposed to write down the complete URL where I can find said image. It actually is not a problem for me to get the image via FTP, but this would simply make things easier. It works flawlessly, but when it comes to print out the last ID in said database i'm stuck. $message.= "http://mysite.comt/img/ //can't figure this part out /{$_FILES['Logo']['name']}<br/><br/>"; Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/298589-last-inserted-id-in-a-string/ Share on other sites More sharing options...
requinix Posted October 14, 2015 Share Posted October 14, 2015 But didn't you get that ID when you put the image in the folder? What's the rest of your code? Particularly the bits that involve the database. Quote Link to comment https://forums.phpfreaks.com/topic/298589-last-inserted-id-in-a-string/#findComment-1523262 Share on other sites More sharing options...
Laaveem Posted October 14, 2015 Author Share Posted October 14, 2015 (edited) <?php if (empty($_POST['NumeroDipendenti'])) $_POST['NumeroDipendenti'] = 0; $messaggio_conferma = false; if (isset($_POST['register_btn'])) { unset($_POST['register_btn']); $_POST['Attiva'] = 0; $_POST['NumeroDipendenti'] = intval($_POST['NumeroDipendenti']); $_POST['Logo'] = ''; $comma = ""; $sql = "INSERT INTO tblAziende ("; $sql .= implode(",", array_keys($_POST)); $sql .= ") VALUES ("; foreach ($_POST as $key => $val) { $sql .= $comma . "?"; $comma = ","; $array_valori[] = stripslashes(utf8_decode($val)); } $sql .= ")"; $query = $db->prepare($sql); if ($query->execute($array_valori)) { $messaggio_conferma = true; $dest = 'mail@mail.com'; $subject = "BSD Torino: Iscrizione Azienda"; $message = "<strong>Referente:</strong><br/>"; $message .= "{$_POST['Partecipante']}<br/><br/>"; $message .= "<strong>Ragione Sociale:</strong><br/>"; $message .= "{$_POST['RagioneSociale']}<br/><br/>"; $message .= "<strong>Indirizzo:</strong><br/>"; $message .= "{$_POST['Indirizzo']}<br/><br/>"; $message .= "<strong>Cap:</strong><br/>"; $message .= "{$_POST['Cap']}<br/><br/>"; $message .= "<strong>Città:</strong><br/>"; $message .= "{$_POST['Citta']}<br/><br/>"; $message .= "<strong>Telefono:</strong><br/>"; $message .= "{$_POST['Telefono']}<br/><br/>"; // Ex campo FAX $message .= "<strong>Partita IVA:</strong><br/>"; $message .= "{$_POST['Fax']}<br/><br/>"; $message .= "<strong>Email:</strong><br/>"; $message .= "{$_POST['Mail']}<br/><br/>"; $message .= "<strong>Indirizzo web:</strong><br/>"; $message .= "{$_POST['Sito']}<br/><br/>"; $message .= "<strong>Settore merceologico:</strong><br/>"; $message .= "{$_POST['SettoreMerceologico']}<br/><br/>"; $message .= "<strong>Numero di dipendenti:</strong><br/>"; $message .= "{$_POST['NumeroDipendenti']}<br/><br/>"; $message .= "<strong>Descrizione attività:</strong><br/>"; $message .= "{$_POST['Descrizione']}<br/><br/>"; $message .= "<strong>Tipologia prodotti/servizi offerti:</strong><br/>"; $message .= "{$_POST['ProdottiServizi']}<br/><br/>"; $message .= "<strong>Logo</strong><br/>"; $message .= "http://demo.bsdtorino.it/wp-content/themes/fontfolio/img/ {echo last_insert_id} /{$_FILES['Logo']['name']}<br/><br/>"; $headers = "From: BSD Torino <email>\r\n"; $headers .= "Reply-To: email\r\n"; add_filter('wp_mail_content_type', create_function('', 'return "text/html"; ')); wp_mail($dest, $subject, $message, $headers); } else { $errore = $db->errorInfo(); //echo "<pre>"; echo $errore[2]; echo "</pre>"; } $sql = "SELECT * FROM tblAziende ORDER BY ID DESC"; $result = $db->query($sql); $rowTemp = $result->fetch(); if (isset($_FILES['Logo']['name'])) { $_FILES['Logo']['name'] = str_replace(array( "'", '"', "&" ), "", $_FILES['Logo']['name']); $_FILES['Logo']['name'] = str_replace(" ", "-", $_FILES['Logo']['name']); $idTemp = $rowTemp['ID']; $img_root = get_theme_root() . "/fontfolio/img/{$idTemp}/"; $array_immagini = array( 'image/jpeg' => true, 'image/png' => true, 'image/gif' => true ); if (isset($array_immagini[$_FILES['Logo']['type']])) { if (!file_exists($img_root)) { mkdir($img_root); //echo "Creo la cartella: " . $img_root; } if (move_uploaded_file($_FILES['Logo']['tmp_name'], $img_root . $_FILES['Logo']['name'])) { echo "<pre>"; print_r($_FILES); echo "</pre>"; $filename = $img_root . $_FILES['Logo']['name']; // Get new sizes list($width, $height, $type, $attr) = getimagesize($filename); $newwidth = 128; $newheight = $height / ($width / $newwidth); // Load $thumb = imagecreatetruecolor($newwidth, $newheight); $white = imagecolorallocate($thumb, 255, 255, 255); imagefill($thumb, 0, 0, $white); switch ($type) { case '1': $source = imagecreatefromgif($filename); break; case '2': $source = imagecreatefromjpeg($filename); break; case '3': default: $source = imagecreatefrompng($filename); break; } // Resize imagecopyresampled($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height); $destination = $img_root . "small_" . $_FILES['Logo']['name']; switch ($type) { case '1': imagegif($thumb, $destination); break; case '2': imagejpeg($thumb, $destination); break; case '3': default: imagepng($thumb, $destination); break; } /*$face_detect = new Face_Detector(get_theme_root() . '/fontfolio/inc/face-detect/detection.dat'); $face_detect->face_detect($destination); $face_detect->saveResizedFace(64,64,$type,$destination);*/ $sql = "UPDATE tblAziende SET Logo=? WHERE ID=?"; $query = $db->prepare($sql); $query->execute(array( '0' => $_FILES['Logo']['name'], '1' => $idTemp )); } } } } ?> <?php if ($messaggio_conferma == false) { ?> <form method="post" action="<?= site_url() ?>/iscriviti/" enctype="multipart/form-data"> <table style="width: 100%"> <tr> <td>Referente</td> <td><input style="width:90%" type="text" name="Partecipante" value="<?= $_POST['Partecipante'] ?>" /></td> </tr> <tr> <td>Ragione Sociale</td> <td><input style="width:90%" type="text" name="RagioneSociale" value="<?= $_POST['RagioneSociale'] ?>" /></td> </tr> <tr> <td>Indirizzo</td> <td><input style="width:90%" type="text" name="Indirizzo" value="<?= $_POST['Indirizzo'] ?>" /></td> </tr> <tr> <td>Cap</td> <td><input style="width:90%" type="text" name="Cap" value="<?= $_POST['Cap'] ?>" /></td> </tr> <tr> <td>Città </td> <td><input style="width:90%" type="text" name="Citta" value="<?= $_POST['Citta'] ?>" /></td> </tr> <tr> <td>Telefono</td> <td><input style="width:90%" type="text" name="Telefono" value="<?= $_POST['Telefono'] ?>" /></td> </tr> <tr> <td>Partita IVA</td> <td><input style="width:90%" type="text" name="Fax" value="<?= $_POST['Fax'] ?>" /></td> </tr> <tr> <td>Email</td> <td><input style="width:90%" type="text" name="Mail" value="<?= $_POST['Mail'] ?>" /></td> </tr> <tr> <td>Indirizzo web</td> <td><input style="width:90%" type="text" name="Sito" value="<?= $_POST['Sito'] ?>" /></td> </tr> <tr> <td>Settore merceologico</td> <td><input style="width:90%" type="text" name="SettoreMerceologico" value="<?= $_POST['SettoreMerceologico'] ?>" /></td> </tr> <tr> <td>Numero di dipendenti</td> <td><input style="width:90%" type="text" name="NumeroDipendenti" value="<?= $_POST['NumeroDipendenti'] ?>" /></td> </tr> <tr> <td>Descrizione attività </td> <td><textarea name="Descrizione" rows="10" style="width:90%"><?= $_POST['Descrizione'] ?></textarea></td> </tr> <tr> <td>Tipologia prodotti/servizi offerti</td> <td><textarea name="ProdottiServizi" rows="10" style="width:90%"><?= $_POST['ProdottiServizi'] ?></textarea></td> </tr> <tr> <td>Upload logo azienda<br/><small>Formati ammessi: JPG, PNG, GIF</small></td> <td><input type="file" name="Logo" style="width:90%" /></td> </tr> </table> <input type="submit" name="register_btn" value="Iscriviti" /> </form> <?php } else { ?> La ringraziamo di essersi registrato all’evento Business Speed Dating: Le ricordiamo che l’assegnazione alla prossima data avverrà in base all’ordine cronologico di arrivo delle domande di iscrizione, fino ad esaurimento posti. Riceverà quindi conferma via mail dell’avvenuto inserimento o, al contrario, della messa in priorità nella prima data successiva.<br/> Per delucidazioni non esiti a contattarci:<br/> Marketing Associativo – Business Speed Dating<br/> <?php } ?> page.php Edited October 14, 2015 by QuickOldCar Quote Link to comment https://forums.phpfreaks.com/topic/298589-last-inserted-id-in-a-string/#findComment-1523269 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.