KJATL 0 Newbie Poster

Appears that $pid is empty (not set), and thus the query is invalid. Shouldn't $_POST be $_COOKIE ??

Maybe, i'm not sure.

On the first script, the player enters pid as an interger value to specify which player they would like to update or delete, if the update button is clicked after information is entered into pid, that information is posted to the next script as $pid. My assumption was that $pid would remain set through the second script, but from the second (editing the record) to the third (performing the update), I though I would need a cookie.

Maybe there is a problem with my method.

---

I've changed my cookie to grab the server time:

setcookie('pid', $pid, time()+3600);

This is still printing that pid is an undefined index.

---

After using the function "print_r($_COOKIE);" I see the following output. I am not sure if this suggests a session is established. The only session I remember establishing was a connection to the database, not a php session:

Array ( [PHPSESSID] => g3i5fqjakvprqgmut894pr5m54 [9d4bb4a09f511681369671a08beff228] => rnnhg0t43bih5p6ke8gkno5a56 [cda3f8363c72cb411c8879ff46e7dbfa] => 356jv7t74i29gjf11a1p0v3tk1 [c0f8b8f4c4af84715b39697f86810ec8] => accf9619f4a96c9642cc37becc69fcfd )
KJATL 0 Newbie Poster

Don't forget the quotes.

setcookie('pid', $pid, 3600);

Hello pritaeas!

I have placed quotes around the name of the cookie, but I am still experiencing problems:

$pid = $_POST['pid'];$delete = $_POST['Delete'];
$update = $_POST['Update'];

if(isset($update))
{
  $sql = "SELECT * FROM player WHERE id = {$pid}";
  $result = mysql_query($sql, $connection);
  $row = mysql_fetch_array($result)
  or die("Database query failed: " . mysql_error());
  setcookie('pid', $pid, 3600);

In the second script:

<?php require_once("includes/connection.php"); ?>
<?php
$pid = $_COOKIE['pid'];$ln = $_POST['ln'];
$fn = $_POST['fn'];
$mi = $_POST['mi'];
$ad = $_POST['ad'];
$ci = $_POST['ci'];
$st = $_POST['st'];
$zi = $_POST['zi'];
$mn = $_POST['mn'];
$dn = $_POST['dn'];

Notice: Undefined index: pid in C:\wamp\www\base_ball\update_player.php on line 3
Database query failed: 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 ')WHERE id = ''' at line 1

I am assuming the query is failing because $pid doesn't carry over. I've changed my browser settings to allow cookies from any website.

Do you have any thoughts?

KJATL 0 Newbie Poster

Hello there,

I am working on an update script that can be broken down into 3 parts.

1. The form (uses id to populate fields)
2. The UPDATE
3. The confirmation.

Form:

<?php require_once("includes/connection.php");

$pid = $_POST['pid'];
$delete = $_POST['Delete'];
$update = $_POST['Update'];

if(isset($update))
{
  $sql = "SELECT * FROM player WHERE id = {$pid}";
  $result = mysql_query($sql, $connection);
  $row = mysql_fetch_array($result)
  or die("Database query failed: " . mysql_error());
  setcookie(pid, $pid, 3600);
  ?>
  <html>
<h3>Update Player</h3>
<br>
    <body>
    <form action="update_player.php" method="post">
<table cellspacing="0" cellpadding="0" width="100%"> 
...
</form>
    </body>
    </html>
  <?php
  
}
else
if(isset($delete))
{
  $sql = "DELETE FROM player WHERE id = {$pid}";
  $result = mysql_query($sql, $connection)
  or die("Database query failed: " . mysql_error());

The UPDATE:

<?php
$pid = $_COOKIE['pid'];
$ln = $_POST['ln'];
$fn = $_POST['fn'];
$mi = $_POST['mi'];
$ad = $_POST['ad'];
...
$DoBYYYY = $_POST['DoBYYYY'];
$team = $_POST['team'];
$output_form = false;

if (empty($ln) || empty($fn) || empty($pcell)){
echo 'You forgot either the last name, first name, or player\'s cell. <br \>';
$output_form = true;
}
else{

$query = "UPDATE player SET last_name = '$ln', first_name = '$fn', middle_initial = '$mi', home_address = '$ad', city = '$ci', state = '$st', zip = '$zi', mother = '$mn', father = '$dn',".
"player_cell = '$pcell', mom_cell = '$mcell', dad_cell = '$dcell', home_number = '$hnumber', mom_work_number = '$mwork', dad_work_number = '$dwork', mom_email = '$memail', dad_email = '$demail', personal_email = '$pemail',".
"preferred_email = '$prefemail', years_played = '$yrsp', medical_conditions = '$medc', emergency_contact_name = '$emerc', emergency_contact_phone = '$emercnumber', texting = '$text', as_of_date …
KJATL 0 Newbie Poster

Hello,

I do not know if I fully comprehend the use of post. My understanding was that because $_POST was a superglobal, the values set applied to all pages after having been set. Here is the problem I am facing.

1) User enters an id number into field to delete x record:

<form action="update_delete.php" method="post">
       Player I.D. <input type="text" name="pid" maxlength=10 size=5><br>
<input type="Submit" value="Delete" name="Delete">
<input type="Submit" value="Update" name="Update">
</form>

2) Information is called and used in delete query:

$pid = $_POST['pid'];
@$delete = $_POST['Delete'];
@$update = $_POST['Update'];

if(isset($update))
{
  //Do update here..
}
else
if(isset($delete))
{
  $sql = "DELETE FROM player WHERE id = {$pid}";
  $result = mysql_query($sql, $connection)
  or die("Database query failed: " . mysql_error());
  echo "Row deleted!";
}

3) Value of pid reported to user:

