Temos pavadinimas: WordPress, Shopify ir PHPFusion programuotojų bendruomenė :: Updating data in mysql neveikia

Parašė cropp· 2012 Sau. 22 21:01:26
#1

Sveiki, radau tokį straipsnį

http://www.phpeasystep.com/mysql...

ir pagal jį darau viską, tačiau man kažkodėl neatsinaujina informacija duomenų bazėje gal kas nors galėtų pasakyti kodėl neatsinaujina informacija?

Mano kodai:


<?php
 
require_once 'maincore.php';
require_once THEMES.'templates/header.php';
 
opentable('Turnyrine lentele');
 
$sql="SELECT * FROM test_mysql";
$result=mysql_query($sql);
?>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>List data from <span style="border-bottom: 1px dotted black;">mysql</span> </strong> </td>
</tr>
 
<tr>
<td align="center"><strong>Name</strong></td>
<td align="center"><strong>Lastname</strong></td>
<td align="center"><strong>Email</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td><? echo $rows['name']; ?></td>
<td><? echo $rows['lastname']; ?></td>
<td><? echo $rows['email']; ?></td>
 
 
<td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td>
</tr>
<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
closetable();
require_once THEMES.'templates/footer.php';
?>
 



<?php
 
require_once 'maincore.php';
require_once THEMES.'templates/header.php';
 
opentable('Turnyrine lentele');
 
// get value of id that sent from address bar
$id=$_GET['id'];
 
// Retrieve data from database
$sql="SELECT * FROM test_mysql 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="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in <span style="border-bottom: 1px dotted black;">mysql</span></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>
 
<?
 
closetable();
require_once THEMES.'templates/footer.php';
?>
 



<?php
 
require_once 'maincore.php';
require_once THEMES.'templates/header.php';
 
opentable('Turnyrine lentele');
 
// update data in <span style="border-bottom: 1px dotted black;">mysql</span> database
$sql = "UPDATE " . test_mysql .
       " SET name='" . mysql_real_escape_string($name) .
       "', lastname='" . mysql_real_escape_string($lastname) .
       "', email='" . mysql_real_escape_string($email) .
       "' WHERE id='" . mysql_real_escape_string($id) . "'";
$result=mysql_query($sql);
 
// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='list_records.php'>View result</a>";
}
 
else {
echo "ERROR";
}
 
closetable();
require_once THEMES.'templates/footer.php';
?>

Parašė avice· 2012 Sau. 22 22:01:05
#2


 $sql = "UPDATE " . test_mysql . " SET name='" . mysql_real_escape_string($_POST['name']) . "', lastname='" . mysql_real_escape_string($lastname) . "', email='" . mysql_real_escape_string($email) . "' WHERE id='" . mysql_real_escape_string($id) . "'"; 
matai ka pakeiciau? Tapati padaryk ir su lastname email ir id

Parašė cropp· 2012 Sau. 22 22:01:57
#3

Viskas susitvarkiau, ačiū tau širdingai knisaus nežinau kiek laiko. Ačiū tau labai;););)

Redagavo cropp· 2012 Sau. 22 22:01:10

Parašė avice· 2012 Sau. 22 22:01:59
#4

As tik $name pakeiciau i $_POST['name'] tai tu pakeisk ir lastname, email ir id i post. Paskutiniam faile

Parašė cropp· 2012 Sau. 22 23:01:54
#5

avice dar turiu vieną klausimą. Man reikia šiame kode pakeisti iš ID į pl_id tačiau kaip pakeičiu šį man rodo ne tą ka reikia.
Čia kodas kuriame reikia pakeisti gal gali pasakyti, kodel man rodo klaidingą info kada pakeičiu pavadinimą?

Aš keičiu čia: $id=$_GET['id']; <? echo $rows['id']; ?>"> id='$id'";


<?php
 
require_once 'maincore.php';
require_once THEMES.'templates/header.php';
 
opentable('Turnyrine lentele');
mysql_select_db("jcore_ras")or die("cannot select DB");
// get value of id that sent from address bar
$id=$_GET['id'];
 
// Retrieve data from database
 
 
$sql="SELECT * FROM j8mp_players 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="update_ac.php">
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in <span style="border-bottom: 1px dotted black;">mysql</span></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="pl_name" type="text" id="pl_name" value="<? echo $rows['pl_name']; ?>"></td>
<td align="center"><input name="pl_fname" type="text" id="pl_fname" value="<? echo $rows['pl_fname']; ?>" size="15"></td>
<td><input name="pl_position" type="text" id="pl_position" value="<? echo $rows['pl_position']; ?>" 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>
 
<?
 
closetable();
require_once THEMES.'templates/footer.php';
?>
 

Parašė avice· 2012 Sau. 23 16:01:19
#6

Bandei $row['id'] keist i $_GET['id'] .
ir apskritai paziurek per source ar gera info.

Parašė cropp· 2012 Sau. 23 16:01:53
#7

Pakeičiau tavo duotą kodą, tačiau tas pats. čia mano source. keista tačiau čia neištraukia ID <td><input name="pl_id" type="hidden" id="pl_id" value=""></td> kaip nekeičiu ID į pl_id viskas gerai veikia, tik pakeičiu ir neveikia.

<table cellpadding='0' cellspacing='0' width='100%'>
<tr>
<td class='capmain'>Turnyrine lentele</td>
</tr>
<tr>
<td colspan='3' class='main-body middle-border'>
<table width="400" border="0" cellspacing="1" cellpadding="0">
<tr>
<form name="form1" method="post" action="update_ac.php">
 
<td>
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<td>&nbsp;</td>
<td colspan="3"><strong>Update data in <span style="border-bottom: 1px dotted black;">mysql</span></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="pl_name" type="text" id="pl_name" value="Jennings"></td>
<td align="center"><input name="pl_fname" type="text" id="pl_fname" value="Brandon" size="15"></td>
<td><input name="pl_position" type="text" id="pl_position" value="4" size="15"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input name="pl_id" type="hidden" id="pl_id" value=""></td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td>&nbsp;</td>
</tr>
 
</table>
</td>
</form>
</tr>
</table>

Parašė avice· 2012 Sau. 23 16:01:34
#8

parasyk i skypa.
galbut per tw sutvarkyciau.

Parašė cropp· 2012 Sau. 23 16:01:38
#9

Parašiau prisijunk skype ;)