Click here to Skip to main content
15,884,298 members

Can anyone convert my PHP to ASP please?

J3ffers asked:

Open original thread
Hi,

Would anyone be so kind to convert my php into asp please?

Greatly appreciated.
James

PHP
<?
$objConnect = mysql_connect("***","***","***") or die(mysql_error());
$objDB = mysql_select_db("***");

//*** Add ***//
if($_POST["hdnCmd"] == "Add")
{
$strSQL = "INSERT INTO xxxxxxx ";
$strSQL .="(ID,StartDateTime,EndDateTime,Name,Email,Telephone,SMS,Sex) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["txtAddID"]."','".$_POST["txtAddStart"]."','".$_POST["txtAddEnd"]."','".$_POST["txtAddName"]."' ";
$strSQL .=",'".$_POST["txtAddEmail"]."' ";
$strSQL .=",'".$_POST["txtAddTelephone"]."','".$_POST["txtAddSMS"]."' ";
$strSQL .=",'".$_POST["txtAddSex"]."') ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Save [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}

//*** Update ***//
if($_POST["hdnCmd"] == "Update")
{
$strSQL = "UPDATE xxxxxxx SET ";
$strSQL .="ID = '".$_POST["txtEditID"]."' ";
$strSQL .=",StartDateTime = '".$_POST["txtEditStart"]."' ";
$strSQL .=",EndDateTime = '".$_POST["txtEditEnd"]."' ";
$strSQL .=",Name = '".$_POST["txtEditName"]."' ";
$strSQL .=",Email = '".$_POST["txtEditEmail"]."' ";
$strSQL .=",Telephone = '".$_POST["txtEditTelephone"]."' ";
$strSQL .=",SMS = '".$_POST["txtEditSMS"]."' ";
$strSQL .=",Sex = '".$_POST["txtEditSex"]."' ";
$strSQL .="WHERE ID = '".$_POST["hdnEditID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Update [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}

//*** Delete ***//
if($_GET["Action"] == "Del")
{
$strSQL = "DELETE FROM xxxxxxx ";
$strSQL .="WHERE ID = '".$_GET["CusID"]."' ";
$objQuery = mysql_query($strSQL);
if(!$objQuery)
{
echo "Error Delete [".mysql_error()."]";
}
//header("location:$_SERVER[PHP_SELF]");
//exit();
}

$strSQL = "SELECT * FROM xxxxxxx order by ID";
$objQuery = mysql_query($strSQL) or die ("Error Query [".$strSQL."]");
?>
<form name="frmMain" method="post" action="<?=$_SERVER["PHP_SELF"];?>">
<!-- Headings -->
<input type="hidden" name="hdnCmd" value="">
<table>
<tr>
<th>ID<br><sub>Max of 6 Characters</sub></th>
<th>Start Date & Time<br><sub>yyyy-mm-dd hh:mm:ss</sub></th>
<th>End Date & Time<br><sub>yyyy-mm-dd hh:mm:ss</sub></th>
<th>Name<br><sub>Full Name</sub></th>
<th>Email<br><sub>All lower case<br>In the format of xxx@xxx.xxx</sub></th>
<th>Telephone<br><sub>No Spaces<br>(11 digits including area code)</sub></th>
<th>SMS<br><sub>No Spaces<br>(11 digits only)</sub></th>
<th>Him or Her<br><sub>Him or Her Only</sub></th>
<th colspan="2">Select Option<br><sub>Add, Edit or Delete</sub></th>
</tr>
<?
while($objResult = mysql_fetch_array($objQuery))
{
?>

<?
if($objResult["ID"] == $_GET["CusID"] and $_GET["Action"] == "Edit")
{
?>
<!-- In Edit Mode -->
<tr>
<td>
<input type="text" name="txtEditID" value="<?=$objResult["ID"];?>">
<input type="hidden" name="hdnEditID" value="<?=$objResult["ID"];?>">
</td>
<td><input type="text" name="txtEditStart" value="<?=$objResult["StartDateTime"];?>"></td>
<td><input type="text" name="txtEditEnd" value="<?=$objResult["EndDateTime"];?>"></td>
<td><input type="text" name="txtEditName" value="<?=$objResult["Name"];?>"></td>
<td><input type="text" name="txtEditEmail" value="<?=$objResult["Email"];?>"></td>
<td><input type="text" name="txtEditTelephone" value="<?=$objResult["Telephone"];?>"></td>
<td><input type="text" name="txtEditSMS" value="<?=$objResult["SMS"];?>"></td>
<td><input type="text" name="txtEditSex" value="<?=$objResult["Sex"];?>"></td>
<td colspan="2" align="center">
<input name="btnAdd" type="button" id="btnUpdate" value="Update" OnClick="frmMain.hdnCmd.value='Update';frmMain.submit();">
<input name="btnAdd" type="button" id="btnCancel" value="Cancel" OnClick="window.location='<?=$_SERVER["PHP_SELF"];?>';">
</td>
</tr>
<?
}
else
{
?>
<!-- In View Mode -->
<tr>
<td><?=$objResult["ID"];?></td>
<td><?=$objResult["StartDateTime"];?></td>
<td><?=$objResult["EndDateTime"];?></td>
<td><?=$objResult["Name"];?></td>
<td><?=$objResult["Email"];?></td>
<td><?=$objResult["Telephone"];?></td>
<td><?=$objResult["SMS"];?></td>
<td><?=$objResult["Sex"];?></td>
<td><a href="<?=$_SERVER["PHP_SELF"];?>?Action=Edit&CusID=<?=$objResult["ID"];?>">Edit</a></td>
<td><a href="java<!-- no -->script:if(confirm('Confirm Delete?')==true){window.location='<?=$_SERVER["PHP_SELF"];?>?Action=Del&CusID=<?=$objResult["ID"];?>';}">Delete</a></td>
</tr>
<?
}
?>
<?
}
?>
<!-- In Add Mode -->
<tr>
<td><input type="text" name="txtAddID"></td>
<td><input type="text" name="txtAddStart"></td>
<td><input type="text" name="txtAddEnd"></td>
<td><input type="text" name="txtAddName"></td>
<td><input type="text" name="txtAddEmail"></td>
<td><input type="text" name="txtAddTelephone"></td>
<td><input type="text" name="txtAddSMS"></td>
<td><input type="text" name="txtAddSex"></td>
<td colspan="2" align="center">
<input name="btnAdd" type="button" id="btnAdd" value="Add" OnClick="frmMain.hdnCmd.value='Add';frmMain.submit();">
</td>
</tr>
</table>
</form>
<?
mysql_close($objConnect);
?>
Tags: ASP, PHP

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900