Update baze pomoc :D

Trebam pomoc u vezi update baze… ovaj prvi kod mi je skripta update.php i kada pokrenem izvuce iz baze informacije o imenu prezimenu i e-mailu i zatim putem form actionsa ide u update1.php i kada se to pokrene update u bazi se nece promjeniti nego ostaje isti kako je i bio zapisan ranije.

<?php
$host="localhost"; 
$username=""; 
$password=""; 
$db_name="test"; 
$tbl_name="test_mysql"; 


mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$id=$_GET['id'];


$sql="SELECT * FROM $tbl_name WHERE id='$id'";
$result=mysql_query($sql);
$rows=mysql_fetch_array($result);
?>

<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update1.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in mysql</strong> </td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
<td align="center">&nbsp;</td>
</tr>
<tr>
<td align="center">&nbsp;</td>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
</tr>
<tr>
<td>&nbsp;</td>
<td align="center">
<input name="name" type="text" id="name" value="<? echo $rows['name']; ?>">
</td>
<td align="center">
<input name="lastname" type="text" id="lastname" value="<? echo $rows['lastname']; ?>" size="15">
</td>
<td>
<input name="email" type="text" id="email" value="<? echo $rows['email']; ?>" size="15">
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td>
<input name="id" type="hidden" id="id" value="<? echo $rows['id']; ?>">
</td>
<td align="center">
<input type="submit" name="Submit" value="Submit">
</td>
<td>&nbsp;</td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?php
// close connection 
mysql_close();
?>

a ovo mi je fajl update1.php

<?php
$host="localhost"; 
$username="";  
$password=""; 
$db_name="test";  
$tbl_name="test_mysql";


mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");


$sql="UPDATE $tbl_name SET name='$name', lastname='$lastname', email='$email' WHERE id='$id'";
$result=mysql_query($sql);


if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list.php'>View</a>";
}

else {
echo "ERROR";
}

?>

http://www.w3schools.com/php/php_forms.asp

pa prije svega ne vidim gdje u “update fajl skripti” punis $name $lastname i $email varijable? Pretpostavljam da saljes te podatke preko forme sto znaci da ti ovdje fali par GET-ova. U biti fali tu svašta nešto.

Rijesio sam samo sam trebao poslat sa $_POST te varijable i radi

Nema na čemu :slight_smile: 20 znakova


Copyright © 2020 WM Forum - AboutContact - Sponsored by: Mydataknox & Profit Monkey