Solved

PHP / MYSQL update

Posted on 2011-03-15
15
247 Views
Last Modified: 2012-05-11
Hi Experts,

Im in need of some help desperately.

I have a page where you can edit "notes" and also edit "last spoken to" and you can edit these by typeing in the boxes at the bottom of the page. The customer is selected using a variable but when i try to navigate back to the page the variable for the customer is obviously lost. is there a way of fixing this? ive attached code many thanks.


// mobile num.php // 

<?php
session_start();
ob_start();
?>
<?
error_reporting(E_ALL);
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">

    
<title>Talk Business Solutions</title>

        <link id="css_default" href="unity_scm.css" 
rel="stylesheet" type="text/css">
    </head><body>
        <div class="fullpage">
            <div class="topbar">
                <div class="topbar_left"></div>
            </div>

            <div class="secondbar">
            </div>

            <div class="header">
              <div align="center"><span class="secondbar"><img src="index_files/unity_scm_images/header.gif" width="970" height="140" alt="headerimage" /></span></div>
            </div>
            <div class="leftcol">

	      <div class="bar">&nbsp;</div>
				<div class="titleimage">
                	<div align="center"><img src="/test.gif" alt="navgif">
              	  </div>
				</div>
				<div class="bar">&nbsp;</div>

                <div align="center"><a name="sitenav"></a>
                  <ul class="navbar">
                    <li><a 
href="logout.php" accesskey="1">Logout</a></li>
                    <li><a href="link2.php" accesskey="2">Link2</a></li>
                    <li><a href="link3.php" accesskey="3">Link3</a></li>
                    <li><a href="link4.php" accesskey="4">Link4</a></li>
                    <li><a href="link5.php" accesskey="5">Link5</a></li>
                    <li><a href="link6.php" accesskey="6">Link6</a></li>
                    <li><a href="link7.php" accesskey="7">Link7</a></li>
                    
                    
                    
                    
                  </ul>
                  </ul>
                </div>
                <div class="sidebarbottom">&nbsp;</div>
            </div>
            <div class="mainarea">
            
    <div align="center">

    </div>
          <div class="pagearea">
                    <div align="center"><a name="content"></a>
                      
                    </div>
            <h2 align="center">Talk Business Solutions</h2>

<p align="center" style="font-size: 0.8em; border-color: rgb(221, 221, 221);"><em>Here is a list of all customers in relation to the company selected..</em></p>

<h3 align="center" class="banner">Customers</h3>
<p align="center"></p>


<title></title>
<div align="center">
  <body>
  
  
  <body bgcolor="#c9cfef" link="#000000" vlink="#000000">
  
</div>
<tr>
</div>
<td width="100" valign="top"></td>
<td width="100" nowrap><div align="center"><br />
  
  
</div></td>
<p align="center">
<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT * FROM customer WHERE customer_name = '" . $val . "'";
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Company:</td><td>".$row['customer_name']."</td></tr>";
    echo "<tr><td>Account Number:</td><td><a href=\"account.php?val=".$row['account_number']."\">".$row['account_number']."</a></td></tr>";
	 echo "<tr><td>Contact Name:</td><td>".$row['contact_name']."</td></tr>";
	 echo "<tr><td>Telephone Number:</td><td>".$row['telephone_number']."</td></tr>";
	 echo "<tr><td>Fax:</td><td>".$row['fax']."</td></tr>";
	 echo "<tr><td>Contact Mob Number:</td><td>".$row['contact_mobile']."</td></tr>";
	 echo "<tr><td>Address:</td><td>".$row['full_address']."</td></tr>";
	 echo "<tr><td>Network:</td><td>".$row['network']."</td></tr>";
	 echo "<tr><td>Last Spoke To:</td><td>".$row['last_spoke_to']."</td></tr>";
	 echo "<tr><td>Notes:</td><td>".$row['notes']."</td></tr>";
	 echo "<tr><td>Kit Fund Level:</td><td>".$row['kit_fund_level']."</td></tr>";
   echo"</table>";
}
   ?> 
<?php 
$query=" SELECT * FROM customer";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$last_spoke_to=mysql_result($result,$i,"last_spoke_to");
$notes=mysql_result($result,$i,"notes");
++$i;
}
?>

