...

View Full Version : PHP add script wont work



jmoney3457
12-12-2008, 10:43 PM
so i have it customers can click a purchase link & it takes the fields from customer & vehicles table & adds it to an empty purchases table but its not working (not adding to purchase table) heres my code

<?
session_start();
if (($_SESSION[auth]='yes') and ($_SESSION[level]==3)) {

include 'connect.inc.php';
$id=$_GET[id];
$query="SELECT * FROM vehicles,customers";
$result=mysql_query($query);


$num=mysql_numrows($result);




$i=0;

while ($i <$num) {
$vid=mysql_result($result,$i,"vid");
$cid=mysql_result($result,$i,"cid");
$year=mysql_result($result,$i,"year");
$make=mysql_result($result,$i,"make");
$model=mysql_result($result,$i,"model");
$price=mysql_result($result,$i,"price");
$fname=mysql_result($result,$i,"fname");
$lname=mysql_result($result,$i,"lname");


$i++;

}

$query="insert into purchases (vid,cid,year,make,model,price,fname,lname) values('$vid','$cid','$year','$make','$model','$price','$fname','$lname')";
$result=mysql_query($query);
mysql_close();

echo "you have just bought $year $make $model for $price";
}
else { header('Location:index.php');
}


?>

Fumigator
12-12-2008, 11:18 PM
Check your queries for errors.

timgolding
12-12-2008, 11:20 PM
dont the INSERT and INTO and VALUE in the sql query have to be capitals. Like you have done with SELECT and DONE for the other query

Fumigator
12-12-2008, 11:29 PM
no those clauses are all case-INsensitive.

jmoney3457
12-13-2008, 12:27 AM
Check your queries for errors.

how so? do you mean run it in the command line? does anyone have quick fix for this or see whats wrong?

timgolding
12-13-2008, 02:11 AM
Have you checked all the spellings of the fields are the same in the database as they are in the code

dharvell
12-13-2008, 02:30 AM
At the end of your INSERT INTO query, include an or die(mysql_error()) line. The end result will look like:


$query="insert into purchases (vid,cid,year,make,model,price,fname,lname) values('$vid','$cid','$year','$make','$model','$price','$fname','$lname')" or die(mysql_error());

This way, if there is an error happening at this query, you will be notified of it.

jmoney3457
12-13-2008, 02:43 AM
At the end of your INSERT INTO query, include an or die(mysql_error()) line. The end result will look like:


$query="insert into purchases (vid,cid,year,make,model,price,fname,lname) values('$vid','$cid','$year','$make','$model','$price','$fname','$lname')" or die(mysql_error());

This way, if there is an error happening at this query, you will be notified of it.

where would the error (if any) display?

jmoney3457
12-13-2008, 02:44 AM
Have you checked all the spellings of the fields are the same in the database as they are in the code

ya...im setting the code (queries & everything) up correctly rnt i?

dharvell
12-13-2008, 02:47 AM
where would the error (if any) display?

Typically, the error would be displayed right in the browser. Depending on how your page is set up, it could be anywhere. Most of the time I have done this, my errors are the only thing showing up on an otherwise white screen. However, that might just be how I set up my pages.

More correctly, the error will show up where the query is executing, if that makes any sense...?

jmoney3457
12-13-2008, 04:05 AM
Typically, the error would be displayed right in the browser. Depending on how your page is set up, it could be anywhere. Most of the time I have done this, my errors are the only thing showing up on an otherwise white screen. However, that might just be how I set up my pages.

More correctly, the error will show up where the query is executing, if that makes any sense...?

somewhat to me lol..but can anyone see mistakes I made like did i not set up my queries correctly or have typo etc? ..

_Aerospace_Eng_
12-13-2008, 05:23 AM
Change this

$result=mysql_query($query);
mysql_close();
to this

$result=mysql_query($query) or die(mysql_error().'<br>SQL:' . $query);
mysql_close();
You'll get an error if there is one. I think it might be a scope issue or your variables aren't being stet properly. I suggest you echo out your variables to see what their values are.

jmoney3457
12-13-2008, 07:27 AM
Change this

$result=mysql_query($query);
mysql_close();
to this

$result=mysql_query($query) or die(mysql_error().'<br>SQL:' . $query);
mysql_close();
You'll get an error if there is one. I think it might be a scope issue or your variables aren't being stet properly. I suggest you echo out your variables to see what their values are.

its displaying the variables fine when i echo them its just not adding it to the empty purchase table..

_Aerospace_Eng_
12-13-2008, 08:00 AM
So you made the changes I told you to make and you got NO errors?

jmoney3457
12-13-2008, 09:01 AM
correct, however i fixed it thx:)

_Aerospace_Eng_
12-14-2008, 03:24 AM
What was the issue?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum