Jump to content

Wondering why this specific section of code NOT working? Please Help?


Modernvox

Recommended Posts

Commented in red is the code that doesn't produce anything. It is 3/4 of the way down the page..

Thanks for looking!

 

 

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

$host= "";
$db_name= "";
$db_user= "";
$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 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();
}

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)  ////This won't add biddersid to database///////[
VALUES ('$winningBidder')");

mysql_query("INSERT INTO transactions       /////This won't add details to the database either?/////
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();

?>

 

I have one database with 2 tables as follows

bidders table ONLY has biddersId field;

transactions has (in order) itemDescription, itemPrice, bidderId, itemQty, totalPrice

 

everything else works, except updating the database with the above?

 

Am I doing something wrong in MySql. I have all eroors on , but i get NONE when running the script?

Unfortunately, "having all errors on" does not include mySql errors, only PHP errors.  Anytime you execute a query, you have to specifically test for an error.  Many people use:

$res = mysql_query($sql) or die(mysql_error());

However, that will kill the script if there was an error.

 

I usually take the long way around:

$res = mysql_query($sql);
if ($res === false) {
  // Some error occured. Handle it or show it
  trigger_error('mysql Error: ' . mysql_error(), E_USER_WARNING);
} else {
  // Process the results
}

by triggering an error instead of dieing, on the production server, with error logging on, the error gets logged. During development with error display on, I get to see the error.

 

At any rate, check mysql_error() after your queries in that part and see if there are errors there.

Narrowed it down to this section of code.  Did I mess up the form? should i be using php self for this since process.php is the page the form redirects to which is the same page that echo's the form?

 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\"/>";
echo "</form>";
exit();
  }
}
$logUser= isset($_POST['logUser']) ? $_POST['logUser'] : '';
if ($logUser= '1') {
header("Location: inprogress.php");
exit();
}

if ($logUser= '2'){
echo "hello";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.