Jump to content

Why doens't my script work? Help much appreciated


DeepakJ

Recommended Posts

<html><head><title>AlibreCam Verification System</title></head>


<center><TABLE border=0 cellpadding=3><form name="input" action="linput.php"
method="get">
<tr>
<td>Customer ID:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>Product ID:</td>
<td> <input type="text" name="user1"></td>
</tr>

<tr>	<td colspan=2><center><input type="submit" value="Submit"></center></td>
</tr>
</form><br></table><br>

<?php
$hostname = "localhost";
$username = "root";
$password = "98989lol";
$dbname = "licensinginformation";
$customerid = $_GET['user'];
$productid = $_GET['user1'];


mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");
$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

$querya = "SELECT * FROM invoiceid WHERE customerid='$customerid'";
$aResult = mysql_query($querya);

while($row1=mysql_fetch_array($aResult)){
$invoicenum[]= $row1['invoicenum'];
}

$queryd = "SELECT * FROM invoiceid, productid WHERE invoiceid.invoicenum = productid.invoicenum && customerid= '$customerid'";
//queryd = "SELECT * FROM productid WHERE invoicenum IN('" . implode("', '", $invoicenum) . "')";
$dResult = mysql_query($queryd) or die(mysql_error());
$boolean = false;
while($row2=mysql_fetch_array($dResult)){
if ($row2['productid']="")
{
	$tableid = $row2['tableid'];
	$queryc = "UPDATE productid SET productid='$productid' WHERE tableid = '$tableid'";
	mysql_query($queryc) or die(mysql_error());
	echo "Data successfully entered.";
	$boolean = true;
	break;
}
}
if ($boolean=false){
echo "The customer does not have enough licenses.";
}



?>
</html>

 

Please help.

Link to comment
Share on other sites

Thats the thing. No errors. Yet when I run the script, the database is not updated and the messages(both) wont show up

 

This is my revised code:

<html><head><title>AlibreCam Verification System</title></head>


<center><TABLE border=0 cellpadding=3><form name="input" action="linput.php"
method="get">
<tr>
<td>Customer ID:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>Product ID:</td>
<td> <input type="text" name="user1"></td>
</tr>

<tr>	<td colspan=2><center><input type="submit" value="Submit"></center></td>
</tr>
</form><br></table><br>

<?php
$hostname = "localhost";
$username = "root";
$password = "98989lol";
$dbname = "licensinginformation";
$customerid = $_GET['user'];
$productid = $_GET['user1'];


mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");
$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

$querya = "SELECT * FROM invoiceid WHERE customerid='$customerid'";
$aResult = mysql_query($querya);

while($row1=mysql_fetch_array($aResult)){
$invoicenum[]= $row1['invoicenum'];
}

$queryd = "SELECT * FROM invoiceid, productid WHERE invoiceid.invoicenum = productid.invoicenum && customerid= '$customerid'";
//queryd = "SELECT * FROM productid WHERE invoicenum IN('" . implode("', '", $invoicenum) . "')";
$dResult = mysql_query($queryd) or die(mysql_error());
$boolean = false;
while($row2=mysql_fetch_array($dResult)){
if ($row2['productid']="")
{
	$tableid = $row2['tableid'];
	$queryc = "UPDATE productid SET productid='$productid' WHERE tableid = '$tableid'";
	mysql_query($queryc) or die(mysql_error());
	echo "Data successfully entered.";
	$boolean = true;
	break;
}
}
if ($boolean=false){
echo "The customer does not have enough licenses.";
}



?>
</html>

Link to comment
Share on other sites

Hi DeepakJ,

 

Are these scripts seperate, as in the PHP is seperate from the HTML?

 

If so, you need a 'handle' (sorry - I don't know the correct terms!) for the script to react to.

 

Try firstly naming the submit button like this:

 

<input type="submit" name="formSent" value="Submit">

 

Then have the script react accordingly by putting this above the script on the PHP page:

<?php
if (isset($_POST['formSent']){
?>

 

and at the very end of the script put the closing bracket and maybe an else statement. Example:

 

<?php
}
else
{
echo 'An unkonwn error has occured!';
}
?>

 

Hope that helps!

Regards,

Iceman

Link to comment
Share on other sites

... sorry, I've just spotted your most likely problem.

 

Change the method to "post":

 

<form action="something.php" method="post">

 

You will also have to modify your PHP as follows:

 

Change:

<?php
$customerid = $_GET['user'];
$productid = $_GET['user1'];
?>

 

To:

<?php
$customerid = $_POST['user'];
$productid = $_POST['user1'];
?>

 

Hope that works!

Iceman

Link to comment
Share on other sites

Even if the form is on it's own, it might still need conditional handling.

 

If the button has been clicked, do this action. If it hasn't, do that action, as it were.

 

<?php
if (!isset($_POST['formSent']){

<center><TABLE border=0 cellpadding=3><form name="input" action="linput.php"
method="get">
<tr>
<td>Customer ID:</td>
<td><input type="text" name="user"></td>
</tr>
<tr>
<td>Product ID:</td>
<td> <input type="text" name="user1"></td>
</tr>

<tr>	<td colspan=2><center><input type="submit" name="formSent" value="Submit"></center></td>
</tr>
</form><br></table><br>

}elseif (isset($_POST['formSent']){

$hostname = "localhost";
$username = "root";
$password = "98989lol";
$dbname = "licensinginformation";
$customerid = $_GET['user'];
$productid = $_GET['user1'];


mysql_connect($hostname, $username, $password) or DIE("Unable to connect to MySQL server $hostname");
$selected = mysql_select_db($dbname) or DIE("Could not select requested db $dbname");

$querya = "SELECT * FROM invoiceid WHERE customerid='$customerid'";
$aResult = mysql_query($querya);

while($row1=mysql_fetch_array($aResult)){
$invoicenum[]= $row1['invoicenum'];
}

$queryd = "SELECT * FROM invoiceid, productid WHERE invoiceid.invoicenum = productid.invoicenum && customerid= '$customerid'";
//queryd = "SELECT * FROM productid WHERE invoicenum IN('" . implode("', '", $invoicenum) . "')";
$dResult = mysql_query($queryd) or die(mysql_error());
$boolean = false;
while($row2=mysql_fetch_array($dResult)){
if ($row2['productid']="")
{
	$tableid = $row2['tableid'];
	$queryc = "UPDATE productid SET productid='$productid' WHERE tableid = '$tableid'";
	mysql_query($queryc) or die(mysql_error());
	echo "Data successfully entered.";
	$boolean = true;
	break;
}
}
if ($boolean=false){
echo "The customer does not have enough licenses.";
}

} else {
echo 'An unknown error has occurred.';
}
?>

 

Maybe that will help?

:)

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.