Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Anyone See A Problem With this code?
Old 03-05-2008, 11:59 PM Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
PHP Code:
<?
include ("include/header.inc.php");
?>

 <h1>Edit / add address book entry</h1> 
  <?php
include("include/dbconnect.php");
if(
$submit)
{

$sql "INSERT INTO $table (firstname, lastname, address, home, mobile, work, email, email2, bday, bmonth, byear) VALUES ('$firstname','$lastname','$address','$home','$mobile','$work','$email','$email2','$bday','$bmonth','$byear')";
$result mysql_query($sql);
echo 
"<br><br>Information entered into address book.\n";
}
else if(
$update)
{
$sql "UPDATE $table SET firstname='$firstname',lastname='$lastname',address='$address',home='$home',mobile='$mobile',work='$work',email='$email',email2='$email2',bday='$bday',bmonth='$bmonth',byear='$byear' WHERE id=$id";
$result mysql_query($sql);
echo 
"<br><br>Address book updated.\n";
}
else if(
$id)
{
$result mysql_query("SELECT * FROM $table WHERE id=$id",$db);
$myrow mysql_fetch_array($result);
?>
  <form method="post" action="edit.php">
    
  <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
        Firstname: </td>
      <td> 
        <input type="Text" name="firstname" size="35" value="<?php echo $myrow["firstname"]?>">
      </td>
    </tr>
    <tr> 
      <td>Lastname:</td>
      <td> 
        <input type="Text" name="lastname" size="35" value="<?php echo $myrow["lastname"]?>">
      </td>
    </tr>
    <tr> 
      <td>Address: </td>
      <td> 
        <textarea name="address" rows="5" cols="35"><?php echo $myrow["address"]?></textarea>
      </td>
    </tr>
    <tr> 
      <td>Telephone:</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Home:</td>
      <td> 
        <input type="Text" name="home" value="<?php echo $myrow["home"]?>">
      </td>
    </tr>
    <tr> 
      <td>Mobile:</td>
      <td> 
        <input type="Text" name="mobile" value="<?php echo $myrow["mobile"]?>">
      </td>
    </tr>
    <tr> 
      <td>Work: </td>
      <td> 
        <input type="Text" name="work" value="<?php echo $myrow["work"]?>">
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Email:</td>
      <td> 
        <input type="Text" name="email" size="35" value="<?php echo $myrow["email"]?>">
      </td>
    </tr>
    <tr> 
      <td>Email2:</td>
      <td> 
        <input type="Text" name="email2" size="35" value="<?php echo $myrow["email2"]?>">
      </td>
    </tr>
    <tr> 
      <td>Birthday:</td>
      <td> 
        <select name="bday">
    <option value="<?php echo $myrow["bday"]?>" selected><?php echo $myrow["bday"]?></option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="bmonth">
          <option value="<?php echo $myrow["bmonth"]?>" selected><?php echo $myrow["bmonth"]?></option>
          <option value="January" selected>January</option>
          <option value="February">February</option>
          <option value="March">March</option>
          <option value="April">April</option>
          <option value="May">May</option>
          <option value="June">June</option>
          <option value="July">July</option>
          <option value="August">August</option>
          <option value="September">September</option>
          <option value="October">October</option>
          <option value="November">November</option>
          <option value="December">December</option>
        </select>
        <input type="text" name="byear" size="4" maxlength="4" value="<?php echo $myrow["byear"]?>">
      </td>
    </tr>
  </table>
    <input type="Submit" name="update" value="Update information">
  </form>
  <?

}
else
{
?>
  <form method="post" action="<?php echo $PHP_SELF?>">
    
  <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
        Firstname:</td>
      <td> 
        <input type="Text" name="firstname" size="35">
      </td>
    </tr>
    <tr> 
      <td>Lastname: </td>
      <td> 
        <input type="Text" name="lastname" size="35">
      </td>
    </tr>
    <tr> 
      <td>Address: </td>
      <td> 
        <textarea name="address" rows="5" cols="35"></textarea>
      </td>
    </tr>
    <tr> 
      <td>Telephone:</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Home:</td>
      <td> 
        <input type="Text" name="home">
      </td>
    </tr>
    <tr> 
      <td>Mobile: </td>
      <td> 
        <input type="Text" name="mobile">
      </td>
    </tr>
    <tr> 
      <td>Work:</td>
      <td> 
        <input type="Text" name="work">
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Email: </td>
      <td> 
        <input type="Text" name="email" size="35">
      </td>
    </tr>
    <tr> 
      <td>Email2: </td>
      <td> 
        <input type="Text" name="email2" size="35">
      </td>
    </tr>
    <tr>
      <td>Birthday:</td>
      <td>
        <select name="bday">
          <option value="1" selected>1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="bmonth">
          <option value="January" selected>January</option>
          <option value="February">February</option>
          <option value="March">March</option>
          <option value="April">April</option>
          <option value="May">May</option>
          <option value="June">June</option>
          <option value="July">July</option>
          <option value="August">August</option>
          <option value="September">September</option>
          <option value="October">October</option>
          <option value="November">November</option>
          <option value="December">December</option>
        </select>
        <input type="text" name="byear" size="4" maxlength="4">
      </td>
    </tr>
  </table>
    <input type="Submit" name="submit" value="Enter information">
  </form>
<?
}

