Reply
Got Another One For Ya...
Old 01-05-2009, 09:58 PM Got Another One For Ya...
pappasaa's Avatar
Ultra Talker

Posts: 267
Trades: 0
This one will pull the data but on submit it will change to the other form...all feilds will be empty...when it should update the database and say "database updated"


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

Edit entry<br> 
  <?php
include("include/dbconnect.php");
if($submit)
{

$sql = "INSERT INTO $table (paypal, contact, mob_id, mob_name, hitlist, attack, paid, status, notes, date, time) VALUES ('$paypal','$contact','$mob_id','$mob_name','$hitlist','$attack','$paid','$status','$notes','$date','$time')";
$result = mysql_query($sql);
echo "<br><br>Information entered into databas.\n";
}
else if($update)
{
$sql = "UPDATE $table SET paypal='$paypal',contact='$contact',mob_id='$mob_id',mob_name='$mob_name',hitlist='$hitlist',attack='$attack',paid='$paid',status='$status',notes='$notes',date='$date',time='$time'WHERE ID=$ID";
$result = mysql_query($sql);
echo "<br><br>database updated.\n";
}
else if ($_GET['ID']) 
{
$result = mysql_query("SELECT * FROM $table WHERE 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"]?>">
        paypal Name: </td>
      <td> 
        <input type="Text" name="paypal" size="35" value="<?php echo $myrow["paypal"]?>">
      </td>
    </tr>
    <tr> 
      <td><br><br>contact: </td>
      <td> 
       <br><br><input type="Text" name="contact" size="35" value="<?php echo $myrow["contact"]?>">
      </td>
    </tr>
    <tr> 
      <td>id:</td>
      <td> 
        <input type="Text" name="mob_id" size="35" value="<?php echo $myrow["mob_id"]?>">
      </td>
    </tr>

<tr> 
      <td><br><br>name: </td>
      <td> 
       <br><br><input type="Text" name="mob_name" size="35" value="<?php echo $myrow["mob_name"]?>">
      </td>
    </tr>
    <tr> 
      <td>active:</td>
      <td> 
        <input type="Text" name="hitlist" size="35" value="<?php echo $myrow["hitlist"]?>">
      </td>
    </tr>
<tr> 
      <td><br><br>active: </td>
      <td> 
       <br><br><input type="Text" name="attack" size="35" value="<?php echo $myrow["attack"]?>">
      </td>
    </tr>
    <tr> 
      <td>paid:</td>
      <td> 
        <input type="Text" name="paid" size="35" value="<?php echo $myrow["paid"]?>">
      </td>
    </tr>
<tr> 
      <td><br><br>status: </td>
      <td> 
       <br><br><input type="Text" name="status" size="35" value="<?php echo $myrow["status"]?>">
      </td>
    </tr>
    <tr> 
      <td>note:</td>
      <td> 
        <input type="Text" name="notes" size="35" value="<?php echo $myrow["notes"]?>">
      </td>
    </tr>
<tr> 
      <td><br><br>date: </td>
      <td> 
       <br><br><input type="Text" name="date" size="35" value="<?php echo $myrow["date"]?>">
      </td>
    </tr>
    <tr> 
      <td>time:</td>
      <td> 
        <input type="Text" name="time" size="35" value="<?php echo $myrow["time"]?>">
      </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"]?>">
        paypal Name:</td>
      <td> 
        <input type="Text" name="paypal" size="35">
      </td>
    </tr>
    <tr> 
      <td><br><br>contact: </td>
      <td> 
        <br><br><input type="Text" name="contact" size="35">
      </td>
    </tr>
     <tr> 
      <td>id:</td>
      <td> 
        <input type="Text" name="mob_id" size="35">
      </td>
    </tr>

<tr> 
      <td><br><br>name: </td>
      <td><br><br><input type="Text" name="mob_name" size="35">
      </td>
    </tr>
     <tr> 
      <td>active:</td>
      <td><input type="Text" name="hitlist" size="35">
      </td>
    </tr>
<tr> 
      <td><br><br>active: </td>
      <td> 
        <br><br><input type="Text" name="attack" size="35">
      </td>
    </tr>
     <tr> 
      <td>paid:</td>
      <td> 
        <input type="Text" name="paid" size="35">
      </td>
    </tr>
<tr> 
      <td><br><br>status: </td>
      <td> 
        <br><br><input type="Text" name="status" size="35">
      </td>
    </tr>
     <tr> 
      <td>notes:</td>
      <td> 
        <input type="Text" name="notes" size="35">
      </td>
    </tr>
<tr> 
      <td><br><br>date: </td>
      <td> 
        <br><br><input type="Text" name="date" size="35">
      </td>
    </tr>
     <tr> 
      <td>TIme:</td>
      <td> 
        <input type="Text" name="time" size="35">
      </td>
    </tr>

        </table>
   <br><br> <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!
 
 
When You Register, These Ads Go Away!
Old 01-06-2009, 01:26 PM Re: Got Another One For Ya...
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
A few things...

1. What are you getting from the script?

2. In your if/elseif statements you're using $submit and $update which aren't defined anywhere else. Using isset() just makes sure that that variable is set, and is a good habit to get into. You want to change those to
Code:
if(isset($_POST['submit'])) {
//that stuff here
}
else if (isset($_POST['update'])) {
//update stuff here
}
else if (isset($_GET['ID'])){
//you get the idea...
}
respectively because the statements aren't being activated. Remember, form information is stored in either $_GET or $_POST and if you want to use it as a $variable you have to set it with an = statement.

3. This query is wrong:
Code:
$result = mysql_query("SELECT * FROM $table WHERE ID",$db);
Change it to:
Code:
$result = mysql_query("SELECT * FROM $table WHERE ID='$_GET[ID]'");
But you probably want to check what $_GET['ID'] is set as before you do anything. Using is_numeric() is probably your best bet for that. If you don't check it someone could enter a query into the browser URL and bad things could happen.

Hope this helps!
__________________
Freelance web+graphic designer and PHP developer.
Web Design Portfolio
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Old 01-06-2009, 11:35 PM Re: Got Another One For Ya...
pappasaa's Avatar
Ultra Talker

Posts: 267
Trades: 0
ok...i changed the code to what you said and tested it out. It looked as if it worked at firs but it never updated the data.

I also added

Code:
$result = mysql_query($sql) or die(mysql_error());
to see if i would get some kind of tip as to what is going on and I got this

Code:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
here is my code again....any thoughts?


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

Edit entry<br> 
  <?php
include('include/dbconnect.php');
if(isset($_POST['submit']))
{

$sql = "INSERT INTO $table (paypal, contact, mob_id, mob_name, hitlist, attack, paid, status, notes, date, time) VALUES ('$paypal','$contact','$mob_id','$mob_name','$hitlist','$attack','$paid','$status','$notes','$date','$time')";
$result = mysql_query($sql);
echo "<br><br>Information entered into address book.\n";
}
else if (isset($_POST['update']))
{
$sql = "UPDATE $table SET paypal='$paypal',contact='$contact',mob_id='$mob_id',mob_name='$mob_name',hitlist='$hitlist',attack='$attack',paid='$paid',status='$status',notes='$notes',date='$date',time='$time'WHERE id=$id";
$result = mysql_query($sql) or die(mysql_error());
echo "<br><br>Address book updated.\n";
}
else if (isset($_GET['ID'])) 
{
$result = mysql_query("SELECT * FROM $table WHERE ID='$_GET[ID]'");
$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"]?>">
        paypal Name: </td>
      <td> 
        <input type="Text" name="paypal" size="35" value="<?php echo $myrow["paypal"]?>">
      </td>
    </tr>
    <tr> 
      <td><br><br>contact: </td>
      <td> 
       <br><br><input type="Text" name="contact" size="35" value="<?php echo $myrow["contact"]?>">
      </td>
    </tr>
    <tr> 
      <td>id:</td>
      <td> 
        <input type="Text" name="mob_id" size="35" value="<?php echo $myrow["mob_id"]?>">
      </td>
    </tr>

<tr> 
      <td><br><br>name: </td>
      <td> 
       <br><br><input type="Text" name="mob_name" size="35" value="<?php echo $myrow["mob_name"]?>">
      </td>
    </tr>
    <tr> 
      <td>active:</td>
      <td> 
        <input type="Text" name="hitlist" size="35" value="<?php echo $myrow["hitlist"]?>">
      </td>
    </tr>
<tr> 
      <td><br><br>active: </td>
      <td> 
       <br><br><input type="Text" name="attack" size="35" value="<?php echo $myrow["attack"]?>">
      </td>
    </tr>
    <tr> 
      <td>paid:</td>
      <td> 
        <input type="Text" name="paid" size="35" value="<?php echo $myrow["paid"]?>">
      </td>
    </tr>
<tr> 
      <td><br><br>status: </td>
      <td> 
       <br><br><input type="Text" name="status" size="35" value="<?php echo $myrow["status"]?>">
      </td>
    </tr>
    <tr> 
      <td>note:</td>
      <td> 
        <input type="Text" name="notes" size="35" value="<?php echo $myrow["notes"]?>">
      </td>
    </tr>
<tr> 
      <td><br><br>date: </td>
      <td> 
       <br><br><input type="Text" name="date" size="35" value="<?php echo $myrow["date"]?>">
      </td>
    </tr>
    <tr> 
      <td>time:</td>
      <td> 
        <input type="Text" name="time" size="35" value="<?php echo $myrow["time"]?>">
      </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"]?>">
        paypal Name:</td>
      <td> 
        <input type="Text" name="paypal" size="35">
      </td>
    </tr>
    <tr> 
      <td><br><br>contact: </td>
      <td> 
        <br><br><input type="Text" name="contact" size="35">
      </td>
    </tr>
     <tr> 
      <td>id:</td>
      <td> 
        <input type="Text" name="mob_id" size="35">
      </td>
    </tr>

<tr> 
      <td><br><br>name: </td>
      <td><br><br><input type="Text" name="mob_name" size="35">
      </td>
    </tr>
     <tr> 
      <td>active:</td>
      <td><input type="Text" name="hitlist" size="35">
      </td>
    </tr>
<tr> 
      <td><br><br>active: </td>
      <td> 
        <br><br><input type="Text" name="attack" size="35">
      </td>
    </tr>
     <tr> 
      <td>paid:</td>
      <td> 
        <input type="Text" name="paid" size="35">
      </td>
    </tr>
<tr> 
      <td><br><br>status: </td>
      <td> 
        <br><br><input type="Text" name="status" size="35">
      </td>
    </tr>
     <tr> 
      <td>notes:</td>
      <td> 
        <input type="Text" name="notes" size="35">
      </td>
    </tr>
<tr> 
      <td><br><br>date: </td>
      <td> 
        <br><br><input type="Text" name="date" size="35">
      </td>
    </tr>
     <tr> 
      <td>TIme:</td>
      <td> 
        <input type="Text" name="time" size="35">
      </td>
    </tr>

        </table>
   <br><br> <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 01-06-2009, 11:44 PM Re: Got Another One For Ya...
pappasaa's Avatar
Ultra Talker

Posts: 267
Trades: 0
Quote:
But you probably want to check what $_GET['ID'] is set as before you do anything. Using is_numeric() is probably your best bet for that. If you don't check it someone could enter a query into the browser URL and bad things could happen.
this is going to be a private admin thing so i will be the only one with access to it. It will be used to track my customers. Just to store and update contact information.

Also made some of the changes you said last night before i read this and was not sure if I was doing it right. Thank you
__________________
visit my link...um...nevermind
pappasaa is offline
Reply With Quote
View Public Profile Visit pappasaa's homepage!
 
Old 01-07-2009, 11:08 AM Re: Got Another One For Ya...
PeachyJuice's Avatar
Super Talker

Posts: 116
Name: Michele T.
Location: Ny, Ny
Trades: 1
I don't see where you're defining $id in the update query. Either set $id = $_GET['ID']; or put $_GET[ID] in the query. I suggest the first now that you've added in the checks.
__________________
Freelance web+graphic designer and PHP developer.
Web Design Portfolio
PeachyJuice is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Got Another One For Ya...
 

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.12197 seconds with 13 queries