Got Another One For Ya...
01-05-2009, 09:58 PM
|
Got Another One For Ya...
|
Posts: 267
|
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
|
|
|
|
01-06-2009, 01:26 PM
|
Re: Got Another One For Ya...
|
Posts: 116
Name: Michele T.
Location: Ny, Ny
|
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!
|
|
|
|
01-06-2009, 11:35 PM
|
Re: Got Another One For Ya...
|
Posts: 267
|
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
|
|
|
|
01-06-2009, 11:44 PM
|
Re: Got Another One For Ya...
|
Posts: 267
|
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
|
|
|
|
01-07-2009, 11:08 AM
|
Re: Got Another One For Ya...
|
Posts: 116
Name: Michele T.
Location: Ny, Ny
|
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.
|
|
|
|
|
« Reply to Got Another One For Ya...
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|