Jump to content

[php] how to have an image within a script link to itself with a script


randydg

Recommended Posts

I am having an issue. I have a code that works fine, but I want to remove a link within a script to another page and bundle it within the main page script so it doesn't have to go to another page. Basicly I want it to post to itself and delete a line out of mysq limit 1. Currently the script looks up the items from the sql database and posts the count of them and next to it has a link with a add 1 or remove 1. that goes to another script that works fine, just want to add it to the one bellow.

I know how to do it with a form & script, but since the link/image is already in a script, I am not sure what to do.

 

Index.php:

<?php
	include 'connect.php';
    $query="SELECT *  FROM inventory WHERE `Device` = 'item1' ";
    $result=mysql_query($query);
    $num=mysql_numrows($result);
	if ($num> 0){ 
    $id=mysql_result($result,$i,"Id");
	$name=mysql_result($result,$i,"Name");
	$discription=mysql_result($result,$i,"Discription");
	$cost=mysql_result($result,$i,"Cost");
	$retail=mysql_result($result,$i,"Retail");
	$amount=mysql_result($result,$i,"Amount");
	$device=mysql_result($result,$i,"Device");
	    print "<tr>";
        print "<td bgcolor='#00ff00'>$num</td>";
		print "<td>item 1 name</td>";
		print "<td>item 1 discription</td>";
		print "<td><a href='addcount.php'><img src='addcount.png'></a></td>";
		print "<td><a href='deletecount.php'><img src='RenderedImage.png'></a></td>";
		print "</tr>";
         }else{ 
        print "<tr>";
        print "<td bgcolor='#FF0033'>0</td>";
		print "<td>item 1 name</td>";
		print "<td>item 1 discription</td>";
		print "<td><a href='addcount.php'><img src='addcount.png'></a></td>";
		print "<td>Nothing to Delete</td>";
		print "</tr>";
} 
	?>

addcount.php:

<?php
 if (isset($_POST['submitadd'])) { 
      $addnew = trim(stripslashes($_POST['addnew'])); 

		include 'connect.php';
		$query="SELECT `id`,`device` FROM `inventory`";
		$result=mysql_query($query);
		$num=mysql_numrows($result);	

	  $sql = "INSERT INTO inventory VALUES('','','','','','','$addnew')";
	  
	  
	  
	  
      $result = mysql_query($sql); 
      if (!$result) { 
              die('Invalid query: '.mysql_error()); 
      } 
      print "$addnew added successfully.<br />"; 
} 
?> 
<form method="POST" action="<?=$PHP_SELF;?>">
  ADD New:<br />  
 Enter Device ID:   
 <input type="text" name="addnew">  
 <input type="submit" name="su'submitadd'value="SUBMIT"/> 
</form>

 These work fine separatly, but I was really wanting to combine them into 1 script, but the link to add/delete needs to be where it currently is in index.php or it will screw up the tables.

Thanks for any advice

 

Link to comment
Share on other sites

Correction at the end of addcount.php:

<form method="POST" action="<?=$PHP_SELF;?>">
  Add Count from<br />  
 Enter Device Name:   
 <input type="text" name="addnew">  
 <input type="submit" name="submitadd" value="SUBMIT"/> 
</form>
Edited by randydg
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.