How go to authorize method ASP.NET
I'm testing Basic Http Authentication. I try go to a page, But when I go
to "books/get", I see nothing. Why? What I should add?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Net.Http.Headers;
using System.Security.Principal;
using System.Text;
using System.Threading;
namespace WebApiTest.Controllers
{
public class BooksController : Controller
{
[Authorize]
public String Get()
{
String res = "Hello";
return res;
}
public ActionResult Index()
{
return View();
}
}
}
Thursday, 3 October 2013
Wednesday, 2 October 2013
how to increment value of a column up to specific range for values in other column?
how to increment value of a column up to specific range for values in
other column?
The existing table is like:
tmc speed
ABC 55
DEF 55
I want to create a table like the following one using the existing table
in SQL Server 2008:
tmc speed
ABC 55
ABC 56
ABC 57
ABC 58
ABC 59
ABC 60
DEF 55
DEF 56
DEF 57
DEF 58
DEF 59
DEF 60
The code I developed is not showing me the exact result I want. Any help
will be highly appreciated.
other column?
The existing table is like:
tmc speed
ABC 55
DEF 55
I want to create a table like the following one using the existing table
in SQL Server 2008:
tmc speed
ABC 55
ABC 56
ABC 57
ABC 58
ABC 59
ABC 60
DEF 55
DEF 56
DEF 57
DEF 58
DEF 59
DEF 60
The code I developed is not showing me the exact result I want. Any help
will be highly appreciated.
Objective C adding C++
Objective C adding C++
I have been given some C++ classes to incorporate into my Objective C
project. I've never done this before, so I have to ask:
Is there something special I need to do or can I just rename the .cpp to .mm?
What about importing (or including) the .h file? Anything special I need
to do there?
Just baby steps here. Thank you.
I have been given some C++ classes to incorporate into my Objective C
project. I've never done this before, so I have to ask:
Is there something special I need to do or can I just rename the .cpp to .mm?
What about importing (or including) the .h file? Anything special I need
to do there?
Just baby steps here. Thank you.
PHP if statements with multiple values
PHP if statements with multiple values
Is there a shorter way of writing this?
<?
if($_GET['id']==1 ||
$_GET['id']==3 ||
$_GET['id']==4 ||
$_GET['id']==5)
{echo 'does it really have to be this explicit?'};
?>
Something like this perhaps?
<?
if($_GET['id']==1 || 3 || 4 || 5){echo 'this is much shorter'};
?>
Is there a shorter way of writing this?
<?
if($_GET['id']==1 ||
$_GET['id']==3 ||
$_GET['id']==4 ||
$_GET['id']==5)
{echo 'does it really have to be this explicit?'};
?>
Something like this perhaps?
<?
if($_GET['id']==1 || 3 || 4 || 5){echo 'this is much shorter'};
?>
Pointers in B Tree
Pointers in B Tree
I read about B trees and understand their input, delete methods. I read
with an introduction like this:
When we build structures on disk, we must deal with certain realities of
access and transfer time:
Random access to disk typically requires on the order of 10-20 ms access
time to position the head and wait for data to come up under it.
Once the head position is right, data can be transferred at rates in
excess of 1 million bytes/sec.
Observe, then, how total transfer times behave for different size blocks
(assuming a fairly fast 10 ms access time, and 1 megabyte/sec transfer
rate)
So, B Tree Data Structure is made for serving from disk ( which is what
makes them great for Databases ). But when I tried to implement it, I hit
this problem.
Normal B Tree diagrams shows pointers to child nodes which then descend
down to leaves.
But how do I make pointers on the disk? Is it like a file name ?
I read about B trees and understand their input, delete methods. I read
with an introduction like this:
When we build structures on disk, we must deal with certain realities of
access and transfer time:
Random access to disk typically requires on the order of 10-20 ms access
time to position the head and wait for data to come up under it.
Once the head position is right, data can be transferred at rates in
excess of 1 million bytes/sec.
Observe, then, how total transfer times behave for different size blocks
(assuming a fairly fast 10 ms access time, and 1 megabyte/sec transfer
rate)
So, B Tree Data Structure is made for serving from disk ( which is what
makes them great for Databases ). But when I tried to implement it, I hit
this problem.
Normal B Tree diagrams shows pointers to child nodes which then descend
down to leaves.
But how do I make pointers on the disk? Is it like a file name ?
Tuesday, 1 October 2013
Access igraph R objects from Python
Access igraph R objects from Python
I have a graph object created with the igraph R package. If I understand
the architecture of the igraph software package correctly the igraph R
package is an interface to use igraph from R. Then since there is also a
igraph Python interface I wonder if it is possible to access my igraph
object created with R via Python directly. Or if the only way to access
and igraph R object from Python is to export the igraph R object with
write.graph() in R and then import it with the igraph R package.
I have a graph object created with the igraph R package. If I understand
the architecture of the igraph software package correctly the igraph R
package is an interface to use igraph from R. Then since there is also a
igraph Python interface I wonder if it is possible to access my igraph
object created with R via Python directly. Or if the only way to access
and igraph R object from Python is to export the igraph R object with
write.graph() in R and then import it with the igraph R package.
Custom URL in PHP
Custom URL in PHP
I am trying to create custom profile URLs using PHP.
I currently have the following URL:
http://mysite.com/profile.php?user=1
where user_id 1 is Kyle Hagler in the database.
I would like to allow access to this same page through the following url:
http://mysite.com/kylehagler
I am trying to create custom profile URLs using PHP.
I currently have the following URL:
http://mysite.com/profile.php?user=1
where user_id 1 is Kyle Hagler in the database.
I would like to allow access to this same page through the following url:
http://mysite.com/kylehagler
Cont'd Decimal Expansion, rational or not?
Cont'd Decimal Expansion, rational or not?
This is a follow up from this question.
Since it's proven by Calvin Lin that $0.11235813213455...$ (Fibonacci
Sequence), I'm not wondering if the sequence
$$0.123456789101112131415...$$
(which is just natural numbers) is rational or not. Thanks for the help in
advanced!
This is a follow up from this question.
Since it's proven by Calvin Lin that $0.11235813213455...$ (Fibonacci
Sequence), I'm not wondering if the sequence
$$0.123456789101112131415...$$
(which is just natural numbers) is rational or not. Thanks for the help in
advanced!
which shell will sudo use to execute a shell script without the shebang line unix.stackexchange.com
which shell will sudo use to execute a shell script without the shebang
line – unix.stackexchange.com
My environment is Ubuntu 12.04 LTS, and the sudo version is 1.8.3p1. First
I login as a normal user: $ whoami fin $ cat /etc/passwd | grep -i
"root\|fin" root:x:0:0:root:/root:/bin/bash ...
line – unix.stackexchange.com
My environment is Ubuntu 12.04 LTS, and the sudo version is 1.8.3p1. First
I login as a normal user: $ whoami fin $ cat /etc/passwd | grep -i
"root\|fin" root:x:0:0:root:/root:/bin/bash ...
Monday, 30 September 2013
Run CRON task directly on router to automate jobs
Run CRON task directly on router to automate jobs
I want to setup CRON job directly on D'LINK DIR-655 router. I need to run
there PING job to monitor my network response times, and log all the
errors with Internet connection directly on router.
D'LINK router firmware have built in some PING tool, but D'LINK prepared
it only to manual tests. I need to automate it with CRON job to monitor
connection 24h/day with interval 3 seconds.
Is it possible?
I want to setup CRON job directly on D'LINK DIR-655 router. I need to run
there PING job to monitor my network response times, and log all the
errors with Internet connection directly on router.
D'LINK router firmware have built in some PING tool, but D'LINK prepared
it only to manual tests. I need to automate it with CRON job to monitor
connection 24h/day with interval 3 seconds.
Is it possible?
Is on one hand...on the other hand a cliché to be avoided=?iso-8859-1?Q?=3F_=96_english.stackexchange.com?=
Is "on one hand...on the other hand" a cliché to be avoided? –
english.stackexchange.com
We should find a way of long peace instead of living just for today. On
one hand, we have to prevent the community from coming apart and suffering
the disasters caused by it; on the other hand, to …
english.stackexchange.com
We should find a way of long peace instead of living just for today. On
one hand, we have to prevent the community from coming apart and suffering
the disasters caused by it; on the other hand, to …
How to show a location with respect to my current location?
How to show a location with respect to my current location?
I have a lat and longitude of my friend's location also my current
location. I want to show the position of my friend with respect to my
location, just like a compass - in an iPhone app. I know the function
didUpdateHeading -
-(void)locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading
{
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);
}
I am not getting an idea about how to do this, Please help me.
I have a lat and longitude of my friend's location also my current
location. I want to show the position of my friend with respect to my
location, just like a compass - in an iPhone app. I know the function
didUpdateHeading -
-(void)locationManager:(CLLocationManager *)manager
didUpdateHeading:(CLHeading *)newHeading
{
NSLog(@"New magnetic heading: %f", newHeading.magneticHeading);
NSLog(@"New true heading: %f", newHeading.trueHeading);
}
I am not getting an idea about how to do this, Please help me.
How to organize js files for a multi page mvc applicaiton
How to organize js files for a multi page mvc applicaiton
We have a project implemented using ASP.NET MVC 4. it is a multi page
application.
We use jQuery for handling client side interactions. Now the js file has a
lot of callback functions.
What is the best way to organize the code in the javascript file?
We have a project implemented using ASP.NET MVC 4. it is a multi page
application.
We use jQuery for handling client side interactions. Now the js file has a
lot of callback functions.
What is the best way to organize the code in the javascript file?
Sunday, 29 September 2013
Function that checks width of an image loaded by user randomly returns 0
Function that checks width of an image loaded by user randomly returns 0
I was trying to write a function that would check if the image I chose via
input[type=file] is exactly 700 px wide and if not - reject this image. I
succeeded, however, sometimes this function randomly returns 0 and I need
to load the same image a couple of times until it reads its width
correctly. Any ideas on how to improve this code? Thanks in advance!
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
var img = new Image;
img.src = e.target.result;
if(img.width == 700) {
DoSomeStuff();
} else {
alert("This image has to be 700 px wide, but is " +
img.width + " px wide. Try again!");
input.value = "";
}
};
reader.readAsDataURL(input.files[0]);
}
I was trying to write a function that would check if the image I chose via
input[type=file] is exactly 700 px wide and if not - reject this image. I
succeeded, however, sometimes this function randomly returns 0 and I need
to load the same image a couple of times until it reads its width
correctly. Any ideas on how to improve this code? Thanks in advance!
if (input.files && input.files[0]) {
var reader = new FileReader();
reader.onload = function(e) {
var img = new Image;
img.src = e.target.result;
if(img.width == 700) {
DoSomeStuff();
} else {
alert("This image has to be 700 px wide, but is " +
img.width + " px wide. Try again!");
input.value = "";
}
};
reader.readAsDataURL(input.files[0]);
}
Get list from list values in a python dictionary
Get list from list values in a python dictionary
I have a python dictionary with the following entries:
professions = {Peasant : ["Peasant", 10000], Merchant : ["Merchant",
15000], ...}
Is there a clever way to get a list of all profession names? I'd like a
function that returns
["Peasant", "Merchant", ...]
thanks for suggestions
I have a python dictionary with the following entries:
professions = {Peasant : ["Peasant", 10000], Merchant : ["Merchant",
15000], ...}
Is there a clever way to get a list of all profession names? I'd like a
function that returns
["Peasant", "Merchant", ...]
thanks for suggestions
In SAO architecture should single API do everything or API should be spilt as multiple action
In SAO architecture should single API do everything or API should be spilt
as multiple action
We have an app which is exposing api(RESTful) to UI for purchasing a item.
I have a question regardinng API design. Lets say the following action
should be taken in order
Item to be chosen for purchase
Next give the address to be delivered to
My question is should we design a single api which gets both data perform
both? Or should we desgin two api calls one that creates a purchase record
and second that update the address to be delivered to?
as multiple action
We have an app which is exposing api(RESTful) to UI for purchasing a item.
I have a question regardinng API design. Lets say the following action
should be taken in order
Item to be chosen for purchase
Next give the address to be delivered to
My question is should we design a single api which gets both data perform
both? Or should we desgin two api calls one that creates a purchase record
and second that update the address to be delivered to?
How to add space between menu and dropdown submenu
How to add space between menu and dropdown submenu
I'm working on a CSS3 full width dropdown menu, but some details i can't
get right. :-(
What i try to achieve is this:
http://i.stack.imgur.com/Egk0P.png
You can see there is a little 20px space between the mainmenu and the
submenu. In this example i used a top-margin:20px for the ul submenu. But
that doesn't really work, because you will leave the hover-area with your
cursor and the submenu wil dissapear. The dropdown only works if the
ul-container of the submenu "touches" the hover-area.
It did tried using the ul:before trick to add an empty block before the
submenu ul, but somehow that doesn't work. :( It doens't take space like a
block should do. It's just adding the content right over the ul element.
What do i overlook or doing wrong here? :( Is there a better way to add a
little bit of empty "hoverspace" above the submenu?
Your help would be very helpfull :-).
Live demo: http://jsfiddle.net/JeroenGerth/hDmxd/
The HTML:
<nav>
<ul id="menu">
<li><a href="#">Home</a></li>
<li><a href="#">Tutorials ></a>
<ul class="submenu">
<li><a href="#">Photoshop 1</a></li>
<li><a href="#">Dreamweaver 2</a></li>
<li><a href="#">Photoshop 3</a></li>
<li><a href="#">InDesign 4</a></li>
<li><a href="#">Bridge 5</a></li>
<li><a href="#">Lightroom 6</a></li>
<li><a href="#">After Effects 7</a></li>
<li><a href="#">Premiere 8</a></li>
<li><a href="#">Motion 9</a></li>
<li><a href="#">Aperture 10</a></li>
<li><a href="#">iPhoto 11</a></li>
</ul>
</li>
<li><a href="#">Downloads ></a>
<ul class="submenu">
<li><a href="#">Wallpapers 1</a></li>
<li><a href="#">PSD files 2</a></li>
<li><a href="#">Video's 3</a></li>
<li><a href="#">Soundeffects 4</a></li>
<li><a href="#">Icons 5</a></li>
<li><a href="#">Maps 6</a></li>
</ul>
</li>
<li><a href="#">About me</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
The CSS:
body {background-color: #E9E9E9;}
nav ul { /*Main menu container*/
margin: 0px;
padding: 0px 20px;
background-color:#444;
color: #fff;
list-style: none;
position:relative;
display:inline-table;
border-radius: 5px;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li { /*Main menu-items*/ float:left;}
nav ul li a {
padding: 10px 20px;
color: #fff;
font-family: Calibri, Verdana, sans-serif;
text-decoration:none;
display: block;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul li a:hover {color: #66D1D3;}
nav ul ul { /*Submenu container*/
display:block;
border-radius:0px;
padding: 0px;
position: absolute;
background-color:#fff;
color: #000;
visibility:hidden;
opacity:0;
transition:all ease-in-out 0.4s;
left: 0px;
top: 100%;
width: 100%;
columns:100px 3;
-webkit-columns:100px 3; /* Safari and Chrome */
-moz-columns:100px 3; /* Firefox */
}
nav ul li:hover > ul { /*Show submenu*/
visibility:visible;
opacity:1;
transition-delay:0s;
}
nav ul ul:before { /*Why doesn't this work :( */
content: "";
display: block;
height: 20px;
position: absolute;
width: 100%;}
nav ul ul li { /*Submenu items*/
float: none;
border-bottom: 1px #CCCCCC dotted;
position:relative;
}
nav ul ul li a {
color: #000;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul ul li a:hover {
color: #66D1D3;
background-color: #444;
}
I'm working on a CSS3 full width dropdown menu, but some details i can't
get right. :-(
What i try to achieve is this:
http://i.stack.imgur.com/Egk0P.png
You can see there is a little 20px space between the mainmenu and the
submenu. In this example i used a top-margin:20px for the ul submenu. But
that doesn't really work, because you will leave the hover-area with your
cursor and the submenu wil dissapear. The dropdown only works if the
ul-container of the submenu "touches" the hover-area.
It did tried using the ul:before trick to add an empty block before the
submenu ul, but somehow that doesn't work. :( It doens't take space like a
block should do. It's just adding the content right over the ul element.
What do i overlook or doing wrong here? :( Is there a better way to add a
little bit of empty "hoverspace" above the submenu?
Your help would be very helpfull :-).
Live demo: http://jsfiddle.net/JeroenGerth/hDmxd/
The HTML:
<nav>
<ul id="menu">
<li><a href="#">Home</a></li>
<li><a href="#">Tutorials ></a>
<ul class="submenu">
<li><a href="#">Photoshop 1</a></li>
<li><a href="#">Dreamweaver 2</a></li>
<li><a href="#">Photoshop 3</a></li>
<li><a href="#">InDesign 4</a></li>
<li><a href="#">Bridge 5</a></li>
<li><a href="#">Lightroom 6</a></li>
<li><a href="#">After Effects 7</a></li>
<li><a href="#">Premiere 8</a></li>
<li><a href="#">Motion 9</a></li>
<li><a href="#">Aperture 10</a></li>
<li><a href="#">iPhoto 11</a></li>
</ul>
</li>
<li><a href="#">Downloads ></a>
<ul class="submenu">
<li><a href="#">Wallpapers 1</a></li>
<li><a href="#">PSD files 2</a></li>
<li><a href="#">Video's 3</a></li>
<li><a href="#">Soundeffects 4</a></li>
<li><a href="#">Icons 5</a></li>
<li><a href="#">Maps 6</a></li>
</ul>
</li>
<li><a href="#">About me</a></li>
<li><a href="#">Contact</a></li>
</ul>
</nav>
The CSS:
body {background-color: #E9E9E9;}
nav ul { /*Main menu container*/
margin: 0px;
padding: 0px 20px;
background-color:#444;
color: #fff;
list-style: none;
position:relative;
display:inline-table;
border-radius: 5px;
}
nav ul:after {
content: ""; clear: both; display: block;
}
nav ul li { /*Main menu-items*/ float:left;}
nav ul li a {
padding: 10px 20px;
color: #fff;
font-family: Calibri, Verdana, sans-serif;
text-decoration:none;
display: block;
-webkit-transition: all 0.2s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul li a:hover {color: #66D1D3;}
nav ul ul { /*Submenu container*/
display:block;
border-radius:0px;
padding: 0px;
position: absolute;
background-color:#fff;
color: #000;
visibility:hidden;
opacity:0;
transition:all ease-in-out 0.4s;
left: 0px;
top: 100%;
width: 100%;
columns:100px 3;
-webkit-columns:100px 3; /* Safari and Chrome */
-moz-columns:100px 3; /* Firefox */
}
nav ul li:hover > ul { /*Show submenu*/
visibility:visible;
opacity:1;
transition-delay:0s;
}
nav ul ul:before { /*Why doesn't this work :( */
content: "";
display: block;
height: 20px;
position: absolute;
width: 100%;}
nav ul ul li { /*Submenu items*/
float: none;
border-bottom: 1px #CCCCCC dotted;
position:relative;
}
nav ul ul li a {
color: #000;
-webkit-transition: all 1s ease-in-out;
-moz-transition: all 0.2s ease-in-out;
-o-transition: all 0.2s ease-in-out;
transition: all 0.2s ease-in-out;
}
nav ul ul li a:hover {
color: #66D1D3;
background-color: #444;
}
Saturday, 28 September 2013
How to end with one result with an if statement on java?
How to end with one result with an if statement on java?
if (number1 + 8 == number2 || number1 - 8 == number2){
if (name1.equals(name2)){
if (cod1 == cod2){
if (some1.equals(some2)){
System.out.println("They're in the same group");
}
System.out.println("They are in the same column");;
}
System.out.println("They are in the same section");
}
System.out.println("They are in the same subgroup");
}
else{
System.out.println("They are different");
}
}
}
How could I change this so that I only get one message at the end? Right
now it gives all the messages or just the They are different. I know I
can't put an actual break since this isn't a loop, but what action could I
take in this problem? Would I have to rewrite it? Thank You for the help.
if (number1 + 8 == number2 || number1 - 8 == number2){
if (name1.equals(name2)){
if (cod1 == cod2){
if (some1.equals(some2)){
System.out.println("They're in the same group");
}
System.out.println("They are in the same column");;
}
System.out.println("They are in the same section");
}
System.out.println("They are in the same subgroup");
}
else{
System.out.println("They are different");
}
}
}
How could I change this so that I only get one message at the end? Right
now it gives all the messages or just the They are different. I know I
can't put an actual break since this isn't a loop, but what action could I
take in this problem? Would I have to rewrite it? Thank You for the help.
Python - PyCharm - PowerShell terminal - run as administrator
Python - PyCharm - PowerShell terminal - run as administrator
In PyCharm I set my terminal to be the Windows PowerShell, but when I try
to use virtualenv in that terminal:
Import-Module virtualenvwrapper
(I have this command in a startup script, but just included the command
alone for simplicity)
I get the following error:
Import-Module : File
C:\Users\Sean\Documents\WindowsPowerShell\Modules\virtualenvwrapper\support.psm1
cannot be loaded because the execution of scripts is disabled on this
system. Please see "get-help about_signing" for more details. At line:1
char:14 + Import-Module <<<< virtualenvwrapper + CategoryInfo :
NotSpecified: (:) [Import-Module], PSSecurityException +
FullyQualifiedErrorId :
RuntimeException,Microsoft.PowerShell.Commands.ImportModuleCommand
So I try to enable script execution (as I did for PowerShell outside of
PyCharm):
Set-ExecutionPolicy RemoteSigned
but get the following error (I avoided this error outside of PyCharm by
running PowerShell as administrator):
Set-ExecutionPolicy : Access to the registry key
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell'
is denied. At line:1 char:20 + Set-ExecutionPolicy <<<< RemoteSigned +
CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy],
UnauthorizedAccessException + FullyQualifiedErrorId :
System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
So what can I do to be able to use virtualenv from the PyCharm terminal?
Windows 7
Python 2.7
PyCharm Community Edition 3.0
In PyCharm I set my terminal to be the Windows PowerShell, but when I try
to use virtualenv in that terminal:
Import-Module virtualenvwrapper
(I have this command in a startup script, but just included the command
alone for simplicity)
I get the following error:
Import-Module : File
C:\Users\Sean\Documents\WindowsPowerShell\Modules\virtualenvwrapper\support.psm1
cannot be loaded because the execution of scripts is disabled on this
system. Please see "get-help about_signing" for more details. At line:1
char:14 + Import-Module <<<< virtualenvwrapper + CategoryInfo :
NotSpecified: (:) [Import-Module], PSSecurityException +
FullyQualifiedErrorId :
RuntimeException,Microsoft.PowerShell.Commands.ImportModuleCommand
So I try to enable script execution (as I did for PowerShell outside of
PyCharm):
Set-ExecutionPolicy RemoteSigned
but get the following error (I avoided this error outside of PyCharm by
running PowerShell as administrator):
Set-ExecutionPolicy : Access to the registry key
'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PowerShell\1\ShellIds\Microsoft.PowerShell'
is denied. At line:1 char:20 + Set-ExecutionPolicy <<<< RemoteSigned +
CategoryInfo : NotSpecified: (:) [Set-ExecutionPolicy],
UnauthorizedAccessException + FullyQualifiedErrorId :
System.UnauthorizedAccessException,Microsoft.PowerShell.Commands.SetExecutionPolicyCommand
So what can I do to be able to use virtualenv from the PyCharm terminal?
Windows 7
Python 2.7
PyCharm Community Edition 3.0
Trouble inserting PHP variables into Mysqli
Trouble inserting PHP variables into Mysqli
I am trying to insert data from a form I have made into my MYsql table
using mysqli but whenever I submit my form it just displays the
successfully connected to db server. Any ideas? It should show my errors
for the insert shouldn't it?
<?php
if ($_POST['submit']) {
$errormsg = "";
$name = $_POST['name'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$connection = @mysqli_connect("$hostname","$username", "$password",
"$database");
if(!$connection){
die("<p>The database server is not available.</p>".mysqli_error());
}
echo "<p>Sucessfully connected to the database server.</p>";
if((!$name)||(!$password)||(!$password2)||(!$email)||(!$phone)){ /*
Checks if all inputs are filled*/
$errormsg = "Please insert the required fields below<br />";
if ($name == "")
{
$errormsg = $errormsg . "Enter a name.<br />";
}
if ($password == "")
{
$errormsg = $errormsg . "Please enter a password.<br />";
}
if ($password2 =="")
{
$errormsg = $errormsg . "Please re-enter your password.<br
/>";
}
if ($email =="")
{
$errormsg = $errormsg . "Please enter an email address.<br
/>";
}
if ($phone =="")
{
$errormsg = $errormsg . "Please enter a phone number.<br />";
}
if($errormsg){
echo "$errormsg";
}
}
if($password != $password2) {
$errormsg = $errormsg. "Your passwords must match!<br/>";
}
function checkEmail($email){ //begin email check function
$sql = "SELECT count(email) FROM CUSTOMER WHERE email='$email'";
$result = mysqli_result(mysqli_query($sql),0);
if( $result > 0 ){
$errormsg = $errormsg. "There is already a user with that
email!";
}//end email check function
if(!$errormsg)
{
$insertquery = "INSERT INTO CUSTOMER (customer_no, name, password,
email, phone)
VALUES(NULL, '$name', '$password', '$email',
'$phone')";
$queryresult = mysqli_query($insertquery);
if($queryresult)
{
echo("<br>Registration sucessful");
}
else
{
echo("<br>registration was not sucessful");
}
}
}
} ?>
I am trying to insert data from a form I have made into my MYsql table
using mysqli but whenever I submit my form it just displays the
successfully connected to db server. Any ideas? It should show my errors
for the insert shouldn't it?
<?php
if ($_POST['submit']) {
$errormsg = "";
$name = $_POST['name'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$connection = @mysqli_connect("$hostname","$username", "$password",
"$database");
if(!$connection){
die("<p>The database server is not available.</p>".mysqli_error());
}
echo "<p>Sucessfully connected to the database server.</p>";
if((!$name)||(!$password)||(!$password2)||(!$email)||(!$phone)){ /*
Checks if all inputs are filled*/
$errormsg = "Please insert the required fields below<br />";
if ($name == "")
{
$errormsg = $errormsg . "Enter a name.<br />";
}
if ($password == "")
{
$errormsg = $errormsg . "Please enter a password.<br />";
}
if ($password2 =="")
{
$errormsg = $errormsg . "Please re-enter your password.<br
/>";
}
if ($email =="")
{
$errormsg = $errormsg . "Please enter an email address.<br
/>";
}
if ($phone =="")
{
$errormsg = $errormsg . "Please enter a phone number.<br />";
}
if($errormsg){
echo "$errormsg";
}
}
if($password != $password2) {
$errormsg = $errormsg. "Your passwords must match!<br/>";
}
function checkEmail($email){ //begin email check function
$sql = "SELECT count(email) FROM CUSTOMER WHERE email='$email'";
$result = mysqli_result(mysqli_query($sql),0);
if( $result > 0 ){
$errormsg = $errormsg. "There is already a user with that
email!";
}//end email check function
if(!$errormsg)
{
$insertquery = "INSERT INTO CUSTOMER (customer_no, name, password,
email, phone)
VALUES(NULL, '$name', '$password', '$email',
'$phone')";
$queryresult = mysqli_query($insertquery);
if($queryresult)
{
echo("<br>Registration sucessful");
}
else
{
echo("<br>registration was not sucessful");
}
}
}
} ?>
Subscribe to:
Posts (Atom)