August 29, 201411 yr Hi, i need help i have been trying to make a mysqli update form. I figured out delete and adding a new table but i dont know how to update an existing table. Can someone please help me ?
August 30, 201411 yr Hi,My advice, paste your code here and tell me what you exactly want to achieve.If you mean sql query, I will try to help you, but it seems that you need php form which will be updating your records in date base?
September 2, 201411 yr Author Hi everyone, Thank you for your reply Here is what i am trying to do. This is the admin area and i can easily delete a record However when i try to update it doesnt work so i click on the update button for any of them and it gets the right id and etc This is the update page When i press query i get this error This is my update.php code the form <?php include "head.php"; ?> <section> <h3>Update user details</h3> <form action="update-process.php" method="POST"> Name: <input type="text" name="name"/> </br> </br> </br> Email: <input type="text" name="email"/> </br> </br> </br> Instit: <input type="text" name="institution"/> </br> </br> </br> <input type="submit"/> </form> </section> <?php include "aside.php"; ?> <?php include "footer.php"; ?> This is the update process.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $linid = $_GET['linid']; $sql = "SELECT * FROM edit WHERE id = $linid"; $result=mysql_query($sql); $con=mysqli_connect("localhost","root","root","lil"); if(mysqli_connect_error()){ echo "failed to connect" . mysqli_connect_error(); } $name = mysqli_real_escape_string($con, $_POST['name']); $email = mysqli_real_escape_string($con, $_POST['email']); $institution = mysqli_real_escape_string($con, $_POST['institution']); if($result = mysqli_query($con,"UPDATE FROM edit WHERE id = $linid")) { echo "its deletd"; } else { echo "Failed to update."; } mysqli_close($con); ?> PS i am using mysqli
September 2, 201411 yr your update statement should be like this UPDATE edit SET email = $email WHERE id = $linid You are trying to update Records in a field? not a table, which is why you got the ALTER functions from NOCK, which is used to alter tables.
September 2, 201411 yr Author Thank you everyone but its still not working. Getting same error PS ive made all of them to POST This is the process.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); $linid = $_POST['linid']; $sql = "SELECT * FROM edit WHERE id = $linid"; $result=mysql_query($sql); $con=mysqli_connect("localhost","root","root","lil"); if(mysqli_connect_error()){ echo "failed to connect" . mysqli_connect_error(); } $name = mysqli_real_escape_string($con, $_POST['name']); $email = mysqli_real_escape_string($con, $_POST['email']); $institution = mysqli_real_escape_string($con, $_POST['institution']); if($result = mysqli_query($con,"UPDATE edit SET email = $email WHERE id = $linid")) { echo "its deletd"; } else { echo "Failed to update."; } mysqli_close($con); ?> This is update.php <?php include "head.php"; ?> <section> <h3>Update user details</h3> <form action="update-process.php" method="POST"> Name: <input type="text" name="name"/> </br> </br> </br> Email: <input type="text" name="email"/> </br> </br> </br> Instit: <input type="text" name="institution"/> </br> </br> </br> <input type="submit"/> </form> </section> <?php include "aside.php"; ?> <?php include "footer.php"; ?>
September 2, 201411 yr Author i don't see you posting the $_POST['linid']; ? from update.php How to do that sorry i am still learning PHP but ive been stuck with this thing for the past few days
September 3, 201411 yr Your form is posting three values which you need to extract as variables., name, email and institution. The value 'linid' is not being submitted along with the form. So the PHP script will fail when it gets to $sql = "SELECT * FROM edit WHERE id = $linid"; As $linid has no value. You need to include a field where the user enters the relevant value for linid so that it is submitted along with the form.
September 3, 201411 yr How to do that sorry i am still learning PHP but ive been stuck with this thing for the past few days like so <input type="hidden" name="linid" value="1" readonly /> probably should call records up dynamically if you want it to work right, or you put each linid individually What do you have in your database ? do you have any records ? Edited September 3, 201411 yr by inlinedivblock
September 3, 201411 yr like so <input type="hidden" name="linid" value="1" readonly /> probably should call records up dynamically if you want it to work right, or you put each linid individually What do you have in your database ? do you have any records ? They'll have a database of one record if they hard wire the value of $linid to 1. No matter what data is entered the only record will have the id of 1. The OP needs to add a field so the visitor can enter their user ID which is what I assume linid is supposed to be. User ID: <input type="text" name="linid"/> To the OP: By the way it would be better to get rid of all those </br> tags by using CSS to set out the form layout.
September 3, 201411 yr ok so this part of the mysql code ' WHERE id = $linid ' should be a unique identification number otherwise any records sharing that id number will also be updated. I would not recommend letting the used input the unique id themselves. as for making the form look nice you can look at implementing some light frameworks? but i would first get your form working and then think about the look and feel of the site.
September 3, 201411 yr Well the user will have to input something unique, either a unique user ID or a unique user name. Looking at an earlier post by the OP the name is described as 13.allan, 14.mohammed and so on. If the integer prefix is unique then name could be divided using PHP explode function to extract the integer and then the OP would have $linid=13 and $name=allan. Don't see a need to start using a framework to cover something as simple as input { display:block; margin-bottom:60px; /* adjust as required */ } Frameworks are for those who don't understand CSS. One step up from a WYSIWYG editor.
September 3, 201411 yr Frameworks are for those who don't understand CSS. One step up from a WYSIWYG editor. framweworks are a great tool to aid in web development, And you need knowledge in css / html / javascript to put it all together, How are you using the linid moham?
Create an account or sign in to comment