3
I am doing a project that is in the following form:
First the person will upload her photo in the comic (Table: registered, field: photo) However this table has other fields, for this I created a form that will change the last line registered and add the other fields (name, phone, email etc) keeping the photo.
The problem is: UPDATE cadastro SET nome = $nome WHERE id = **PROBLEMA**;
I need the ID to be the last one that recorded the photo, but I don’t know how to get it.
To better interpret my doubt:
This is the table, and its Mysql fields. I’ve already saved the photo as you can see. Now in the form I want to give an UPDATE to add the remaining information on that line there (id = 20).
IMAGE INSERT CODE:
function saveimagem($name, $image)
{
$host = "localhost";
$user = "root";
$pass = "";
$conexao = mysqli_connect($host, $user, $pass) or die (mysql_error());
mysqli_select_db($conexao, "teste");
$sql = "insert into cadastro (foto) values ('$image')";
if($sql){
print "ID: ". mysqli_insert_id($conexao);
}
$result = mysqli_query($conexao, $sql);
if($result)
{
echo "<br/>Foi feito o upload";
}else
{
echo "<br/>Não foi feito o upload";
}
}
What api is using to connect to the database?
– rray
@No, I’m doing everything
– WSS
If you have any code ask the question :)
– rray
Just play the
mysqli_insert_id()
within theif($result)
– rray
Uffa. worked very well thanks. Do I need to do something now? Close the question?
– WSS
Mark August response as accepted, How and why to accept an answer?
– rray