ag3nt42 Posted June 18, 2008 Share Posted June 18, 2008 Hello again all, I have a situation where I am submitting form data and I want to check to see if there is anything in the database if nothing is there I want to use an insert query if something is there I want to use an update query. I'm first assigning a 'null' value to $Z variables to keep php error from crying then i'm running a select statement to the database to check for data.. if there is data the $Z variables obtain those values.. then i run a check to see if my input variables have been set.. if they haven't the $U variables are assigned the value of $Z variables..(either 'null' or 'database info') now my problem comes in.. If nothing comes in from the database then I want to run an Insert query.. but if something IS in the database I want to run an update query.. I'm just not sure how I can say that... anyone have suggestions plz share thankx, ag3nt42 Link to comment https://forums.phpfreaks.com/topic/110760-solved-is-anything-in-databse-do-thisgt/ Share on other sites More sharing options...
MatthewJ Posted June 18, 2008 Share Posted June 18, 2008 if(mysql_num_rows < 1) { // Do the insert because no records were found } else { // Do the update because records were found } Maybe something like that? Link to comment https://forums.phpfreaks.com/topic/110760-solved-is-anything-in-databse-do-thisgt/#findComment-568229 Share on other sites More sharing options...
Jabop Posted June 18, 2008 Share Posted June 18, 2008 <?php //do your query here $count=mysqli_num_rows($yourquery) if ($count>0) { // list your select vars (if you need them for the update) // do your update } else { // do your insert } ?> That of any assistance? Link to comment https://forums.phpfreaks.com/topic/110760-solved-is-anything-in-databse-do-thisgt/#findComment-568237 Share on other sites More sharing options...
ag3nt42 Posted June 18, 2008 Author Share Posted June 18, 2008 tryed the count function but nothing is echoing back for me here is my code: <?php session_start(); require('../../config.php'); $Success="False"; /////////////////////// //* OPEN CONNECTION *// /////////////////////// $con = mssql_connect($dblocation,$dbusername,$dbpassword); if (!$con) { die('Could not connect: ' . mssql_error()); } mssql_select_db($dbname, $con); /////////////////////////////////// //*******************************// //* Snatch Database Information *// //*******************************// /////////////////////////////////// //* STOP THE BITCHING *// $ZItem= array( 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null', 'null', ); $ItemSQL = "SELECT [itemName] FROM [".$tblpre."Equipment]"; $result = mssql_query($ItemSQL)or die(mssql_error()); $count=mssql_num_rows(mssql_query($result)); $x=1; while($row = mssql_fetch_row($result)) { $ZItem[$x]=$row[0]; echo($ZItem[$x]."<br />"); $x++; } echo($count."CRAP"); /////////////////////////////// //***************************// //* Harvest Input Variables *// //***************************// /////////////////////////////// //Item1 if(!(isset($_POST['Item1']))){$UItem1=$ZItem[0];}else{$UItem1=$_POST['Item1'];} //Item2 if(!(isset($_POST['Item2']))){$UItem2=$ZItem[1];}else{$UItem2=$_POST['Item2'];} //Item3 if(!(isset($_POST['Item3']))){$UItem3=$ZItem[2];}else{$UItem3=$_POST['Item3'];} //Item4 if(!(isset($_POST['Item4']))){$UItem4=$ZItem[3];}else{$UItem4=$_POST['Item4'];} //Item5 if(!(isset($_POST['Item5']))){$UItem5=$ZItem[4];}else{$UItem5=$_POST['Item5'];} //Item6 if(!(isset($_POST['Item6']))){$UItem6=$ZItem[5];}else{$UItem6=$_POST['Item6'];} //Item7 if(!(isset($_POST['Item7']))){$UItem7=$ZItem[6];}else{$UItem7=$_POST['Item7'];} //Item8 if(!(isset($_POST['Item8']))){$UItem8=$ZItem[7];}else{$UItem8=$_POST['Item8'];} //Item9 if(!(isset($_POST['Item9']))){$UItem9=$ZItem[8];}else{$UItem9=$_POST['Item9'];} //Item10 if(!(isset($_POST['Item10']))){$UItem10=$ZItem[9];}else{$UItem10=$_POST['Item10'];} Link to comment https://forums.phpfreaks.com/topic/110760-solved-is-anything-in-databse-do-thisgt/#findComment-568249 Share on other sites More sharing options...
ag3nt42 Posted June 18, 2008 Author Share Posted June 18, 2008 hehe oops, clicked the wrong submit button was showing a different page... this might work.. its showing a count now.. thnx.. i'll post back if i get it working Link to comment https://forums.phpfreaks.com/topic/110760-solved-is-anything-in-databse-do-thisgt/#findComment-568266 Share on other sites More sharing options...
ag3nt42 Posted June 18, 2008 Author Share Posted June 18, 2008 ya i think this will work thanks a million guyz Link to comment https://forums.phpfreaks.com/topic/110760-solved-is-anything-in-databse-do-thisgt/#findComment-568274 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.