Update record in php/mySQL

Posted on 2009-04-14
Last Modified: 2012-05-06
I'm trying to do a simple edit of rows in a database and am hitting a wall.

I am adding rows with no problem.

Please take a look and see if you can see any problems.  For debug purposes, I have echo'd out the Strain_ID (primary field) echos correctly in the first page but it is empty in the second page.
*********here's the edit page -- Strain_ID is the primary field***********



require ""; 



// Connect to an authenticated session or relocate to logout.php




$username = $_SESSION["loginUsername"]




<?php require_once("includes/connection.php"); ?>


	$mouse_id =  $_GET['mouse_id'];

	$record = mysql_query("SELECT * FROM mousetest WHERE ( Strain_ID='$mouse_id' )")

		or die("Could not query database");


	$mouse_row = mysql_fetch_array( $record );




<form action="edit_mouseline2.php" method="POST">

<table width="100%" border="0">


    <td valign="top"><p>Principal Investigator: <input type="text" name ="Principal_Investigator" 

    value="<?php echo $mouse_row['Principal_Investigator']; ?>"  /></p>

    <p>Co Investigator: <input type="text" name ="Co_Investigator" 

    value="<?php echo $mouse_row['Co_Investigator']; ?>"  /></p>



Strain ID Is <?php echo $mouse_row['Strain_ID']; ?>



**************here's  the code for:  edit_mouseline2.php ******************

<?php require_once("includes/connection.php"); ?>

<?php  require_once 'includes/functions.php'; ?>


require ""; 



// Connect to an authenticated session or relocate to logout.php




$username = $_SESSION["loginUsername"]







		$Common_Strain =  mysql_prep($_POST['Common_Strain']);

		$Co_Investigator = mysql_prep($_POST['Co_Investigator']);


$query = "UPDATE mousetest SET Principal_Investigator='$Principal_Investigator' WHERE Strain_ID='$Strain_ID'";


$result = mysql_query($query)

or die ("Couldn't execute query");


Open in new window

Question by:liz2008
LVL 11

Accepted Solution

AlexanderR earned 500 total points
ID: 24141123
because you are not passing strain_id between your form and edit_mouseline2.php

create a hidden input your form that stores strain_id:

<input type="hidden" name="strain_id" value="<?php echo $mouse_row['Strain_ID']; ?>" />

grab it in edit_mouseline2.php:
$Strain_ID = mysql_prep($_POST['strain_id']);

Author Closing Comment

ID: 31570012
Thank you, that was the missing piece.

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
get domain with php 7 19
datetime in sql 6 23
MySqlDump not dumping triggers 1 15
configure dependency in POM for new database 3 13
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

919 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now