if varible set, if not get

  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

okay i have this script that lets you modify/update information in a database, why eather going to the page or by going to the page where the info is desplayed and click a link witch will take you to the page to modify... confusing i know look over this script to understand it more ill say more below

PHP Code: [ Select ]
<?
 
if(!$user) {
 
   $user = $usercook;
 
   $pass = $passcook;
 
}
 
setcookie("usercook", "$user");
 
setcookie("passcook", "$pass");
 
 
 
require("functions.php");
 
include("header.php");
 
?>
 
<?
 
include("html_head.php");
 
if($rank >= 1) {
 
if(isset($id)) {
 
$result = @mysql_query("SELECT * FROM shows WHERE id = '$id'");
 
  $row = mysql_fetch_array($result);
 
  extract($row);
 
  $venu = $row[venu];
 
  $timedate = $row[timedate];
 
  $age = $row[age];
 
  $cost = $row[cost];
 
  $lineup = $row[lineup];
 
  $poster = $row[poster];
 
  $info = $row[info];
 
echo("
 
<form method='post' action='modshow.php'>
 
<input type='hidden'name='id' value='$id'>
 
 Venu:
 
 <input type='text' name='venu' value='$venu'>
 
 <br>
 
 Time/date:
 
 <input type='text' name='timedate' value='$timedate'>
 
 <br>
 
 Age:
 
 <select name='age'  value='$age'>
 
 <option>- Select -</option>
 
 <option value='All Age'>All Ages</option>
 
 <option value='21+'>21+</option>
 
 </select>
 
 <br>
 
 Cost:
 
 <input type='text' name='cost' value='$cost'>
 
 <br>
 
 Line up:
 
 <input type='text' name='lineup' value='$lineup'>
 
 <br>
 
 Poster:
 
 <select name='poster' value='$poster'>
 
 ");
 
      UploadDis(poster);
 
  echo("
 
 </select>
 
 <br>
 
 Info: <br>
 
 <textarea name='info' cols='45' rows='10'>$info</textarea>
 
 <br>
 
 <input type='submit' name='Submit' value='Submit'>
 
</form>
 
 ");
 
  }
 
 else {
 
 if(empty($id)) {
 
echo("
 
<form method='post' action='mod_show.php?id=$id'>
 
<select name='id_select'>
 
");
 
Select($id_select);
 
echo("
 
</select>
 
<input type=submit value=Submit>
 
</form>
 
");
 
}
 
}
 
}
 
   include("html_foot.php");
 
  ?>
  1. <?
  2.  
  3. if(!$user) {
  4.  
  5.    $user = $usercook;
  6.  
  7.    $pass = $passcook;
  8.  
  9. }
  10.  
  11. setcookie("usercook", "$user");
  12.  
  13. setcookie("passcook", "$pass");
  14.  
  15.  
  16.  
  17. require("functions.php");
  18.  
  19. include("header.php");
  20.  
  21. ?>
  22.  
  23. <?
  24.  
  25. include("html_head.php");
  26.  
  27. if($rank >= 1) {
  28.  
  29. if(isset($id)) {
  30.  
  31. $result = @mysql_query("SELECT * FROM shows WHERE id = '$id'");
  32.  
  33.   $row = mysql_fetch_array($result);
  34.  
  35.   extract($row);
  36.  
  37.   $venu = $row[venu];
  38.  
  39.   $timedate = $row[timedate];
  40.  
  41.   $age = $row[age];
  42.  
  43.   $cost = $row[cost];
  44.  
  45.   $lineup = $row[lineup];
  46.  
  47.   $poster = $row[poster];
  48.  
  49.   $info = $row[info];
  50.  
  51. echo("
  52.  
  53. <form method='post' action='modshow.php'>
  54.  
  55. <input type='hidden'name='id' value='$id'>
  56.  
  57.  Venu:
  58.  
  59.  <input type='text' name='venu' value='$venu'>
  60.  
  61.  <br>
  62.  
  63.  Time/date:
  64.  
  65.  <input type='text' name='timedate' value='$timedate'>
  66.  
  67.  <br>
  68.  
  69.  Age:
  70.  
  71.  <select name='age'  value='$age'>
  72.  
  73.  <option>- Select -</option>
  74.  
  75.  <option value='All Age'>All Ages</option>
  76.  
  77.  <option value='21+'>21+</option>
  78.  
  79.  </select>
  80.  
  81.  <br>
  82.  
  83.  Cost:
  84.  
  85.  <input type='text' name='cost' value='$cost'>
  86.  
  87.  <br>
  88.  
  89.  Line up:
  90.  
  91.  <input type='text' name='lineup' value='$lineup'>
  92.  
  93.  <br>
  94.  
  95.  Poster:
  96.  
  97.  <select name='poster' value='$poster'>
  98.  
  99.  ");
  100.  
  101.       UploadDis(poster);
  102.  
  103.   echo("
  104.  
  105.  </select>
  106.  
  107.  <br>
  108.  
  109.  Info: <br>
  110.  
  111.  <textarea name='info' cols='45' rows='10'>$info</textarea>
  112.  
  113.  <br>
  114.  
  115.  <input type='submit' name='Submit' value='Submit'>
  116.  
  117. </form>
  118.  
  119.  ");
  120.  
  121.   }
  122.  
  123.  else {
  124.  
  125.  if(empty($id)) {
  126.  
  127. echo("
  128.  
  129. <form method='post' action='mod_show.php?id=$id'>
  130.  
  131. <select name='id_select'>
  132.  
  133. ");
  134.  
  135. Select($id_select);
  136.  
  137. echo("
  138.  
  139. </select>
  140.  
  141. <input type=submit value=Submit>
  142.  
  143. </form>
  144.  
  145. ");
  146.  
  147. }
  148.  
  149. }
  150.  
  151. }
  152.  
  153.    include("html_foot.php");
  154.  
  155.   ?>


this page is called mod_show.php
there is a page called shows.php witch desplays the information in the database.

//shows.php function
PHP Code: [ Select ]
function DisShow($user, $rank) {
 
 
 
 $result = @mysql_query("SELECT * FROM shows WHERE disable = 0 ORDER BY id DESC");
 
  while ($row = mysql_fetch_array($result)) {
 
  $id = $row[id];
 
echo("
 
<table width='500' border='1' cellspacing='1' bordercolor='#333333' bgcolor='#666666'>
 
 <tr>
 
   <td width='35%' bgcolor='#000000'>Venu:$row[venu]</td>
 
   <td width='65%'  bgcolor='#000000' rowspan='5' valign='top'>Linup:<br>
 
      $row[lineup]<br><br>$row[info]</td>
 
 </tr>
 
 <tr>
 
   <td bgcolor='#000000'>Time/Date:$row[timedate]</td>
 
 </tr>
 
 <tr>
 
   <td bgcolor='#000000'>Age:$row[age]</td>
 
 </tr>
 
 <tr>
 
   <td bgcolor='#000000'>Cost:$row[cost]</td>
 
 </tr>
 
 <tr>
 
   <td bgcolor='#000000'><a href='$row[poster]'>Banner</a></td>
 
 </tr>
 
 <tr>
 
   <td>
 
   ");
 
   if($rank >= 1) {
 
      echo("
 
         <center>
 
         <a href=mod_show.php?id=$id>Modify</a>
 
      ");
 
     }
 
     echo("
 
      </td><td width=33%>
 
     ");
 
     if($rank >= 1) {
 
      echo("
 
         <center>
 
         <a href=remove_show.php?id=$id>Delete</a>
 
      ");
 
      }
 
     echo("
 
     </td>
 
     </tr>
 
</table>
 
<br>
 
<br>
 
");
 
}
 
}
 
 
  1. function DisShow($user, $rank) {
  2.  
  3.  
  4.  
  5.  $result = @mysql_query("SELECT * FROM shows WHERE disable = 0 ORDER BY id DESC");
  6.  
  7.   while ($row = mysql_fetch_array($result)) {
  8.  
  9.   $id = $row[id];
  10.  
  11. echo("
  12.  
  13. <table width='500' border='1' cellspacing='1' bordercolor='#333333' bgcolor='#666666'>
  14.  
  15.  <tr>
  16.  
  17.    <td width='35%' bgcolor='#000000'>Venu:$row[venu]</td>
  18.  
  19.    <td width='65%'  bgcolor='#000000' rowspan='5' valign='top'>Linup:<br>
  20.  
  21.       $row[lineup]<br><br>$row[info]</td>
  22.  
  23.  </tr>
  24.  
  25.  <tr>
  26.  
  27.    <td bgcolor='#000000'>Time/Date:$row[timedate]</td>
  28.  
  29.  </tr>
  30.  
  31.  <tr>
  32.  
  33.    <td bgcolor='#000000'>Age:$row[age]</td>
  34.  
  35.  </tr>
  36.  
  37.  <tr>
  38.  
  39.    <td bgcolor='#000000'>Cost:$row[cost]</td>
  40.  
  41.  </tr>
  42.  
  43.  <tr>
  44.  
  45.    <td bgcolor='#000000'><a href='$row[poster]'>Banner</a></td>
  46.  
  47.  </tr>
  48.  
  49.  <tr>
  50.  
  51.    <td>
  52.  
  53.    ");
  54.  
  55.    if($rank >= 1) {
  56.  
  57.       echo("
  58.  
  59.          <center>
  60.  
  61.          <a href=mod_show.php?id=$id>Modify</a>
  62.  
  63.       ");
  64.  
  65.      }
  66.  
  67.      echo("
  68.  
  69.       </td><td width=33%>
  70.  
  71.      ");
  72.  
  73.      if($rank >= 1) {
  74.  
  75.       echo("
  76.  
  77.          <center>
  78.  
  79.          <a href=remove_show.php?id=$id>Delete</a>
  80.  
  81.       ");
  82.  
  83.       }
  84.  
  85.      echo("
  86.  
  87.      </td>
  88.  
  89.      </tr>
  90.  
  91. </table>
  92.  
  93. <br>
  94.  
  95. <br>
  96.  
  97. ");
  98.  
  99. }
  100.  
  101. }
  102.  
  103.  

now what happens is no matter what $id is set to it always brings up this one row witch happens to be row 1, id 1 and no matter what i do it keeps doing it. if you can help me that would be great!

heres the other funcion

//selectshow
PHP Code: [ Select ]
function SelectShow($id) {
 
 $result = @mysql_query("SELECT * FROM shows WHERE id = '$id' AND disable = '0'");
 
  while ($row = mysql_fetch_array($result)) {
 
  echo("
 
 <option value='$row[id]'>$row[timedate]</option>
 
");
 
}
 
}
  1. function SelectShow($id) {
  2.  
  3.  $result = @mysql_query("SELECT * FROM shows WHERE id = '$id' AND disable = '0'");
  4.  
  5.   while ($row = mysql_fetch_array($result)) {
  6.  
  7.   echo("
  8.  
  9.  <option value='$row[id]'>$row[timedate]</option>
  10.  
  11. ");
  12.  
  13. }
  14.  
  15. }
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

When you are selecting the show, how many are you trying to get? If you only one, you don't need to use the while statement.
Also if you do not have register_globals turned on you need to change $id to $_GET[id].
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

Scorpius wrote:
When you are selecting the show, how many are you trying to get? If you only one, you don't need to use the while statement.
Also if you do not have register_globals turned on you need to change $id to $_GET[id].


Edit on the id:
Slightly wrong - $_GET['id'] (don't forget the single quotes)

If I am wrong please tell me as everytime I have tried it the other way I receive an error.

Also when struggling with a SQL query i usually echo the query and try it through phpMyAdmin or MySQL Control Center.

The @ symbol is forcing mysql to fail silently and if you remove it you might get a string of really useful error messages
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

if your talking about the while in the selectshow function, it is getting more than 1 row from the database. the function lets you select the show you want to edit from the database
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Rabid Dog wrote:
Scorpius wrote:
When you are selecting the show, how many are you trying to get? If you only one, you don't need to use the while statement.
Also if you do not have register_globals turned on you need to change $id to $_GET[id].


Edit on the id:
Slightly wrong - $_GET['id'] (don't forget the single quotes)

If I am wrong please tell me as everytime I have tried it the other way I receive an error.

Also when struggling with a SQL query i usually echo the query and try it through phpMyAdmin or MySQL Control Center.

The @ symbol is forcing mysql to fail silently and if you remove it you might get a string of really useful error messages

Well RabidDog what you show'd will also work but from what I've seen and done they are not required as long as you are using it in an echo or in a MySQL query.
For Example:
PHP Code: [ Select ]
$id = $_GET[id];  // would not work you need the single quotes.
 
$id = $_GET['id']; // works just fine
 
echo "Your id is: $_GET[id]"; // works
 
echo "Your id is: $_GET['id']"; // should work but if you test it
 
//you will get an error like. Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in file.php on line 11
  1. $id = $_GET[id];  // would not work you need the single quotes.
  2.  
  3. $id = $_GET['id']; // works just fine
  4.  
  5. echo "Your id is: $_GET[id]"; // works
  6.  
  7. echo "Your id is: $_GET['id']"; // should work but if you test it
  8.  
  9. //you will get an error like. Parse error: parse error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in file.php on line 11

So, if he were to set $id = $_GET['id'] then the problem would be gone.

Also have you checked if you have register_globals on?
  • SpooF
  • ٩๏̯͡๏۶
  • Bronze Member
  • User avatar
  • Posts: 3422
  • Loc: Richland, WA

Post 3+ Months Ago

how would i do that?
im a noob at php and such i just can do things lol
  • Rabid Dog
  • Web Master
  • Web Master
  • User avatar
  • Posts: 3245
  • Loc: South Africa

Post 3+ Months Ago

If you are running windows look for a php.ini file under your windows or WINNT directory.

Open this file and keep scrolling until you find a value that says
register_globals.

If you are running PHP 4.2 or higher this value will be set to false by default. So if you haven't edited the above mentioned file and are running that version of PHP don't worry about looking for it.

An easy way to view your config is to create a php file with a call to the function phpInfo().

Call that page and bang, all your php config settings are shown

Did you echo your SQL query and remove the @ symbol? Any helpful error messages?

//Scorpius thanks for clearing that up.

Post Information

  • Total Posts in this topic: 7 posts
  • Users browsing this forum: No registered users and 71 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.