[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Update record in php/mySQL

Posted on 2009-04-14
2
Medium Priority
?
194 Views
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) ...it 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***********
 
<?php
require "authentication.inc"; 
session_start();
 
// Connect to an authenticated session or relocate to logout.php
sessionAuthenticate();
 
 
$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">
  <tr>
    <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>
 </tr>
</table>
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'; ?>
<?php
require "authentication.inc"; 
session_start();
 
// Connect to an authenticated session or relocate to logout.php
sessionAuthenticate();
 
 
$username = $_SESSION["loginUsername"]
?>
 
 
 <?php
			
  
		$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

0
Comment
Question by:liz2008
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 11

Accepted Solution

by:
AlexanderR earned 2000 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']);
0
 

Author Closing Comment

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

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

649 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