The ProgrammersTalk Community
Forum Register Search Today's Posts Mark Forums Read
Register

Go Back   The ProgrammersTalk Community > Web Programming > PHP


Welcome to the The ProgrammersTalk Community forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.
Reply
 
LinkBack Thread Tools    Display Modes   
  #1 (permalink)  
Old 11-03-2007, 04:33 PM
mikejkellyuk mikejkellyuk is offline
Novice
Join Date: Nov 2007
Posts: 8
iTrader: (0)
mikejkellyuk is on a distinguished road
can somebody tell me why this code is not working

hi can somebody tell me why this code is not working
thanks
mike
PHP Code:
<?php
if (!$_POST) {
   
//haven't seen the form, so show it
   
$display_block "
   <form method=\"post\" action=\""
.$_SERVER["PHP_SELF"]."\">
   <p><strong>First/Last Names:</strong><br/>
   <input type=\"text\" name=\"f_name\" size=\"30\" maxlength=\"75\">
   <input type=\"text\" name=\"l_name\" size=\"30\" maxlength=\"75\"></p>

   <p><strong>Address:</strong><br/>
   <input type=\"text\" name=\"address\" size=\"30\"></p>

   <p><strong>City/State/PostCode:</strong><br/>
   <input type=\"text\" name=\"city\" size=\"30\" maxlength=\"50\">
   <input type=\"text\" name=\"state\" size=\"5\" maxlength=\"2\">
   <input type=\"text\" name=\"postcode\" size=\"10\" maxlength=\10"
></p>

   <
p><strong>Address Type:</strong><br/>
   <
input type="radio\" name=\"add_type\" value=\"home\" checked> home
   <input type=\"radio\" name=\"add_type\" value=\"work\"> work
   <input type=\"radio\" name=\"add_type\" value=\"other\"> other</p>

   <p><strong>Telephone Number:</strong><br/>
   <input type=\"text\" name=\"tel_number\" size=\"30\" maxlength=\"25\">
   <input tupe=\"radio\" name=\"tel_type\" value=\"home\"checked> home
   <input type=\"radio\" name=\"tel_type\" value=\"work\"> work
   <inpur type=\"radio\" name=\"tel_type\" value=\"other\"> other</p>

   <p><strong>Fax Number:</strong><br/>
   <input type=\"text\" name=\"fax_number\" size=\"30\" maxlength=\"25\">
   <input type=\"radio\" name=\"fax_type\" value=\"home\"checked> home
   <input type=\"radio\" name=\"fax_type\" value=\"work\"> work
   <input type=\"radio\" name=\"fax_type\" value=\"other\"> other</p>

   <p><strong>Email Address:</strong><br/>
   <input type=\"text\" name=\"email\" size=\"30\" maxlength=\"25\">
   <input type=\"radio\" name=\"email_type\" value=\"home\"checked> home
   <input type=\"radio\" name=\"email_type\" value=\"work\"> work
   <input type=\"radio\" name=\"email_type\" value=\"other\"> other</p>

   <p><strong>Personal Notes:</strong><br/>
   <textarea name=\"note\" cols=\"35\" row=\"3\"
   wrap=\"virtual\"></textarea></p>

   <p><input type=\"submit\" name=\"submit\" value=\"Add Entry\"></p>
   </form>"
;

} else if (
$_POST) {
   
//time to add to tables, so check for required fields
   
if (($_POST["f_name"] == "") || ($_POST["l_name"] == "")) {
       
header("Location: addentry.php");
       exit;

    }

   
//connect to database
   
$mysqli mysqli_connect("localhost""root""michael1""addressbook");

  
//add to master name table
  
$add_master_sql "INSERT INTO master_name (date_added, date_modified,
                     f_name, l_name) VALUES (now(), now(),
                     '"
.$_POST["f_name"]."', '".$_POST["l_name"]."')";
  
$add_master_res mysqli_query($mysqli$add_master_sql)
                    or die(
mysqli_error($mysqli));
  
  
//get master_id for use with other tables
  
$master_id mysqli_insert_id($mysqli);

  if ((
$_POST["address"]) || ($_POST["city"]) || ($_POST["state"])
      || (
$_PORT["postcode"])) {
      
//something relevant so add to address table
     
$add_address_sql "INSERT INTO address (master_id, date_added,
                         date_modified, address, city, state, postcode,
                         type) VALUES ('"
.$master_id"', now(), now(),
                         '"
.$_POST["address"]."', '".$_POST["city"]."',
                         '"
.$_POST["state"]."', '".$_POST["postcode"]."',
                         '"
.$_POST["add_type"]."')";
  
$add_address_res mysqli_query($mysqli$add_address_sql)
                     or die(
mysqli_error($mysqli));

 }

  if (
$_POST["tel_number"]) {
     
//something relevant, so add to telephone table
     
$add_fax_sql "INSERT INTO fax (master_id, date_added,
                     date_modified, tel_number, type) VALUES
                     ('"
.$master_id."', now(), now(),
                     '"
.$_POST["tel_number"]."',
                     '"
.$_POST["tel_type"]."')";
     
$add_tel_res mysqli_query($mysqli$add_tel_sql)
                    or die(
mysqli_error($mysqli));

 }

  if (
$_POST["fax_number"]) {
      
//something relevant, so add to fax table
      
$add_fax_sql "INSERT INTO fax (master_id, date_added,
                      date_modified, fax_number, type) VALUES
                      ('"
.$master_id."', now(), now(),
                      '"
.$_POST["fax_number"]."',
                      '"
.$_POST["fax_type"]."')";
      
$add_fax_res mysqli_query($mysqli$add_fax_sql)
                     or die(
mysqli_error($mysqli));

 }
  
  if (
$_POST["email"]) {
      
//something relevant, so add to email table
      
$add_email_sql "INSERT INTO email (master_id, date_added,
                        date_modified, email, type) VALUES
                        ('"
.$master_id."', now(), now(),
                        '"
.$_POST["email"]."',
                        '"
.$_POST["email_type"]."')";
      
$add_email_res mysqli_query($mysqli$add_email_sql)
                       or die(
mysqli_error($mysqli));

 }

  if (
$_POST["note"]) {
      
//something relevant, so add to notes table
      
$add_notes_sql "INSERT INTO personal_notes (master_id, date_added,
                       date_modified, notes) VALUES ('"
.$master_id."',
                       now(), now(), '"
.$_POST["notes"]."')";
      
$add_notes_res mysqli_query($mysqli$add_notes_sql)
                       or die(
mysqli_error($mysqli));
 }
 
mysqli_close($mysqli);
 
$displayblock "<p>Your entry has been added.
 would you like to <a href=\"addentry.php\">add another</a>?</p>;
}
?>
<html>
<head>
<title>Add an Entry</title>
</head>
<body>
<h1>Add an Entry</h1>
<php echo $display_block; ?>
</body>
</html>

