Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

udpate php form

Featured Replies

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 ?

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?

  • 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

 

Screen_Shot_2014_09_02_at_12_57_15_PM.pn

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

 

Screen_Shot_2014_09_02_at_12_58_17_PM.pn

 

When i press query i get this error

 

Screen_Shot_2014_09_02_at_1_09_54_PM.png

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

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.

  • 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"; ?>

  • 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

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.

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 by inlinedivblock

 

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.

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.

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.

 

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

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.