Jump to content

[SOLVED] is anything in databse? do this>


ag3nt42

Recommended Posts

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

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'];}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.