include (
"include/footer.inc.php");
?>
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
 
Register now for full access!
Old 03-06-2008, 12:22 AM Re: Anyone See A Problem With this code?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
I see many problems because there are many vars used that are not declared in the above example. I assume that the includes is taking care of that part ?

What problems are you looking for? Are you experiencing error messages?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-06-2008, 12:35 AM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
yes...the includes are linking to my db login info...

I am not getting errors but on submit none of the data will enter into the database...I have used this script with my old hosting company and its worked fine but I have changed hosts and nothing i do seems to work...

FYI: I found this script a frew years back....made a few changes to fit the needs of my site and was working for a few years....uploaded the script to my new hosting company and it did not work. Found the script again online and just loaded it up as is to see if i messed it up with all my changes...still nothing...

new host in hostmonster if that hepls any...I have had problems with other scripts with them too...
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-06-2008, 12:39 AM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
not trying to spam....but here is the link if you want to see the script in action

http://www.nwabars.com/bars/edit.php
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-06-2008, 12:46 AM Re: Anyone See A Problem With this code?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Probably the host has upgraded the PHP version and/or has disabled the option to register globals (which is better for more secure site).

So in your line:
if ($submit)

probably will require:
if ($_POST['submit'])

Use the superglobals instead. You will need to make changes like this throughout.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-06-2008, 12:50 AM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
I will try that out and let you know how it works out....thanks
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-08-2008, 09:10 PM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
OK..i had a moment to work on this today and I am still a bit lost. I can enter data into the DB but I am having a problem with updating the the data. before it would pull the data fron the db into my input boxes. I am not sure how to query this the right way....

PS: just looking for a push in the right direction so I can learn...please do not re-write it for me...i will get lazy



PHP Code:
<?
include ("include/header.inc.php");
?>

 <h1>Edit / add address book entry</h1> 
  <?php