__________________

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!

Last edited by TeraTask : 11-03-2007 at 11:55 PM. Reason: Added code tags
Reply With Quote
  #2 (permalink)  
Old 11-03-2007, 11:44 PM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
I suggest you to also post the error messages if there's any.. and I think there is for this one so that it's easier for us to look for the problems...

I'd say that the first line of code:

PHP Code:
if (!$_POST) { 
As far that I know $_POST is supposed to be $_POST['variable']

In addition, please read:
Markup For Easy Reading

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #3 (permalink)  
Old 11-03-2007, 11:58 PM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 426
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Now that I've added in code tags, check where the color changes in an odd spot -- you'll notice some errors with escaping double quotes.

Also, you have $_PORT which will ultimately cause you problems.

Finally, you are not sanitizing your data, so your code is easily subject to SQL injection attacks!

HelloWorld:

What you mention is not an error, just not the best coding.
PHP Code:
if (!$_POST) { 

will function the same as
PHP Code:
if (!empty($_POST)) { 

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #4 (permalink)  
Old 11-04-2007, 12:17 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Moreover, I see that all of your mysql functions are called incorrectly...

PHP Code:
 mysqli_close($mysqli); 
Suppose to be:

PHP Code:
 mysql_close($mysqli); 

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #5 (permalink)  
Old 11-04-2007, 12:21 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 426
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Not to be constantly contradicting you, HelloWorld, but that call is correct. The mysqli functions allow access to the "improved" functions for MySQL 5.x which are not available through simply calling mysql. See PHP: MySQL Improved Extension - Manual for more information.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
The Following User Says Thank You to TeraTask For This Useful Post:
HelloWorld (11-04-2007)
  #6 (permalink)  
Old 11-04-2007, 01:09 AM
HelloWorld's Avatar
HelloWorld HelloWorld is offline
Programming Expert
Awards Showcase
Quality Tutorial 
Total Awards: 1
Join Date: Jun 2007
Location: In front of computer...
Posts: 1,111
iTrader: (0)
HelloWorld will become famous soon enoughHelloWorld will become famous soon enoughHelloWorld will become famous soon enough
Thanx TeraTask, and I'm sorry for the poor advices..

__________________
PHP Code:
System.out.println("Hello World!"); 

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
  #7 (permalink)  
Old 11-04-2007, 01:13 AM
TeraTask's Avatar
TeraTask TeraTask is offline
PT Staff*
Awards Showcase
Quality Tutorial Quality Tutorial Quality Tutorial 
Total Awards: 3
Join Date: Jun 2007
Location: Reno, NV
Posts: 426
iTrader: (0)
TeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enoughTeraTask will become famous soon enough
Quote:
Originally Posted by HelloWorld View Post
Thanx TeraTask, and I'm sorry for the poor advices..
No worries! You're still learning PHP anyway and for a noob, you do well.

__________________
Jeremy Miller
Content Farmer - Optimized Automated Blog Posting

Digg this Post! Del.Icio.Us this Post! Technorati this Post! Furl this Post! Mister Wong this Post! Newsvine this Post! Spurl this Post! Reddit this Post! Netscape this Post!
Reply With Quote
Reply


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

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



All times are GMT -7. The time now is 12:22 AM. Powered by vBulletin
Copyright © 2000 - 2007, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO © 2007 ProgrammersTalk Sedo - Buy and Sell Domain Names and Websites project info: programmerstalk.net Statistics for project programmerstalk.net etracker® web controlling instead of log file analysis


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50