<title></title>
<body>
<form name="register" method="post" action="edituploadednotes.php">
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
    <td colspan="14" bgcolor="#ffffff"><strong>Edit Notes</strong></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Last spoke to</td>
    <td width="7" bgcolor="#ffffff">:</td>
   <td width="393" bgcolor="#ffffff"><textarea name="last_spoke_to" cols="40" rows="10">
Enter your last spoke to here....
</textarea>
      <br /></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Notes</td>
    <td width="7" bgcolor="#ffffff">:</td>
    <td width="393" bgcolor="#ffffff"><textarea name="notes" cols="40" rows="10">
Enter your notes here....
</textarea>
      <br /></td>
  </tr>
  <td wdith="1298" bgcolor="#ffffff"><input type="submit" name="Submit" value="Update" /></td>
  </tr>
</table></td>
</form>


</p>

<th>&nbsp;</th> 
  <td>&nbsp;</td>
  <div align="center"><br/>
    <img src="" width="" height="
                              ">
    
    
  </div>
<div align="center">
  </div>
  </div>
  
</div>
<div class="spacer"></div>

         
            <div class="footer">
            	<div class="secondbar_bottom">
            	  <div align="center">
            	    <?php //echo 'Welcome ' .''. $_SESSION['myusername'];?>
          	    </div>
            	</div>
            	<div class="bottombar">
            	  <div align="center">Talk Business Solutions</div>
            	</div>
            </div>
        <div align="center">
              </div>
    </div>
</body></html>

/// EDITUPLOADEDNOTES.PHP THIS IS THE PAGE IT EXECUTES TO /// 

<?php
session_start();
ob_start();
?>
<?php 
error_reporting(E_ALL);

$last_spoke_to = $_POST['last_spoke_to'];
$notes = $_POST['notes'];
$val = $_GET['val'];


include 'myphp.php';


//update the database with the set variables recoverd from the form from the other page. 

$query = "UPDATE customer SET last_spoke_to = '$last_spoke_to', notes = '$notes'";


$result=mysql_query($query);

 if($result){
	header("location:mobilenum.php");
}
else{
	echo "ERROR";
}
mysql_close();

?>

Open in new window

0
Comment
Question by:NeoAshura
  • 8
  • 5
  • 2
15 Comments
 
LVL 13

Assisted Solution

by:dsmile
dsmile earned 50 total points
ID: 35136858
Online 218, use this

header("location:mobilenum.php". $val);
0
 
LVL 13

Expert Comment

by:dsmile
ID: 35136870
header("location:mobilenum.php?val=". $val);

Explanation: since you use $_GET['val'] as the input for your query, you have to pass it to the url again when you redirect the page.
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35136983
hi sadly that did not work.

 Notice: Undefined index: val in I:\EasyPHP-5.3.5.0\www\mobilenum.php on line 93
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 6

Author Comment

by:NeoAshura
ID: 35137022
for example when i click update the url goes to the following.

http://127.0.0.1:8888/mobilenum.php

and obviously unsets the variable.

When it should just refer back to its previous variable of...

http://127.0.0.1:8888/mobilenum.php?val=Mrs%20Anna%20Norris 
0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35137030
dsmile's explanation is best answer.. any how if you need all the values to your page.....

Please try this


Change this code as follwoing

$last_spoke_to = $_POST['last_spoke_to'];
$notes = $_POST['notes'];
$val = $_GET['val'];


$last_spoke_to  = $_REQUEST['last_spoke_to'];
$notes               = $_REQUEST['notes'];
$val                        = $_REQUEST['val'];


And change this line

header("location:mobilenum.php");
 
header("location:mobilenum.php?val=".$val."&last_spoke_to=".$last_spoke_to."&note=".$notes);
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35137086
thats for the reply,

This return the following, url

http://127.0.0.1:8888/mobilenum.php?val=

as you can see it misses out the val of the customer.

thanks for the reply any more ideas?
0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35137226
Instead of this

$_GET['val']

Try request method


$_REQUEST['val']


or

in the page

just print the values that are sent

using

print_r($_GET); exit;

or

print_r($_REQUEST); exit;
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35137281
hi pius thanks for reply,

with print_r($_get);EXIT;

i get the following..

Array ( [val] => )

with

$val= $_REQUEST['val'];
print_r($_REQUEST); exit;

