lolclol Posted May 5, 2013 Share Posted May 5, 2013 <?php $host="localhost"; $username="user"; $password="pass!"; $db_name="_login1"; $tbl_name="mr_recipes"; // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data $sql="UPDATE $tbl_name SET name='$name', url='$url', cat='$cat', isApproved='$isApproved' WHERE id='$id'"; $result=mysql_query($sql); if($result){ echo "Successful"; echo "<BR>"; echo "<a href='editrecipe.php'>View result</a>"; } else { echo "ERROR"; } ?> update_ud.php still not updating! I have gone on the isApproved, update.php <?php $host="localhost"; // Host name $username="user"; // Mysql username $password="pass!"; // Mysql password $db_name="_login1"; // Database name $tbl_name="mr_recipes"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <table class="display" width="400" border="0" cellspacing="1" cellpadding="0"> <tr> <form name="form1" method="post" action="update_ud.php"> <td> <table width="100%" border="0" cellspacing="1" cellpadding="0"> <tr> <td> </td> <td colspan="3"><strong>Update data in mysql</strong> </td> </tr> <tr> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> <td align="center"> </td> </tr> <tr> <td align="center"> </td> <td align="center"><strong>url</strong></td> <td align="center"><strong>cat</strong></td> <td align="center"><strong>name</strong></td> <td align="center"><strong>isApproved</strong></td> </tr> <tr> <td> </td> <td align="center"> <input name="url" type="text" id="url" value="<? echo $rows['url']; ?>"> </td> <td align="center"> <input name="cat" type="text" id="cat" value="<? echo $rows['cat']; ?>" size="15"> </td> <td> <input name="name" type="text" id="name" value="<? echo $rows['name']; ?>" size="15"> </td> <td> <input name="isApproved" type="radio" value="yes" /></td> </tr> <tr> <td> </td> <td> <input name="id" hidden="hidden" id="id" value="<? echo $rows['id']; ?>"> </td> <td align="center"> <input type="submit" name="Submit" value="Submit"> </td> <td> </td> </tr> </table> </td> </form> </tr> </table> <?php // close connection mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/277669-updating-database/ Share on other sites More sharing options...
wright67uk Posted May 5, 2013 Share Posted May 5, 2013 In your form you are using a post method, but are you recalling it with a get? Also where are you assigning the values for the variables used within your mysql query? Quote Link to comment https://forums.phpfreaks.com/topic/277669-updating-database/#findComment-1428474 Share on other sites More sharing options...
lolclol Posted May 6, 2013 Author Share Posted May 6, 2013 <?php $host="localhost"; // Host name $username="user"; // Mysql username $password="Pass!"; // Mysql password $db_name="_login1"; // Database name $tbl_name="mr_recipes"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $sql="SELECT * FROM $tbl_name WHERE isApproved = 'no'"; $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 mysql </strong> </td> </tr> <tr> <td align="center"><strong>isApproved</strong></td> <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['isApproved']; ?></td> <td><? echo $rows['name']; ?></td> <td><? echo $rows['cat']; ?></td> <td><? echo $rows['url']; ?></td> <td align="center"><a href="update.php?id=<? echo $rows['id']; ?>">update</a></td> </tr> <?php } ?> </table> </td> </tr> </table> <?php mysql_close(); ?> Quote Link to comment https://forums.phpfreaks.com/topic/277669-updating-database/#findComment-1428524 Share on other sites More sharing options...
Psycho Posted May 6, 2013 Share Posted May 6, 2013 // update data $sql="UPDATE $tbl_name SET name='$name', url='$url', cat='$cat', isApproved='$isApproved' WHERE id='$id'"; Where are the variables $name, $cat, $url, $isApproved and $id defined??? Pro tip: Don't use values such as yes/no for a Boolean value. use 1/0 so you can treat them as logical TRUE / FALSE values. Then you can doa condition such as if ($isApproved) { instead of if ($isApproved == 'yes') { Quote Link to comment https://forums.phpfreaks.com/topic/277669-updating-database/#findComment-1428525 Share on other sites More sharing options...
lolclol Posted May 6, 2013 Author Share Posted May 6, 2013 $name=$_POST['name']; $cat=$_POST[cat]; $url=$_POST[url]; so this for variables? Quote Link to comment https://forums.phpfreaks.com/topic/277669-updating-database/#findComment-1428527 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.