include("include/dbconnect.php");
if (
$_POST['submit'])
{

$sql "INSERT INTO $table (firstname, lastname, address, home, mobile, work, email, email2, bday, bmonth, byear) VALUES 

('
{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['address']}','{$_POST['home']}','{$_POST['mobile']}','{$_POST['work']}','{$_POST['email']}','{$_POST['email2']}','{$_POST['bday']}','{$_POST['bmonth']}','{$_POST['byear']}')";
$result mysql_query ($sql);
echo 
"<br><br>Information entered into address book.\n";
}
else if (
$_POST['update'])
{
$sql "UPDATE $table SET firstname='$firstname',lastname='$lastname',address='$address',home='$home',mobile='$mobile',work='$work',email='$email',email2='$email2',bday='$bday',bmonth='$bmonth',byear='$byear' WHERE id=$id";
$result mysql_query($sql);
echo 
"<br><br>Address book updated.\n";


}
else if (
$_POST['id'])
{
$result mysql_query("SELECT * FROM $table WHERE id=$id",$db);
$myrow mysql_fetch_array($result);
?>
  <form method="post" action="edit.php">
    
  <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
        Firstname: </td>
      <td> 
        <input type="Text" name="firstname" size="35" value="<?php echo $myrow["firstname"]?>">
      </td>
    </tr>
    <tr> 
      <td>Lastname:</td>
      <td> 
        <input type="Text" name="lastname" size="35" value="<?php echo $myrow["lastname"]?>">
      </td>
    </tr>
    <tr> 
      <td>Address: </td>
      <td> 
        <textarea name="address" rows="5" cols="35"><?php echo $myrow["address"]?></textarea>
      </td>
    </tr>
    <tr> 
      <td>Telephone:</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Home:</td>
      <td> 
        <input type="Text" name="home" value="<?php echo $myrow["home"]?>">
      </td>
    </tr>
    <tr> 
      <td>Mobile:</td>
      <td> 
        <input type="Text" name="mobile" value="<?php echo $myrow["mobile"]?>">
      </td>
    </tr>
    <tr> 
      <td>Work: </td>
      <td> 
        <input type="Text" name="work" value="<?php echo $myrow["work"]?>">
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Email:</td>
      <td> 
        <input type="Text" name="email" size="35" value="<?php echo $myrow["email"]?>">
      </td>
    </tr>
    <tr> 
      <td>Email2:</td>
      <td> 
        <input type="Text" name="email2" size="35" value="<?php echo $myrow["email2"]?>">
      </td>
    </tr>
    <tr> 
      <td>Birthday:</td>
      <td> 
        <select name="bday">
    <option value="<?php echo $myrow["bday"]?>" selected><?php echo $myrow["bday"]?></option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="bmonth">
          <option value="<?php echo $myrow["bmonth"]?>" selected><?php echo $myrow["bmonth"]?></option>
          <option value="January" selected>January</option>
          <option value="February">February</option>
          <option value="March">March</option>
          <option value="April">April</option>
          <option value="May">May</option>
          <option value="June">June</option>
          <option value="July">July</option>
          <option value="August">August</option>
          <option value="September">September</option>
          <option value="October">October</option>
          <option value="November">November</option>
          <option value="December">December</option>
        </select>
        <input type="text" name="byear" size="4" maxlength="4" value="<?php echo $myrow["byear"]?>">
      </td>
    </tr>
  </table>
    <input type="Submit" name="update" value="Update information">
  </form>
  <?

}
else
{
?>
  <form method="post" action="<?php echo $PHP_SELF?>">
    
  <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
        Firstname:</td>
      <td> 
        <input type="Text" name="firstname" size="35">
      </td>
    </tr>
    <tr> 
      <td>Lastname: </td>
      <td> 
        <input type="Text" name="lastname" size="35">
      </td>
    </tr>
    <tr> 
      <td>Address: </td>
      <td> 
        <textarea name="address" rows="5" cols="35"></textarea>
      </td>
    </tr>
    <tr> 
      <td>Telephone:</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Home:</td>
      <td> 
        <input type="Text" name="home">
      </td>
    </tr>
    <tr> 
      <td>Mobile: </td>
      <td> 
        <input type="Text" name="mobile">
      </td>
    </tr>
    <tr> 
      <td>Work:</td>
      <td> 
        <input type="Text" name="work">
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Email: </td>
      <td> 
        <input type="Text" name="email" size="35">
      </td>
    </tr>
    <tr> 
      <td>Email2: </td>
      <td> 
        <input type="Text" name="email2" size="35">
      </td>
    </tr>
    <tr>
      <td>Birthday:</td>
      <td>
        <select name="bday">
          <option value="1" selected>1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="bmonth">
          <option value="January" selected>January</option>
          <option value="February">February</option>
          <option value="March">March</option>
          <option value="April">April</option>
          <option value="May">May</option>
          <option value="June">June</option>
          <option value="July">July</option>
          <option value="August">August</option>
          <option value="September">September</option>
          <option value="October">October</option>
          <option value="November">November</option>
          <option value="December">December</option>
        </select>
        <input type="text" name="byear" size="4" maxlength="4">
      </td>
    </tr>
  </table>
    <input type="Submit" name="submit" value="Enter information">
  </form>
<?
}

include (
"include/footer.inc.php");
?>
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-08-2008, 09:38 PM Re: Anyone See A Problem With this code?
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Do you get any errors? might help.

i would suggest putting the WHERE id=$id in quotes So WHERE id='$id'
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 03-08-2008, 11:06 PM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
no errors....yet. added the ' to id and no changes


here is the link to the page i am working on if you want a visual


http://www.nwabars.com/bars/edit.php?id=5

the input boxes should have ID # 5 contact info in all the boxes but its not pulling it from the DB...
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-08-2008, 11:20 PM Re: Anyone See A Problem With this code?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
You're trying to update with variables that have no value. You should set $firstname = $_POST['firstname']; and so on. However, as a security concern, you are going to want to escape your data before just inserting it into the database instead of inserting it straight from the form. Do a search on SQL injection attacks and you'll see what I mean. Also, check to see that $id is set equal to something. I don't see any code that tells me you have a value for it.

Last edited by VirtuosiMedia; 03-08-2008 at 11:23 PM..
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-09-2008, 12:40 AM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
F#%K....I have been looking for a easy to understand tutorial on this but I am not sure what I am looking for....I get most of this but I have been out of practice for a year or so....

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/public_html/bars/edit.php on line 17



PHP Code:
<?
include ("include/header.inc.php");
?>

 <h1>Edit / add address book entry</h1> 
  <?php
include("include/dbconnect.php");
if (
$_POST['submit'])
{
$sql "INSERT INTO $table (firstname, lastname, address, home, mobile, work, email, email2, bday, bmonth, byear) VALUES ('{$_POST['firstname']}','{$_POST['lastname']}','{$_POST['address']}','{$_POST['home']}','{$_POST['mobile']}','{$_POST['work']}','{$_POST['email']}','{$_POST['email2']}','{$_POST['bday']}','{$_POST['bmonth']}','{$_POST['byear']}')";
$result mysql_query ($sql);
echo 
"<br><br>Information entered into address book.\n";
}
else if (
$_POST['update'])
{
$sql "UPDATE $table SET
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname']; 
$address = $_POST['address']; 
$home = $_POST['home']; 
$mobile = $_POST['mobile']; 
$work = $_POST['work']; 
$email = $_POST['email']; 
$email2 = $_POST['email2']; 
$bday = $_POST['bday']; 
$bmonth = $_POST['bmonth']; 
$byear = $_POST['byear']; 
WHERE 
$id = $_POST['id'];";
$result mysql_query($sql);
echo 
"<br><br>Address book updated.\n";
}
else if (
$_POST['id'])
{
$result mysql_query("SELECT * FROM $table WHERE id=$id",$db);
$myrow mysql_fetch_array($result);
?>
  <form method="post" action="edit.php">
    
  <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
        Firstname: </td>
      <td> 
        <input type="Text" name="firstname" size="35" value="<?php echo $myrow["firstname"]?>">
      </td>
    </tr>
    <tr> 
      <td>Lastname:</td>
      <td> 
        <input type="Text" name="lastname" size="35" value="<?php echo $myrow["lastname"]?>">
      </td>
    </tr>
    <tr> 
      <td>Address: </td>
      <td> 
        <textarea name="address" rows="5" cols="35"><?php echo $myrow["address"]?></textarea>
      </td>
    </tr>
    <tr> 
      <td>Telephone:</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Home:</td>
      <td> 
        <input type="Text" name="home" value="<?php echo $myrow["home"]?>">
      </td>
    </tr>
    <tr> 
      <td>Mobile:</td>
      <td> 
        <input type="Text" name="mobile" value="<?php echo $myrow["mobile"]?>">
      </td>
    </tr>
    <tr> 
      <td>Work: </td>
      <td> 
        <input type="Text" name="work" value="<?php echo $myrow["work"]?>">
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Email:</td>
      <td> 
        <input type="Text" name="email" size="35" value="<?php echo $myrow["email"]?>">
      </td>
    </tr>
    <tr> 
      <td>Email2:</td>
      <td> 
        <input type="Text" name="email2" size="35" value="<?php echo $myrow["email2"]?>">
      </td>
    </tr>
    <tr> 
      <td>Birthday:</td>
      <td> 
        <select name="bday">
    <option value="<?php echo $myrow["bday"]?>" selected><?php echo $myrow["bday"]?></option>
          <option value="1">1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="bmonth">
          <option value="<?php echo $myrow["bmonth"]?>" selected><?php echo $myrow["bmonth"]?></option>
          <option value="January" selected>January</option>
          <option value="February">February</option>
          <option value="March">March</option>
          <option value="April">April</option>
          <option value="May">May</option>
          <option value="June">June</option>
          <option value="July">July</option>
          <option value="August">August</option>
          <option value="September">September</option>
          <option value="October">October</option>
          <option value="November">November</option>
          <option value="December">December</option>
        </select>
        <input type="text" name="byear" size="4" maxlength="4" value="<?php echo $myrow["byear"]?>">
      </td>
    </tr>
  </table>
    <input type="Submit" name="update" value="Update information">
  </form>
  <?

}
else
{
?>
  <form method="post" action="<?php echo $PHP_SELF?>">
    
  <table width="380" border="0" cellspacing="1" cellpadding="1">
    <tr> 
      <td> 
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>">
        Firstname:</td>
      <td> 
        <input type="Text" name="firstname" size="35">
      </td>
    </tr>
    <tr> 
      <td>Lastname: </td>
      <td> 
        <input type="Text" name="lastname" size="35">
      </td>
    </tr>
    <tr> 
      <td>Address: </td>
      <td> 
        <textarea name="address" rows="5" cols="35"></textarea>
      </td>
    </tr>
    <tr> 
      <td>Telephone:</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Home:</td>
      <td> 
        <input type="Text" name="home">
      </td>
    </tr>
    <tr> 
      <td>Mobile: </td>
      <td> 
        <input type="Text" name="mobile">
      </td>
    </tr>
    <tr> 
      <td>Work:</td>
      <td> 
        <input type="Text" name="work">
      </td>
    </tr>
    <tr> 
      <td>&nbsp;</td>
      <td>&nbsp;</td>
    </tr>
    <tr> 
      <td>Email: </td>
      <td> 
        <input type="Text" name="email" size="35">
      </td>
    </tr>
    <tr> 
      <td>Email2: </td>
      <td> 
        <input type="Text" name="email2" size="35">
      </td>
    </tr>
    <tr>
      <td>Birthday:</td>
      <td>
        <select name="bday">
          <option value="1" selected>1</option>
          <option value="2">2</option>
          <option value="3">3</option>
          <option value="4">4</option>
          <option value="5">5</option>
          <option value="6">6</option>
          <option value="7">7</option>
          <option value="8">8</option>
          <option value="9">9</option>
          <option value="10">10</option>
          <option value="11">11</option>
          <option value="12">12</option>
          <option value="13">13</option>
          <option value="14">14</option>
          <option value="15">15</option>
          <option value="16">16</option>
          <option value="17">17</option>
          <option value="18">18</option>
          <option value="19">19</option>
          <option value="20">20</option>
          <option value="21">21</option>
          <option value="22">22</option>
          <option value="23">23</option>
          <option value="24">24</option>
          <option value="25">25</option>
          <option value="26">26</option>
          <option value="27">27</option>
          <option value="28">28</option>
          <option value="29">29</option>
          <option value="30">30</option>
          <option value="31">31</option>
        </select>
        <select name="bmonth">
          <option value="January" selected>January</option>
          <option value="February">February</option>
          <option value="March">March</option>
          <option value="April">April</option>
          <option value="May">May</option>
          <option value="June">June</option>
          <option value="July">July</option>
          <option value="August">August</option>
          <option value="September">September</option>
          <option value="October">October</option>
          <option value="November">November</option>
          <option value="December">December</option>
        </select>
        <input type="text" name="byear" size="4" maxlength="4">
      </td>
    </tr>
  </table>
    <input type="Submit" name="submit" value="Enter information">
  </form>
<?
}

include (
"include/footer.inc.php");
?>
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-09-2008, 01:13 AM Re: Anyone See A Problem With this code?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Try it like this:

Code:

$firstname = $_POST['firstname']; 
$lastname = $_POST['lastname'];  
$address = $_POST['address'];  
$home = $_POST['home'];  
$mobile = $_POST['mobile'];  
$work = $_POST['work'];  
$email = $_POST['email'];  
$email2 = $_POST['email2'];  
$bday = $_POST['bday'];  
$bmonth = $_POST['bmonth'];  
$byear = $_POST['byear'];  
$id = $_POST['id'];

$sql = "UPDATE $table SET firstname='$firstname',lastname='$lastname',address='$address',home='$home',mobile='$mobile',work='$work',email='$email',email2='$email2',bday='$bday',bmonth='$bmonth',byear='$byear' WHERE id=$id"; 
$result = mysql_query($sql); 
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-09-2008, 01:41 AM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
it got rid of the error but my input boxes are still not pulling the data from the DB.....does this form look right..

PHP Code:
<form method="post" action="<?php echo $PHP_SELF?>"> 
     
  <table width="380" border="0" cellspacing="1" cellpadding="1"> 
    <tr>  
      <td>  
        <input type="hidden" name="id" value="<?php echo $myrow["id"]?>"> 
        Firstname:</td> 
      <td>  
        <input type="Text" name="firstname" size="35"> 
      </td> 
    </tr> 
    <tr>  
      <td>Lastname: </td> 
      <td>  
        <input type="Text" name="lastname" size="35"> 
      </td> 
    </tr> 
    <tr>  
      <td>Address: </td> 
      <td>  
        <textarea name="address" rows="5" cols="35"></textarea> 
      </td> 
    </tr> 
    <tr>  
      <td>Telephone:</td> 
      <td>&nbsp;</td> 
    </tr> 
    <tr>  
      <td>Home:</td> 
      <td>  
        <input type="Text" name="home"> 
      </td> 
    </tr> 
    <tr>  
      <td>Mobile: </td> 
      <td>  
        <input type="Text" name="mobile"> 
      </td> 
    </tr> 
    <tr>  
      <td>Work:</td> 
      <td>  
        <input type="Text" name="work"> 
      </td> 
    </tr> 
    <tr>  
      <td>&nbsp;</td> 
      <td>&nbsp;</td> 
    </tr> 
    <tr>  
      <td>Email: </td> 
      <td>  
        <input type="Text" name="email" size="35"> 
      </td> 
    </tr> 
    <tr>  
      <td>Email2: </td> 
      <td>  
        <input type="Text" name="email2" size="35"> 
      </td> 
    </tr> 
    <tr> 
      <td>Birthday:</td> 
      <td> 
        <select name="bday"> 
          <option value="1" selected>1</option> 
          <option value="2">2</option> 
          <option value="3">3</option> 
          <option value="4">4</option> 
          <option value="5">5</option> 
          <option value="6">6</option> 
          <option value="7">7</option> 
          <option value="8">8</option> 
          <option value="9">9</option> 
          <option value="10">10</option> 
          <option value="11">11</option> 
          <option value="12">12</option> 
          <option value="13">13</option> 
          <option value="14">14</option> 
          <option value="15">15</option> 
          <option value="16">16</option> 
          <option value="17">17</option> 
          <option value="18">18</option> 
          <option value="19">19</option> 
          <option value="20">20</option> 
          <option value="21">21</option> 
          <option value="22">22</option> 
          <option value="23">23</option> 
          <option value="24">24</option> 
          <option value="25">25</option> 
          <option value="26">26</option> 
          <option value="27">27</option> 
          <option value="28">28</option> 
          <option value="29">29</option> 
          <option value="30">30</option> 
          <option value="31">31</option> 
        </select> 
        <select name="bmonth"> 
          <option value="January" selected>January</option> 
          <option value="February">February</option> 
          <option value="March">March</option> 
          <option value="April">April</option> 
          <option value="May">May</option> 
          <option value="June">June</option> 
          <option value="July">July</option> 
          <option value="August">August</option> 
          <option value="September">September</option> 
          <option value="October">October</option> 
          <option value="November">November</option> 
          <option value="December">December</option> 
        </select> 
        <input type="text" name="byear" size="4" maxlength="4"> 
      </td> 
    </tr> 
  </table> 
    <input type="Submit" name="submit" value="Enter information"> 
  </form>
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-09-2008, 04:12 AM Re: Anyone See A Problem With this code?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
You're trying to get it pre-filled with the info from your database? You'll have to echo the variable into each input value.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Old 03-09-2008, 09:12 AM Re: Anyone See A Problem With this code?
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
like:
PHP Code:
<? echo $row['field'?>
or something like that
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 03-09-2008, 01:33 PM Re: Anyone See A Problem With this code?
Junior Talker

Posts: 3
Trades: 0
its not work
proxy1 is offline
Reply With Quote
View Public Profile
 
Old 03-09-2008, 02:18 PM Re: Anyone See A Problem With this code?
dansgalaxy's Avatar
Defies a Status

Posts: 6,522
Name: Dan
Location: Swindon
Trades: 0
Quote:
Originally Posted by proxy1 View Post
its not work
Hmm Okay thanks Proxy1 for bringing such a useful post to the discussion...
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 03-09-2008, 03:11 PM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
Hmm Okay thanks Proxy1 for bringing such a useful post to the discussion...


there are two forms on this page...one to enter the info and the other to update the info...is it nessary to use echo on both forms or just use it on the one used to update the database?
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-09-2008, 03:14 PM Re: Anyone See A Problem With this code?
pappasaa's Avatar
Ultra Talker

Posts: 268
Trades: 0
oh...whould it be better to split the pages so i have one page for entering the data and one to update the data....


PS: I guess i owe you guys a few beers for helping out...thanks
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 03-10-2008, 12:41 PM Re: Anyone See A Problem With this code?
VirtuosiMedia's Avatar
Web Design Made Simple

Posts: 1,228
Trades: 0
Quote:
Originally Posted by pappasaa View Post
oh...whould it be better to split the pages so i have one page for entering the data and one to update the data....
You can do that if you want, but you don't have to because it doesn't really make any difference in performance. But you'll have to set your variables in each of the conditional statements otherwise it won't work, ie:

Code:
if ($_POST['submit']){
$firstname = $_POST['firstname'];
}elseif($_POST['update']){
$firstname = $_POST['firstname'];
}
The other way you could do it is by setting your variable values outside of the conditionals and you would only have to do it once, like this:


Code:
$firstname = $_POST['firstname'];

if ($_POST['submit']){

}elseif($_POST['update']){

}

I don't think you can directly insert a $_POST variable into a string. If you want to include it in, you'll have to do something like:

Code:
$string = 'begin string'.$_POST['string'].'end string.';

However, it's very important NOT to just insert information you get from a form directly into database. Look up SQL injection attacks and you'll learn about a lot of security problems that you can avoid by sanitizing your data. If you don't do this, your site could be hacked very easily.
VirtuosiMedia is offline
Reply With Quote
View Public Profile Visit VirtuosiMedia's homepage!
 
Reply     « Reply to Anyone See A Problem With this code?

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.61180 seconds with 12 queries