HTML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignHTML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 9th, 2012, 06:31 PM
BethK BethK is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 1 BethK User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 41 m 2 sec
Reputation Power: 0
New Member - Passing variables from a table row to PHP script

I'm developing a web application for our village public library. This is a labor of love. I can put things in the database, and view the database just fine. With updates and deletes, I have a problem.

In short, I have a pretty plain HTML file where the user selects the books he or she wishes to update or delete. That, in turn, calls a PHP routine, called upd2.php, which does the MySQL database query, and displays the results in a table, along with UPDATE and DELETE buttons and editable values in the fields of the table. Clicking one of those buttons calls a second PHP script, called upd3.php. The isbn field is the primary key on the database.

Investigation shows that there appear to be no variables or values passed to the second PHP script, except for the button values (UPDATE or DELETE).

So, passing parameters worked from the regular HTML file to the upd2.PHP script. That, in turn, wrote an HTML page, with a table having multiple columns and one or more rows. However, I cannot seem to use the HTML generated from this PHP script to call another PHP script.

If I hard code a $bookid into the upd3.PHP script, it will delete that book fine.

There are other columns in the tables and in the database, but for simplicity I've removed them here.

(upd2.php)
PHP Code:
echo '<form action="upd3.php" method="post">';
echo 
"<table border='1'>

  for (
$i=0; $i <$num_results$i++)
  {

     
$row = $result->fetch_assoc();
     
$tti = $row['title'];
     
$bookid = stripslashes($row['isbn']);
  echo '<tr>';
  echo '<td width=65> <input name=upda type=submit value="
Update" > </td>';
  echo '<td width=65> <input name=dele type=submit value="
Delete"> </td>';

// Make this a hidden input later, since it would not make sense to edit this.
  echo '<td width=30><input name=bkid value="';
  echo $bookid;
  echo '" size=15 maxlength=30> </td>';

  echo '<td width=220><input name=titlee value="';
  echo $tti;
  echo '" size=20 maxlength=100> </td>';
  echo '<td width=110><input name=lauth value="';
  echo $authl;
  echo '" size=20 maxlength=30> </td>';
  echo '</tr>';
  }
echo '</table>';
echo '</form>';
  
  
$result->free();
  
$db->close();

?> 

(upd3.php)
PHP Code:
<?php
  
// create short variable names
  
$upda=$_POST['upda'];
  
$dele=$_POST['dele'];
  
$titl=$_Post['titlee'];
  
$authl=$_Post['lauth'];
  
$bookid=$_Post['bkid'];



 
//This works okay, but I left out the details for this post
 
$db = new mysqli([I]parameters[/I]);

  if (
mysqli_connect_errno()) 
  {
     echo 
'Error: Could not connect to database.  Please try again later.';
     exit;
  }



    
$bookid addslashes($bookid);

 
$query "delete from books where isbn = '".$bookid."'";

  
$result $db->query($query);
  if (
$result)
{
      echo  
$db->affected_rows.' book deleted from database.'
}

  
$result->free();
  
$db->close();


?>

If I hard code something in for $bookid, like $bookid="444" right above the $query= line, this works great.

The UPDATE code in upd3.php works similarly, but I'm working on getting it debugged on the simpler case of DELETE.

Any help would be appreciated.

Reply With Quote
  #2  
Old November 9th, 2012, 06:52 PM
requinix's Avatar
requinix requinix is online now
Still alive
Click here for more information.
 
Join Date: Mar 2007
Location: Washington, USA
Posts: 12,706 requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)requinix User rank is General 120th Grade (Above 100000 Reputation Level)  Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1Folding Points: 417516 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 5 Months 1 Week 4 Days 6 h 22 m 9 sec
Reputation Power: 8969
Send a message via AIM to requinix Send a message via MSN to requinix Send a message via Yahoo to requinix Send a message via Google Talk to requinix
PHP variables are case-sensitive. $_POST and $_Post are two different things.

For development you should always have two php.ini settings set a certain way: error_reporting=E_ALL (or better) and display_errors=on. Enable those, restart your webserver, and run your script as it is now. You should see error messages.

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignHTML Programming > New Member - Passing variables from a table row to PHP script

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap