Jump to content

Why are 5 of my 7 Variables reporting as Undefined? I'm Lost......


Modernvox

Recommended Posts

 

Still don't understand why the script tells me delete and newbidder are undefined when I am not submitting those forms??

 

Because even though you're not submitting that form the code is getting a point where it's using a variable that is not defined (obviously). Just make sure that before you use a variable from an outside source that might not be set you make sure that it is using isset.

 

You must've edited that code because the errors you posted can't be happening on those lines in the code provided.

 

Don't know what to tell ya bud, it is what it is. Just ain't working....

Link to comment
Share on other sites

No it's not working. That along with this:

 

if ($_POST['newBidder']) {

 

Will cause problems when the $_POST['deleteBidder'] and $_POST['newBidder'] variables are not set, as you're seeing.

Link to comment
Share on other sites

No it's not working. That along with this:

 

if ($_POST['newBidder']) {

 

Will cause problems when the $_POST['deleteBidder'] and $_POST['newBidder'] variables are not set, as you're seeing.

 

Alright, So I owe you a cheeseburger. When your in the U.S. come see me. The only remaining problem is in my SQL statement as it reads "Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\process.php on line 91

 

I will look into this thoroughly t see if I can't find what i am doing wrong.

Thanks again:-)

Link to comment
Share on other sites

That's happening because the previous mysql_query is returning false. Print out the query and see what the problem is.

 

C'mon now, I can barely swallow what's in front of me...I don't know where to print out the query?

This is a problem , no?

mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$winningBidder')");
echo $row['winningBidder'];


mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) 
VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')")
or die(mysql_error());   
header("Location: index.php");
exit();

 

Because I ma using the same name mysql_Query?

Link to comment
Share on other sites

PHP function names are case-insensitive, so it doesn't matter.

 

Find the line where the error is occurring, find the result that the call to mysql_num_rows on that line is using and print out the query that was used to create that result.

 

Just wanted to let you know where i goofed(we know all the other goofs, this is the my sql goof:-) highlighted in Orange.

 

<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);

$host= "localhost";
$db_name= "bidders";
$db_user= "root";
$db_password= "";

ob_start();

if(isset($_POST['newBidder'])) {
$newBidder= isset($_POST['newBidder']) ? $_POST['newBidder'] : '';
$bidderId= $newBidder;

mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM bidders WHERE biddersId='$bidderId'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==0){
// Add $biddersId and redirect to anypage
mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$bidderId')");
header("Location: index.php");
exit();
  }
}

if(isset($_POST['deleteBidder']))
{
$deleteBidder= isset($_POST['deleteBidder']) ? $_POST['deleteBidder'] : '';
mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_query("DELETE FROM bidders WHERE biddersId='$deleteBidder'");
header("Location: index.php");
exit();
}

if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty']))
{
$itemDescription= isset($_POST['itemDescription']) ? $_POST['itemDescription'] : '';
$itemPrice= isset($_POST['itemPrice']) ? $_POST['itemPrice'] : '';
$winningBidder= isset($_POST['winningBidder']) ? $_POST['winningBidder'] : '';
$itemQty= isset($_POST['itemQty']) ? $_POST['itemQty'] : '';

mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM transactions WHERE bidderIds='$winningBidder'";  [color=red]//transactions uses bidderId NOT biddersId[/color]
$result=mysql_query($sql);

$count=mysql_num_rows($result);
// If result matched, table row must be 1 row

if($count==0){
echo "That Bidder Number is NOT logged in, ";
echo "would you like to set this bidder as active?";
echo " Enter 1 for NO or 2 for YES";
echo "<form action= \"process.php\" method= \"POST\">";
echo "<input type =\"text\" name= \"logUser\"/>";
echo "<input type= \"submit\" value = \"Submit\"/>";
$logUser= isset($_POST['logUser']) ? $_POST['logUser'] : '';
exit();
}
if ($logUser= 1) {
header("Location: inprogress.php");
exit();
}

else if ($logUser= 2){
// Add $biddersId and redirect to anypage
mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$winningBidder')");
echo $row['winningBidder'];


mysql_query("INSERT INTO transactions (itemDescription, itemPrice, bidderId, itemQty , totalPrice) 
VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')")
or die(mysql_error());   
header("Location: inprogress.php");
exit();
   }
}

echo "<font color= \"red\" face=\"calibri\" size=\"4\">That bidder is already logged, Please press your browsers back button and try again.</font>";


ob_end_flush();

?>

Link to comment
Share on other sites

Almost there, but i face one more obstacle.

 

I receive no errors, but no input is added to the database. If anyone sees something out of whack, please respond?

 

if (isset($_POST['itemDescription'], $_POST['itemPrice'], $_POST['winningBidder'], $_POST['itemQty']))
{
$itemDescription= isset($_POST['itemDescription']) ? $_POST['itemDescription'] : '';
$itemPrice= isset($_POST['itemPrice']) ? $_POST['itemPrice'] : '';
$winningBidder= isset($_POST['winningBidder']) ? $_POST['winningBidder'] : '';
$itemQty= isset($_POST['itemQty']) ? $_POST['itemQty'] : '';

mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

$sql="SELECT * FROM bidders WHERE biddersId='$winningBidder'";
$result=mysql_query($sql);

$count=mysql_num_rows($result);
// If result matched, table row must be 1 row

if($count==0){
echo "That Bidder Number is NOT logged in, ";
echo "would you like to set this bidder as active?";
echo " Enter 1 for NO or 2 for YES";
echo "<form action= \"process.php\" method= \"POST\">";
echo "<input type =\"text\" name= \"logUser\"/>";
echo "<input type= \"submit\" value = \"Submit\"/>";
exit();
  }
}
$logUser= isset($_POST['logUser']) ? $_POST['logUser'] : '';
if ($logUser= '1') {
header("Location: inprogress.php");
exit();
}

else if ($logUser= '2'){

// Add $biddersId and redirect to anypage
mysql_connect("$host", "$db_user", "$db_password")or die("cannot connect to server");
mysql_select_db("$db_name")or die("cannot select DB");

mysql_Query("INSERT INTO bidders (biddersId)
VALUES ('$winningBidder')");

mysql_query("INSERT INTO transactions
VALUES('$itemDescription', '$itemPrice','$winningBidder', '$itemQty', '$totalPrice')")
or die(mysql_error());   
header("Location: inprogress.php");
exit();
   }

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.