Jump to content

How to check before insert with xml


postonoh

Recommended Posts

Hello PHP World,

I don't have access to the database yet for the project I am working on so I created a work around until I get full access to the mysql database.

 

I

<?php

	$xml_file = "affiliate.xml";		

	// OPEN XML FILE ######################################################

	if(!$xml=simplexml_load_file($xml_file)){
	    trigger_error('Error reading XML file',E_affiliate_ERROR);
	}
if(!empty($_GET['add'])){

           
		$u_name = stripslashes($_POST['name']);
		$u_company = stripslashes($_POST['company']);
		$u_address = stripslashes($_POST['address']);
		$u_city = stripslashes($_POST['city']);
		$u_state = stripslashes($_POST['state']);
		$u_phone = stripslashes($_POST['phone']);
		$u_email = stripslashes($_POST['email']);
		$u_desc = stripslashes($_POST['description']);
		$u_region = stripslashes($_POST['region']);

		// Generate new (appended) ID

		foreach($xml as $affiliate){
		    $last_id = $affiliate->uid;
		}

		$id = $last_id+1;

		// Add node

		$x = $xml->addChild("affiliate");
		$x->addChild("uid",$id);
		$x->addChild("name",$u_name);
		$x->addChild("company",$u_company);
		$x->addChild("address",$u_address);
		$x->addChild("city",$u_city);
		$x->addChild("state",$u_state);
		$x->addChild("phone",$u_phone);
		$x->addChild("email",$u_email);
		$x->addChild("description",$u_desc);
		$x->addChild("region",$u_region);

		$xml->asXML($xml_file);

	}
?>

 

 

html form

 

<br />
	<br />

	<h1>Affiliate </h1>

	<form name="xml_writing" method="post" action="?add=t">
	<table width="393">
	<tr><td width="56">
	Name:<br /></td><td width="206">
	<input type="text" name="name" width="150"/></td>
	<td>Region:</td>
	<td><select name="region" value="options">
	<option value="resellerNE">NorthEast</option>
	<option value="resellerSE">SouthEast</option>
	<option value="resellerC">Central</option>
	<option value="resellerNE">NorthWest</option>
	<option value="resellerNE">SouthWest</option>
	<option value="resellerNE">International</option>	
	</select></td>
	</tr>
	<tr>
	<td>
	Company:<br /></td><td>
	<input type="text" name="company" width="150" /></td>
	</tr>
	<tr><td>
	Address:<br /></td><td>
	<input type="text" name="address" width="150"/></td>
	</tr>
	<tr><td height="45">
	City:<br /></td><td>
	<input type="text" name="city" width="150"/></td>
	<tr><td>
	State:<br /></td><td>
	<input type="text" name="state" width="150"/></td>
	<tr><td>
	Phone:<br /></td><td>
	<input type="text" name="phone" width="150"/></td>
	<tr><td>
	Email:<br /></td><td>
	<input type="text" name="email" width="150"/></td>
	</tr>

	<tr><td colspan="2">
	Short description of yourself, your practice, your services, and other information of interest to potential clients or collaborators.<br /></td>
	<tr><td colspan="2">
	<textarea name="description" style="width: 406px; height: 136px;"></textarea></td>
	</tr>
	<tr><td></td><td>
	<input type="submit" value="Submit" /></td>
	</tr>
	</table></form>

What I am trying to do is have on submit check against the email node in the xml file to see if email exist.

if exist string already a member else insert.

 

if you can help with code or point to something that will help.

 

 

"Everyone needs a mentor to lead them into success."

Quote by Shelby Poston

 

Link to comment
Share on other sites

Hello PHP World,

I don't have access to the database yet for the project I am working on so I created a work around until I get full access to the mysql database.

 

I know how to do it with the database

 

$query "SELECT email FROM owners WHERE email = '$u_email' ":

$result = mysql_query($query) or die(mysql_error());

 

if(mysql_affected_rows())

 

{

 

}else

{

 

}

 

trying figure out with xml.

 

 

 

I

<?php

	$xml_file = "affiliate.xml";		

	// OPEN XML FILE ######################################################

	if(!$xml=simplexml_load_file($xml_file)){
	    trigger_error('Error reading XML file',E_affiliate_ERROR);
	}
if(!empty($_GET['add'])){

           
		$u_name = stripslashes($_POST['name']);
		$u_company = stripslashes($_POST['company']);
		$u_address = stripslashes($_POST['address']);
		$u_city = stripslashes($_POST['city']);
		$u_state = stripslashes($_POST['state']);
		$u_phone = stripslashes($_POST['phone']);
		$u_email = stripslashes($_POST['email']);
		$u_desc = stripslashes($_POST['description']);
		$u_region = stripslashes($_POST['region']);

		// Generate new (appended) ID

		foreach($xml as $affiliate){
		    $last_id = $affiliate->uid;
		}

		$id = $last_id+1;

		// Add node

		$x = $xml->addChild("affiliate");
		$x->addChild("uid",$id);
		$x->addChild("name",$u_name);
		$x->addChild("company",$u_company);
		$x->addChild("address",$u_address);
		$x->addChild("city",$u_city);
		$x->addChild("state",$u_state);
		$x->addChild("phone",$u_phone);
		$x->addChild("email",$u_email);
		$x->addChild("description",$u_desc);
		$x->addChild("region",$u_region);

		$xml->asXML($xml_file);

	}
?>

 

 

html form

 

<br />
	<br />

	<h1>Affiliate </h1>

	<form name="xml_writing" method="post" action="?add=t">
	<table width="393">
	<tr><td width="56">
	Name:<br /></td><td width="206">
	<input type="text" name="name" width="150"/></td>
	<td>Region:</td>
	<td><select name="region" value="options">
	<option value="resellerNE">NorthEast</option>
	<option value="resellerSE">SouthEast</option>
	<option value="resellerC">Central</option>
	<option value="resellerNE">NorthWest</option>
	<option value="resellerNE">SouthWest</option>
	<option value="resellerNE">International</option>	
	</select></td>
	</tr>
	<tr>
	<td>
	Company:<br /></td><td>
	<input type="text" name="company" width="150" /></td>
	</tr>
	<tr><td>
	Address:<br /></td><td>
	<input type="text" name="address" width="150"/></td>
	</tr>
	<tr><td height="45">
	City:<br /></td><td>
	<input type="text" name="city" width="150"/></td>
	<tr><td>
	State:<br /></td><td>
	<input type="text" name="state" width="150"/></td>
	<tr><td>
	Phone:<br /></td><td>
	<input type="text" name="phone" width="150"/></td>
	<tr><td>
	Email:<br /></td><td>
	<input type="text" name="email" width="150"/></td>
	</tr>

	<tr><td colspan="2">
	Short description of yourself, your practice, your services, and other information of interest to potential clients or collaborators.<br /></td>
	<tr><td colspan="2">
	<textarea name="description" style="width: 406px; height: 136px;"></textarea></td>
	</tr>
	<tr><td></td><td>
	<input type="submit" value="Submit" /></td>
	</tr>
	</table></form>

What I am trying to do is have on submit check against the email node in the xml file to see if email exist.

if exist string already a member else insert.

 

if you can help with code or point to something that will help.

 

 

"Everyone needs a mentor to lead them into success."

Quote by Shelby Poston

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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