Jump to content

Ander_3

Members
  • Posts

    5
  • Joined

  • Last visited

Ander_3's Achievements

Newbie

Newbie (1/7)

0

Reputation

  1. index.php: $selectSql='select '. 'Transactions.TransID, '. 'Transactions.OrderID, '. 'Transactions.DVDID, '. 'Transactions.DateOut, '. 'Transactions.DateDue, '. 'Transactions.DateIn, '. 'Customers.CustFN, '. 'Customers.CustLN, '. 'DVDs.DVDName '. 'from Transactions, Orders, Customers, DVDs '. 'where Orders.OrderID=Transactions.OrderID '. 'and Customers.CustID=Orders.CustID '. 'and DVDs.DVDID=Transactions.DVDID '. 'order by Transactions.OrderID desc, Customers.CustLN asc, '. 'Customers.CustFN asc, '. 'Transactions.DateDue desc, DVDs.DVDName asc;';//Execute the SQL query$result=mysql_query($selectSql, $link);
  2. I forgot to put this code in. This is from update.php. The code looks very similiar to the code I posted previously but this one does not have any errors: <?php//Build the update statement$sqlString='update Transactions set OrderID='.$orderId.', DVDID='.$dvdId.', DateOut="'.$dateOut.'", DateDue="'.$dateDue.'", DateIn="'.$dateIn.'" where TransID='.$transactionId.'';//Execute the update statementmysql_query($sqlString) or die('Error in query $sqlString' .mysql_error());?>
  3. I keep getting this error and can't figure out how to fix it... Error in query $sqlString Cannot add or update a child row: a foreign key constraint fails (`dvdrentals`.`transactions`, CONSTRAINT `transactions_ibfk_2` FOREIGN KEY (`DVDID`) REFERENCES `dvds` (`DVDID`)) This is the code causing the error: <?php//Build the insert statement$sqlString='insert into Transactions(OrderID, DVDID, DateOut, DateDue) values('.$orderId.', '.$dvdId.', "'.$dateOut.'", "'.$dateDue.'")';//Execute the insert statementmysql_query($sqlString) or die('Error in query $sqlString '.mysql_error());?>Thank you!
  4. Thank you! Replacing that code took away the undefined error!
  5. I've just begun trying to learn php and MySQL and am having problems running some example code in a beginner book.I have tried everything I know to get the program working but keep getting an 'undefined variable: dateIn' error.The code is included from the beginning of program down to the error line. The line throwing the error is typed in red. Could someone please take a look and see if I have missed something?Thank you! <?php//connect to server or return an error$link=mysql_connect('localhost', 'mysqlapp', 'pw1')or die('Could not connect: '.mysql_error());//Select a database or return an errormysql_select_db('DVDRentals', $link);//Initialize an error-related variable$error='';//initialize variables with parameters retrieved from the posted formif(isset($_POST['command'])){ $command=$_POST['command'];}if(isset($_POST['transaction_id'])){ $transactionId=$_POST['transaction_id'];}if(isset($_POST['date_due'])){ $dateDue=$_POST['date_due'];}if(isset($_POST['order_id'])){ $orderId=$_POST['order_id'];}if(isset($_POST['dvd_id'])){ $dvdId=$_POST['dvd_id'];}if(isset($_POST['date_out'])){ $dateOut=$_POST['date_out'];}if(isset($_POST['date_in'])){ $dateIn=$_POST['date_in'];}//Process the save and savenew commandsif((strcmp('save', $command)==0)||(strcmp('savenew', $command)==0)){ //Check for missing parameters if($orderId==-1){ $error.='Please select an \'Order\'<br />'; } if($dvdId==-1){ $error.='Please select a \'DVD\'<br />'; } if(($dateOut==null)||(strlen($dateOut)==0)){ $error.='Please enter a \'Date Out\' Value<br />'; } if(($dateDue==null)||(strlen($dateDue)==0)){ $error.='Please enter a \'Date Due\' Value<br />'; } if(strlen($error)==0){ //Reformat dates so that they are compatible with the MySQL format if($dateOut!=null){ $dateOut=substr($dateOut, 6, 4).'-'.substr($dateOut, 0, 2).'-'.substr($dateOut, 3, 2); } if($dateDue!=null){ $dateDue=substr($dateDue, 6, 4).'-'.substr($dateDue, 0, 2).'-'.substr($dateDue, 3, 2); } if($dateIn!=null){ $dateIn=substr($dateIn, 6, 4).'-'.substr($dateIn, 0, 2).'-'.substr($dateIn, 3, 2); }
×
×
  • Create New...