» »

PHP in link ?mode= ...

PHP in link ?mode= ...

osti1 ::

Haj.

Zanima me, kaj moram narediti, da iz ene strani (Search results) naredim link na formular, kjer bodo v polju vpisani podatki stika, ki ga je Search našel.

Trenutno poizkušam z 'a href="contact.php"?mode=edit', v contact.php imam pa na voljo if ( mode=="add") pa if ( mode=="edit"). Vendar noče pokazati formularja.

LP
osti
PS: a lahko tu na ta forum dam v svoj post php in html kodo, da ljudje vidijo, kake umotvore pišem in jih lahko pokomentirajo?
Če polžu ukradejo hišico, ... a je nag ali brezdomec?

camx ::

Napiši malo bolj jasno vprašanje ker iz tega se ne razume glih dobro kaj te muči.
Mogoče to da ne veš kako prebrat vrednost "mode" iz urlja?

//najprej preveri če je 'mode' nastavljen......
if(isset($_GET['mode'])){
$mode = $_GET['mode'];
} else {
//mode ni nstavljen
}

Pol pa z ifom al pa switchom pač pogledaš če je v 'mode' to kar ti iščeš:
if ( $mode=="add")......

Oziroma:
switch($mode){
case 'add':
//naredi nekaj
break;

case 'edit':
//naredi nekaj drugega
break;

default:
//če ni nič od zgoraj naštetega naredi nekaj x....
}

Nisem pa siguren če je to tvoja težava.

Zgodovina sprememb…

  • spremenilo: camx ()

osti1 ::

Imam tri datoteke, contact.php, search.php in p_contact.php. V contact.php je formular, ki vrednosti v poljih pošlje v p_contact.php, kjer je narejena skripta, ki podatke pošlje v mysql bazo. V search.php pa je skripta, ki išče po bazi in izvrže najdene informacije v search.php.

Rad bi naredil, da se preko linka v search.php (npr. Priimek je link v contact.php) vrednosti tega najdenega podatka prenesejo v contact.php in jih lahko spremenim.

To naj bi šlo preko tega mode=edit. Če pravilno razumem, moram obstoječi formular v contact.php spremeniti, da kadar hočem le dodati vrednosti se pojavi mode=add, kadar pa hočem spremeniti ali pa dodati podatke obstoječim podatkom se pa pojavi mode=edit (preko if ( mode=="add" oz. "edit")).

Poleg tega, da bom moral pošint kako bo skripta vedla ktere podatke naj da v mode=edit (verjetno preko $id ali $master_id), bom verjetno dodal še mode=delete.

LP
alen
Če polžu ukradejo hišico, ... a je nag ali brezdomec?

osti1 ::

Še to bi vprašal, a je bolje, da naredim tri različne datoteke, ali pa raje vse v eno spravim?

LP
alen
Če polžu ukradejo hišico, ... a je nag ali brezdomec?

Tody ::

Osti ja ... uporabi (st.koda) moja koda (/st.koda) stem da () zamenjaš z []

osti1 ::

Zanima me, kako naj naredim naslednje. Tole je search.php, iz katerega bi rad naredil povezavo ...?mode=edit&ID=|izbrani uporabnik| oz. ...?mode=delete&ID=|izbrani uporabnik| v contact.php (do sem sem prišel, pol se je pa ustavilo):

<?php
include('db_login.php');

$connection = mysql_connect($db_host, $db_username, $db_password);
if (!$connection) {
		die ("Could not connect to the database: <br />". mysql_error());
}

// izbira baze
$db_select = mysql_select_db($db_database);
if (!$db_select){
		die ("Could not select the database: <br />". mysql_error());
}

$rowsPerPage = 5;
$pageNum = 1;

if(isset($_GET['page'])) {
	$pageNum = $_GET['page'];
}

