Current location: Hot Scripts Forums » Programming Languages » PHP » Global_variable off?


Global_variable off?

Reply
  #1 (permalink)  
Old 10-03-03, 02:33 PM
eddyvlad eddyvlad is offline
Wannabe Coder
 
Join Date: Sep 2003
Location: In The Bloody Pits Of Hell
Posts: 160
Thanks: 2
Thanked 0 Times in 0 Posts
Global_variable off?

I just upgraded my PHP and ohh boy.. They turned off the global variable and now I get lots and lots of Undefined Variable. I don't want to turn it back on coz I'm aware of the security issue. So... Umm. How do I make my code compatible with the global variable turned off?

My code is messy isn't it?
I only had 1months experience in PHP and i'm still learning.. So pls bear with me.
PHP Code:

$username="default";

$password="shibby";
$database="dude";

###############################################
mysql_connect('localhost',$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if($_POST['submit']){ 
    $insert = "INSERT INTO journal (date,time,content) VALUES ('$date','$time','$content')";
    mysql_query($insert);
}
elseif($update){
    $update = "UPDATE journal SET date='$date', time='$time', content='$content' WHERE id='$id'";
    mysql_query($update);
}
elseif($action == "del"){
    $delete = "DELETE FROM journal WHERE id='$id'";
    mysql_query($delete);
}

#####################################################
if($action == "edit"){

    $edit = "SELECT * FROM journal WHERE id='$id'";
    $edit_result = mysql_query($edit);
    $edit_rows = MySQL_fetch_array($edit_result);

    $the_id = $edit_rows['id'];
    $the_date = $edit_rows['date'];
    $the_time = $edit_rows ['time'];
    $the_content = $edit_rows ['content'];
}
else{
    $the_time = date("g.i:s a", time());
    $the_date = date("l, d F Y");
}

###############################################################

?>
<body bgcolor="#000000" background="images/solitary_03.jpg" leftmargin="4" topmargin="8" marginwidth="0" marginheight="0">
<p align="center" class="title">Journal</p>
<!--- Start Form --->
<form method="post" action="<? echo $PHP_SELF?>">
<input name="id" type="hidden" value="<? echo $id?>">
<table border="0" cellpadding="0" cellspacing="0">
  <tr> 
    <td class="name" align="right" valign="top">Date:</td>
    <td>
        <input name="date" type="text" value="<? echo $the_date?>" size="40" maxlength="50">
      </td>
  </tr>
  <tr> 
    <td class="name" align="right" valign="top">Time:</td>
    <td><input name="time" type="text" value="<? echo $the_time?>" size="40" maxlength="10"></td>
  </tr>
  <tr> 
    <td class="name" align="right" valign="top">Content:</td>
    <td><textarea name="content" cols="50" rows="8"><? echo $the_content?></textarea></td>
  </tr>
  <tr> 
    <td align="right" valign="top">&nbsp</td>
    <td>
<?
if (!$edit){
echo 
"<input name=\"submit\" type=\"submit\" value=\"Submit\">";
}
else{
echo 
"<input name=\"update\" type=\"submit\" value=\"Edit\">";
}
?>
    </td>
  </tr>
</table>
</form>
<?

$select 
"SELECT * FROM journal order by id desc";
$result mysql_query($select);

While( 
$rows MySQL_fetch_array($result) ) {
$id $rows['id'];
$date $rows['date'];
$time $rows ['time'];
$content $rows ['content'];

$content str_replace("\n""<br>"$content);

echo 
"<p><span class=\"subtitle\">$date<br>";
echo 
"$time</span><br>"
echo 
"$content<br>";
echo 
"<a href=\"?action=edit&id=$id\">Edit</a> || <a href=\"?action=del&id=$id\">Delete</a></p>";

}
mysql_close();
?>
Thanks for you help
Reply With Quote
  #2 (permalink)  
Old 10-03-03, 02:55 PM
YourPHPPro's Avatar
YourPHPPro YourPHPPro is offline
Community VIP
 
Join Date: Aug 2003
Posts: 430
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
and now I get lots and lots of Undefined Variable.
Feel free to list the errors that you are getting...
Reply With Quote
  #3 (permalink)  
Old 10-03-03, 02:57 PM
Chroder Chroder is offline
Newbie Coder
 
Join Date: Sep 2003
Location: Toronto, Ontario
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Turn all the values you got from post forms into $_POST['fieldname'], all values from a query string into $_GET['somename'], session vars come from $_SESSION, cookies form $_COOKIE...

http://ca2.php.net/variables.predefined
__________________
DevBox.net | DevBoxForums.com
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 06:29 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.