-
Oct 23rd, 2014, 01:45 AM
#1
[RESOLVED] You must enter a number greater then 0!
Hi,
I have not done php for awhile and I am experience a problem with the following code
PHP Code:
/convert the POST variables from the html to local variables
if(isset($_POST['cid'], $_POST['fname'], $_POST['lname'], $_POST['snum'], $_POST['sname'], $_POST['suburb'], $_POST['pcode'], $_POST['country'], $_POST['phone'], $_POST['email'], $_POST['user'],$_POST['upassword'],$_POST['repassword'])){
$cid = mysql_real_escape_string($_POST['cid']);
$fname = mysql_real_escape_string($_POST['fname']);
$lname = mysql_real_escape_string($_POST['lname']);
$snum = mysql_real_escape_string($_POST['snum']);
$sname = mysql_real_escape_string($_POST['sname']);
$suburb = mysql_real_escape_string($_POST['suburb']);
$pcode = mysql_real_escape_string($_POST['pcode']);
$country = mysql_real_escape_string($_POST['country']);
$phone = mysql_real_escape_string($_POST['phone']);
$email = mysql_real_escape_string($_POST['email']);
$user = mysql_real_escape_string($_POST['user']);
$password = mysql_real_escape_string($_POST['upassword']);
$repassword = mysql_real_escape_string($_POST['repassword']);
$ccnumber = mysql_real_escape_string($_POST['credit_card']);
}
//validate or send data.
if($_SERVER['REQUEST_METHOD'] == "POST"){
if($cid==""||$cid ==0){
echo 'You must enter a number greater then 0!';
exit;
}
if($fname==""){
echo 'You must enter your first name!';
exit;
}
if($lname==""){
echo 'You must enter your last name!';
exit;
}
if($snum==""){
echo 'You must enter a street number!';
exit;
}
if($sname==""){
echo 'You must enter a street name!';
exit;
}
if($suburb==""){
echo 'You must enter a suburb!';
exit;
}
if($pcode==""){
echo 'You must enter a post code!';
exit;
}
if($country==""){
echo 'You must enter your counry name!';
exit;
}
if($phone==""){
echo 'You must enter your phone number!';
}
if (!(is_numeric($phone))){
echo "Please enter a numeric value!";
}
if($email==""){
echo 'You must enter your email address!';
exit;
}
if($user==""){
echo 'You must enter a username!';
exit;
}
if($password==""){
echo 'You must enter a password!';
exit;
}
if($repassword==""){
echo 'You must reenter the password!';
exit;
}
if(!($repassword==$password)){
echo 'Password does not match! Please reenter the password.';
exit;
}
//send mysql a query to select records from the products table where the id's match. If the query fails exit
if (!($result = mysql_query("SELECT * FROM customers where cid= '$cid'"))){
echo '&message=query+failed&';
exit;
}
//Retrieve the number of rows (records)that have been returned from above query
$num_results = mysql_num_rows($result);
if($num_results <= 0) {//customer does not exist so insert
$query = "INSERT INTO customers (cid, FName, LName, Housenum, Streetname, Suburb, Postcode, Country, Phone, Email, Username, Password, Credit_Card_Number)
VALUES ('$cid','$fname', '$lname', '$snum', '$sname','$suburb','$pcode','$country','$phone','$email','$user','$password', '$ccnumber')";
if (mysql_query($query , $conn)){
$update = "update customers set FName='$fname', LName='$lname' where customerid='$cid'";
echo "&message=the+customer+'$fname'+'$lname'+has+been+successfully+added&";
}else{
echo '&message=the+insert+was+not+successful&';
}
if(!mysql_query($update, $conn)){
echo "&message=the+details+have+been+updated&";
}else{
echo "&message=update+not+successful&";
}
}
}
$_SESSION['username'] = $user;
$_SESSION['credit'] = $ccnumber;
$_SESSION['snum'] = $snum;
$_SESSION['sname'] = $sname;
$_SESSION['suburb'] = $suburb;
$_SESSION['pcode'] = $pcode;
$_SESSION['country'] = $country;
?>
Here is the code I use to create the table
PHP Code:
//create tables
$query = "CREATE TABLE IF NOT EXISTS customers (
cid int(2) NOT NULL auto_increment,
FName varchar(30) default NULL,
LName varchar(30) default NULL,
Email varchar(50) default NULL,
Streetname varchar(20) default NULL,
Housenum char(3) default NULL,
Suburb varchar(20) default NULL,
Postcode varchar(6) default NULL,
Country varchar(20) default NULL,
Phone varchar(10) default NULL,
Username varchar(10) default NULL unique,
Password varchar(8) default NULL,
Credit_Card_Number varchar(20) default NULL,
PRIMARY KEY (cid)
) TYPE=MyISAM";
For some reason this user define message "You must enter a number greater then 0!" keeps on occurring although, I enter a number greater than "0".
Thanks,
Nightwalker
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Oct 23rd, 2014, 02:43 AM
#2
Re: You must enter a number greater then 0!
It was actually because I was missing some fields in the form as to why I was receiving the error.
HTML Code:
<form action="<?php $_SERVER['PHP_SELF'];?>" method="post" enctype="application/x-www-form-urlencoded" name="Register" target="_self">
<label class="left-label" for="cid">Customer ID:</label><label class="center-label" for="fname">First Name:</label><label class="right-label" for="lname">Last Name:</label><br /><input name="cid" id="cid" type="text" /> <input name="fname" id="fname" type="text" /> <input name="lname" id="lname" type="text" /> <br /><label class= "row2left-label" for="snum">Street Number:</label><label class= "row2center-label" for="sname">Street Name:</label><label class= "row2right-label" for="suburb">Suburb:</label><br /><input name="snum" id="snum" type="text" /> <input name="sname" id="sname" type="text" /> <input name="suburb" id="suburb" type="text" /> <br /><label class= "row3left-label" for="pcode">Post Code:</label><label class= "row3center-label" for="country">Country:</label><label class= "row3right-label" for="phone">Phone:</label><br /> <input name="pcode" id="pcode" type="text" /> <input name="country" id="country" type="text" /> <input name="phone" id="phone" type="text" /><br /> <label class= "row4left-label" for="email">Email:</label><label class= "row4center-label" for="user">Username:</label><label class= "row4right-label" for="upassword">Password:</label><br /><input name="email" id="email" type="text" /> <input name="user" id="user" type="text" /> <input name="upassword" id="upassword" type="password" />
<br /><label class= "row5left-label" for="repassword">Retype Password:</label><label class= "row5center-label" for="credit_card">C_C Number:</label><br /><input name="repassword" id="repassword" type="password" />
<input name="credit_card" id="credit_card" type="text" /><br />
<input name="submit" class="form-button" type="submit" value="Submit" /> <input name="reset" type="reset" value="Reset" />
</form>
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|