i get

Array ( [val] => [last_spoke_to] => Enter your last spoke to here.... [notes] => Enter your notes here.... [Submit] => Update )

as you can see the only variable not being set is val.... i need this to be able to send the header back to my origonal page.. all i need to do is somehow pass my val to the next page and then pass it back again.

0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35137486
NeoAshura....

ok fine form which page you are sending val ? val does not have values to request or get....

assign some value for val and  check
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35137590
VAL is set and comes from this page here

Please See line 4.


<?php 
error_reporting(E_ALL);
include 'myphp.php';
$val = $_GET['val'];
$sql = "SELECT * FROM customer WHERE customer_name = '" . $val . "'";
$result = mysql_query($sql) or die(mysql_error() . " IN $sql"); 
$rs = mysql_query($sql);

while($row = mysql_fetch_array($rs))
{
   echo"<table>";
   echo "<tr><td>Company:</td><td>".$row['customer_name']."</td></tr>";
    echo "<tr><td>Account Number:</td><td><a href=\"account.php?val=".$row['account_number']."\">".$row['account_number']."</a></td></tr>";
	 echo "<tr><td>Contact Name:</td><td>".$row['contact_name']."</td></tr>";
	 echo "<tr><td>Telephone Number:</td><td>".$row['telephone_number']."</td></tr>";
	 echo "<tr><td>Fax:</td><td>".$row['fax']."</td></tr>";
	 echo "<tr><td>Contact Mob Number:</td><td>".$row['contact_mobile']."</td></tr>";
	 echo "<tr><td>Address:</td><td>".$row['full_address']."</td></tr>";
	 echo "<tr><td>Network:</td><td>".$row['network']."</td></tr>";
	 echo "<tr><td>Last Spoke To:</td><td>".$row['last_spoke_to']."</td></tr>";
	 echo "<tr><td>Notes:</td><td>".$row['notes']."</td></tr>";
	 echo "<tr><td>Kit Fund Level:</td><td>".$row['kit_fund_level']."</td></tr>";
   echo"</table>";
}
   ?> 
<?php 
$query=" SELECT * FROM customer";
$result=mysql_query($query);
$num=mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$last_spoke_to=mysql_result($result,$i,"last_spoke_to");
$notes=mysql_result($result,$i,"notes");
++$i;
}
?>

<title></title>
<body>
<form name="register" method="post" action="edituploadednotes.php">
<td><table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
  <tr>
    <td colspan="14" bgcolor="#ffffff"><strong>Edit Notes</strong></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Last spoke to</td>
    <td width="7" bgcolor="#ffffff">:</td>
   <td width="393" bgcolor="#ffffff"><textarea name="last_spoke_to" cols="40" rows="10">
Enter your last spoke to here....
</textarea>
      <br /></td>
  </tr>
  <tr>
    <td width="249" bgcolor="#ffffff">Notes</td>
    <td width="7" bgcolor="#ffffff">:</td>
    <td width="393" bgcolor="#ffffff"><textarea name="notes" cols="40" rows="10">
Enter your notes here....
</textarea>
      <br /></td>
  </tr>
  <td wdith="1298" bgcolor="#ffffff"><input type="submit" name="Submit" value="Update" /></td>
  </tr>
</table></td>
</form>

Open in new window

0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35137611
p.s page attached is called mobilenum.php and need the variable passing to edituploadednotes.php which is sent for by the form.

then when on edituploadednotes.php the val then needs to be sent back... to mobilenum.php to display

mobilenum.php?val=var here
0
 
LVL 3

Accepted Solution

by:
pius_babbun earned 450 total points
ID: 35137675
Just add a hidden feild after the form tag as below and check if it is helpful

<form name="register" method="post" action="edituploadednotes.php">
<input type="hidden" value="<?php echo $_GET['val']; ?>" name="val" >
0
 
LVL 6

Author Comment

by:NeoAshura
ID: 35137713
You sir are a genius.

Thank you very much.
0
 
LVL 6

Author Closing Comment

by:NeoAshura
ID: 35137726
points awarded for contributing to dsmile.

full answer awarded 200 points to pius.
0
 
LVL 3

Expert Comment

by:pius_babbun
ID: 35137875
thanks NeoAshura..great participating ....
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

777 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