@ $pid = $_POST['pid'];
?>
<html>
<body><br><br>
Record(s): <?php echo "$pid" ?> have been deleted.
</body>

</html>

My problem ends in step 3 where the record is reported back. The $pid variable is not echoed and I see no feedback suggesting that $pid was not set. Perhaps there is something wrong in the code on step 3?

KJATL 0 Newbie Poster

Hello,

I've got a series of buttons that take the user to the same page. Different information is passed to the PHP page effecting the behavior or the page. The functions work but the problem is that for each button not pressed, a Notice is displayed.

Is there a switch I can use to turn off notice error reporting for a single page? Is there perhaps a more effeicient way of tunneling information through buttons that does not generate notices?

Currently I am using isset instead of empty.

Notice: Undefined index: Update in ****.php on line 6
Notice: Undefined index: Add in ****.php on line 16
Record deleted!

KJATL 0 Newbie Poster

You should check isset($_POST) instead of $Delete

Ack, awfully bone-headed of me. Thank you for your fresh-set of eyes.

KJATL 0 Newbie Poster

hi there

im a novice to PHP and have been trying to put together a form with two buttons that post a variable value. The value is tested and then php perfroms whatever action that value points to (Update or Delete). My problem is that when I click the button, the record is still there and I get no feedback inspite of having established it in the code:

Here are the buttons (called through include):

<form action="update_delete.php" method="post">
       Player I.D. <input type="text" name="pid" maxlength=10 size=5><br>
<input type="Submit" value="Delete" name="Delete">
<input type="Submit" value="Update" name="Update">
</form>

And here is the PHP:

<?php require_once("includes/connection.php"); ?>
<?php

$pid = $_POST['pid'];

if(isset($Update))
{
  //Update stuff
}
else
if(isset($Delete))
{
  $sql = "DELETE from player where id=$pid";
  $result = mysql_query($sql, $connection)
  or die("Database query failed: " . mysql_error());
  echo "Row deleted!";
}
?>

<?php require("includes/footer.php"); ?>

I'm not sure what to apply here...