PDA

View Full Version : PHP Help



Luno1599
15-12-2007, 10:36 AM
Hey

I have having touble adding this into the database :( it says Successfull but then there is nothing in the database :(


<?php
if($_GET['add'] == "yes"){
//Get Data
$client = $_POST['client'];
$date = $_POST['date'];
$byy = $_POST['by'];
$invoice = $_POST['invoice'];
$acc = $_POST['ac'];
if($by == NULL | $invoice == NULL){
echo "<br /><div class='failed'>You left something blank.<br><a href='javascript:history.back();'>[Back?]</a></div>";
}else{
include("config.php");
$add_invoice = "INSERT INTO invoice (client_id, date, created, for, activ) VALUES ('$client','$date','$byy','$invoice','$acc')";
mysql_query($add_invoice);
//Added?
echo "<br /><div class='success'>The invoice for client ID#$client was added successfully!</div>";
}}
?>Whats up with it?

Dan

Moved by Agesilaus (Forum Moderator) from Design and Development: Please post in the correct forum in future.

Hitman
15-12-2007, 10:50 AM
Hey, I quickly edited it a bit and fixed something I thought might be a problem. Tell me if it works!


<?php
if($_GET['add'] == "yes"){
//Get Data
$client = $_POST['client'];
$date = $_POST['date'];
$byy = $_POST['by'];
$invoice = $_POST['invoice'];
$acc = $_POST['ac'];
if($byy == NULL | $invoice == NULL){
echo "<br /><div class='failed'>You left something blank.<br><a href='javascript:history.back();'>[Back?]</a></div>";
}else{
include("config.php");
$add_invoice = mysql_query("INSERT INTO `invoice` (`client_id`, `date`, `created`, `for`, `activ`) VALUES ('$client','$date','$byy','$invoice','$acc')");
//Added? Should be!
echo "<br /><div class='success'>The invoice for client ID#$client was added successfully!</div>";
}
}
?>

Tomm
15-12-2007, 11:09 AM
Question: Where do you actually connect to the database?

Hitman
15-12-2007, 11:14 AM
Question: Where do you actually connect to the database?
He has got a connection, after the }else{ he connects then does the query. I always connect on the third line. :P

Luno1599
15-12-2007, 11:16 AM
Hey its


include("config.php");

That connects :)

And its working fine now +rep for help

Hitman
15-12-2007, 11:20 AM
Hey its


include("config.php");That connects :)

And its working fine now +rep for help
My code worked? Hah, I finally can fix things (I'm still a bit of a PHP newbie). :D

Florx
15-12-2007, 11:21 AM
He has got a connection, after the }else{ he connects then does the query. I always connect on the third line. :P
Me too I like to have the database connected on EVERY page even if it's not going to be used :)

Hitman
15-12-2007, 11:23 AM
Me too I like to have the database connected on EVERY page even if it's not going to be used :)I think I have it on every page, at least all that need connecting.

... But most of the PHP pages I make require the connection anyway. xD

Luno1599
15-12-2007, 11:41 AM
I have it on every page as the check.php file has it and it includes it :P, in a php newbie to :P

Check what im making in projects

Beau
15-12-2007, 08:14 PM
Just a heads up, if you're actually going to be releasing this as a script, you'll want to be sanitizing your form input before chucking it into the database.

Want to hide these adverts? Register an account for free!