if(isset($_GET['search'])) {
	$search = $_GET['search'];

/*if(!$search) {
	echo "No search entered, please go back and fill in the fields properly.";
}*/
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;

$keywords = explode(" ", $search);

$query = "SELECT id,f_name,l_name,phone FROM stiki " . "WHERE l_name LIKE '%".$keywords['0']."%'";

for ($i=1; $i<count($keywords); $i++) {
	$query = $query." OR l_name LIKE '%".$keywords[$i]."%'";
}

$query = $query." ORDER BY l_name ASC LIMIT $offset, $rowsPerPage";

$result2 = mysql_query($query) or die(mysql_error());
?>
	<table align="center" bgcolor="#E1E5E7" width="800" border="1" cellspacing="0" cellpadding="0" >
  		<tr>
    		<td width="152" height="76"><img src="images/CDELogo1.gif"></td>
    		<td align="left" valign="bottom"><font color="#8A9297" size="+3">&nbsp;phonebook</font></td>
  		</tr>
  		<tr>
    		<td valign="top">
				<table width="152" border="0" cellspacing="0" cellpadding="0">
		  			<tr>
		    			<td><font color="#8A9297" size="+1">&nbsp;Menu</font></td>
		  			</tr>
		  			<tr>
		    			<td><font color="#8A9297" size="+1">&nbsp;<a href="contact.php">Add</a></font></td>
		  			</tr>
		  			<tr>
		    			<td><font color="#8A9297" size="+1">&nbsp;<a href="search.php">Search/Edit</a></font></td>
		  			</tr>
		  			<tr>
		    			<td>&nbsp;</td>
		  			</tr>
				</table>
			</td>
    		<td>
			<form method="GET" action="search_limited.php">
			<b>Search:</b>
			<input name="search" type="text" value="<?php echo $_GET['search']; ?>" size="20">
			<input type="submit" value="Search">
			</form>
				<table width="100%" style="border:1px solid #000000;">
<?php
$keywords = explode(" ", $search);

$query = "SELECT COUNT(id) AS numrows FROM stiki " . "WHERE l_name LIKE '%".$keywords['0']."%'";

for ($i=1; $i<count($keywords); $i++) {
	$query = $query." OR l_name LIKE '%".$keywords[$i]."%'";
	}

$result = mysql_query($query) or die('Error, query failed');
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav = '';

for($page = 1; $page <= $maxPage; $page++) {
		if ($page == $pageNum)
	{
		$nav .= " $page ";
	}
else
	{
		$nav .= " <a href=\"$self?page=$page&search=$search\">$page</a> ";
	}
}

// naprej, nazaj, prva, zadnja stran

if ($pageNum > 1) {

	$page = $pageNum - 1;
	$prev = " <a href=\"$self?page=$page&search=$search\">[Prev]</a> ";

	$first = " <a href=\"$self?page=1&search=$search\">[First Page]</a> ";
}
else {
	$prev = ' ';
	$first = ' ';
}

if ($pageNum < $maxPage) {
	$page = $pageNum + 1;
	$next = " <a href=\"$self?page=$page&search=$search\">[Next]</a> ";

	$last = " <a href=\"$self?page=$maxPage&search=$search\">[Last Page]</a> ";
}
else {
	$next = ' ';
	$last = ' ';
}

while($row = mysql_fetch_array($result2)) {

	echo "<tr>";
	echo "<td style='border-bottom: 1px solid #000000;'>";
	echo "<tr><td><a href=\"contact.php?mode=edit&id=$_POST[sel_id]\">".$row['f_name']."</a></td>" . "<td>".$row['l_name']."</td>" . "<td>".$row['phone']."</td></tr>";
	echo "</td>";
	echo "</tr>";
}

	// povezave za navigacijo
	echo "<tr>";
	echo "<td>";
	echo "<center>".$first . $prev . $nav . $next . $last."</center>";
	echo "</td>";
	echo "</tr>";

?>
				</table>
			</td>
		</tr>
	</td>
    </td>
  </tr>
</table>


In še contact.php:

<!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=iso-8859-2" />
<title>Contact</title>
</head>

<body>

<?php

if ( mode=="add")
{
echo "<table align=\"center\" bgcolor=\"#E1E5E7\" width=\"800\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >
  <tr>
    <td width=\"152\" height=\"76\"><img src=\"images/CDELogo1.gif\"></td>
    <td align=\"left\" valign=\"bottom\"><font color=\"#8A9297\" size=\"+3\">&nbsp;phonebook</font></td>
  </tr>
  <tr>
    <td valign=\"top\">
		<table width=\"152\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		  <tr>
		    <td><font color=\"#8A9297\" size=\"+1\">&nbsp;Menu</font></td>
		  </tr>
		  <tr>
		    <td><font color=\"#8A9297\" size=\"+1\">&nbsp;<a href=\"contact.php\"?mode=add>Add</a></font></td>
		  </tr>
		  <tr>
		    <td><font color=\"#8A9297\" size=\"+1\">&nbsp;<a href=\"search.php\">Search/Edit</a></font></td>
		  </tr>
		  <tr>
		    <td>&nbsp;</td>
		  </tr>
		</table>
	</td>
    <td>
		<form method=\"post\" action=\"contact.php\"?mode=add>
		<table width=\"648\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		  <tr>
   			  <td width=\"90\">&nbsp;</td>
   			<td width=\"558\"><font color=\"#8A9297\" size=\"+2\">Add</font></td>
		  </tr>
  			<tr>
    			<td>&nbsp;First Name</td>
    			<td><input type=\"text\" id=\"f_name\" name=\"f_name\" size=\"30\"></td>
  			</tr>
  			<tr>
    			<td>&nbsp;Last Name</td>
    			<td><input type=\"text\" id=\"l_name\" name=\"l_name\" size=\"45\"></td>
  			</tr>
  			<tr>
    			<td>&nbsp;Phone</td>
    			<td><input type=\"text\" id=\"phone\" name=\"phone\" size=\"50\"></td>
  			</tr>
  			<tr>
    			<td>&nbsp;</td>
    			<td align=\"right\"><input type=\"submit\" name=\"Submit\" value=\"Submit\"><input type=\"reset\" name=\"Reset\" value=\"Reset\">			
				</td>
  			</tr>
		</table>
		</form>
	</td>
  </tr>
</table>
";
}

if ( mode =="edit")
{
echo "<table align=\"center\" bgcolor=\"#E1E5E7\" width=\"800\" border=\"1\" cellspacing=\"0\" cellpadding=\"0\" >
  <tr>
    <td width=\"152\" height=\"76\"><img src=\"images/CDELogo1.gif\"></td>
    <td align=\"left\" valign=\"bottom\"><font color=\"#8A9297\" size=\"+3\">&nbsp;phonebook</font></td>
  </tr>
  <tr>
    <td valign=\"top\">
		<table width=\"152\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		  <tr>
		    <td><font color=\"#8A9297\" size=\"+1\">&nbsp;Menu</font></td>
		  </tr>
		  <tr>
		    <td><font color=\"#8A9297\" size=\"+1\">&nbsp;<a href=\"contact.php?mode=add\">Add</a></font></td>
		  </tr>
		  <tr>
		    <td><font color=\"#8A9297\" size=\"+1\">&nbsp;<a href=\"search.php\">Search/Edit</a></font></td>
		  </tr>
		  <tr>
		    <td>&nbsp;</td>
		  </tr>
		</table>
	</td>
    <td>
		<form method=\"post\" action=\"p_contact.php\">
		<table width=\"648\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
		  <tr>
   			  <td width=\"90\">&nbsp;</td>
   			<td width=\"558\"><font color=\"#8A9297\" size=\"+2\">Edit</font></td>
		  </tr>
  			<tr>
    			<td>&nbsp;First Name</td>
    			<td><input type=\"text\" id=\"f_name\" name=\"f_name\" size=\"30\"></td>
  			</tr>
  			<tr>
    			<td>&nbsp;Last Name</td>
    			<td><input type=\"text\" id=\"l_name\" name=\"l_name\" size=\"45\"></td>
  			</tr>
  			<tr>
    			<td>&nbsp;Phone</td>
    			<td><input type=\"text\" id=\"phone\" name=\"phone\" size=\"50\"></td>
  			</tr>
  			<tr>
    			<td>&nbsp;</td>
    			<td align=\"right\"><input type=\"submit\" name=\"Submit\" value=\"Submit\"><input type=\"reset\" name=\"Reset\" value=\"Reset\">			
				</td>
  			</tr>
		</table>
		</form>
	</td>
  </tr>
</table>
";
}

?>

</body>
</html>



~ popravil barvanje kode. hint: ce napises [st.koda php] se koda pobarva kot da gre za php / D.
Če polžu ukradejo hišico, ... a je nag ali brezdomec?

Zgodovina sprememb…



Vredno ogleda ...

TemaSporočilaOglediZadnje sporočilo
TemaSporočilaOglediZadnje sporočilo
»

html/PHP kontakt obrazec

Oddelek: Izdelava spletišč
192037 (1582) Netrunner
»

Rewrite URLja (apache)

Oddelek: Izdelava spletišč
8950 (870) levaky
»

PHP - nujno! - email forma

Oddelek: Izdelava spletišč
262025 (1707) DonMatejo
»

PHP KONTAKT

Oddelek: Izdelava spletišč
71497 (1334) rkasteli
»

pa spet PHP in MySQL... jao...

Oddelek: Izdelava spletišč
111211 (1036) cahahopie

Več podobnih tem