Updating information in database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

bobby
Forum Commoner
Posts: 27
Joined: Sat Oct 04, 2003 4:00 pm
Location: usa
Contact:

Post by bobby »

Hi sorry to be a pain, but does anyone know any other good websites to post php questions. or anywhere else on the www to get php support.

Thanks
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post by McGruff »

This is a good site, particularly the advanced php forums: http://www.sitepointforums.com/index.php.

Maybe I'm not an impartial judge but I think phpdn is the best place on the net for newbie or intermediate queries. Were you having trouble getting an answer for a problem?
Linkjames
Forum Commoner
Posts: 90
Joined: Tue Sep 16, 2003 8:39 am

Post by Linkjames »

Just a tip. If you use [ php ] tags rather than [ code ] tags, your code will be php colour highlighted, which makes it easier to read (For me anyway) For example, your above code would display as

Code: Select all

<?php 
include("C:\Program Files\Apache Group\Apache2\htdocs\db_password.inc"); 
mysql_connect($hostname, $user, $password); 
mysql_select_db("weblogs"); 

// Validate this user 
$test_username = $_POST['test_username']; 
$query = "SELECT password 
          FROM login 
          WHERE username = '$test_username'"; 
$result = mysql_query($query); 
if (mysql_num_rows($result) != 1) { 
  echo "Something is wrong"; 
  exit; 
} 
$password_row = mysql_fetch_array($result); 
$db_password = $password_row[0]; 

if ($_POST['test_password'] == $db_password && $_POST['test_password'] != "") { 
  if ($_POST['Submit'] == 'Enter') { 
   // Insert edited entry 
    $edit_date = $_POST['edit_date']; 
    // Escape single-quotes and apostrophes 
    $blogtext = addslashes($_POST['blogtext']); 
    $query = "UPDATE mylog SET blogtext = '$blogtext' WHERE date = '$edit_date'"; 
    echo mysql_errno() . ": ". mysql_error(). "\n" ; 
    $result = mysql_query($query); 
    if (mysql_affected_rows() == 0) { 
      header("Location: db_login.php"); 
    } else { 
      echo "There was a problem inserting your text."; 
      exit; 



    } 
  } else { 
    // Show the form with the appropriate entry filled in 
    $php_self = $_SERVER['PHP_SELF']; 
    $test_password = $_POST['test_password']; 
    $edit_date = $_POST['edit_date']; 
    $query = "SELECT blogtext FROM mylog WHERE date = $edit_date"; 
    $result = mysql_query($query); 
    if (mysql_num_rows($result) == 0) { 
      echo "No entry matches that date"; 
      exit; 
    } 
    $entry_row = mysql_fetch_array($result); 
    // When you get text from a SQL database, 
    // you may need to strip backslashes from single-quotes. 
    $blogtext = stripslashes($entry_row[0]); 

$form_str = <<< EOFORMSTR 
<HTML> 
<HEAD> 
<TITLE>Weblog data edit screen</TITLE> 
</HEAD> 
<BODY> 
<FORM ACTION="$php_self" METHOD="POST"> 
<P>Text:<BR><TEXTAREA NAME="blogtext" COLS=75 ROWS=20 WRAP="VIRTUAL">$blogtext</TEXTAREA></P> 
<INPUT TYPE="hidden" NAME="test_username" VALUE="$test_username"> 
<INPUT TYPE="hidden" NAME="test_password" VALUE="$test_password"> 
<INPUT TYPE="hidden" NAME="edit_date" VALUE="$edit_date"> 
<P><INPUT TYPE="SUBMIT" NAME="Submit" VALUE="Enter"></P> 
</FORM> 
</BODY> 
</HTML> 
EOFORMSTR; 
    echo $form_str; 
  } 
} else { 
  mail("me@localhost", "Weblog snoop", "Someone from $REMOTE_ADDR is trying to get into your weblog entry screen."); 
} 
?>
bobby
Forum Commoner
Posts: 27
Joined: Sat Oct 04, 2003 4:00 pm
Location: usa
Contact:

Post by bobby »

Ok thanks for the tips guys much appreciated


Hope someone out there can help

bye for now
Post Reply