Jump to content

NeilB

Members
  • Posts

    10
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

NeilB's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Thnaks for the replies so far guys! :) I have tried your coding Ken and it doesnt like it it says - [i]You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('','Samsung','D900','2','02','4545 4545 4545 4545','Delta','10/07'' at line 1[/i] I don't understand it as this insert command is just a modified version of one that works perfectly on another script.
  2. I've got a single form where I want the data to be split up into two databases, an order and customer database. I have the following code [code=php:0]         $connection = mysql_connect("localhost","root","");         mysql_select_db("db0369467", $connection)         or die("Unable to select database");         $query1 = "INSERT INTO customer VALUES ('','$title','$fname','$lname','$housenum','$street','$town','$postcode', '$email', '', '')";         mysql_query($query1);         echo mysql_error().         mysql_close($connection);         $connection = mysql_connect("localhost","root","");         mysql_select_db("db0369467", $connection)         or die("Unable to select database");         $query2 = "INSERT INTO order VALUES ('','$make','$model','$qty','$provider','$card_num','$type','$expires', '$price')";         mysql_query($query2);         echo mysql_error().         mysql_close($connection);                 Print "Thank you for your order"; [/code] But when I try to run the script I get the following error. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'order VALUES ('','Samsung','D900','2','02','4545 4545 4545 4545','Delta','10/07'' at line 11 Any idea's as to where I'm going wrong? ???
  3. Ah thanks, couldn't see the wood for the tree's there. I'm trying to get the update command to now work that was causing the problem, but it won't accept it now I have renamed it no error messages or anything. >:( [code=php:0]//Update totals         $connection2 = mysql_connect2("***", "***", "***");         mysql_select_db2("neil", $connection2)         or die("Unable to select database");         $result = mysql_query2("UPDATE mobile SET stock='$stocknumber' WHERE model='$model'")         or die(mysql_error());         mysql_query2($query2);         echo mysql_error().         mysql_close($connection2);[/code]
  4. At least that has narrowed it down to the order.php piece of coding, however I cannot see why it would enter twice though, as the same code just slightly modified enters just once into another database. ??? [code=php:0]<? session_start(); $stocknumber = $_SESSION["stocknumber"]; $origstocknumber = $_SESSION["stocknumber"]; $stocknumber = $stocknumber - $_POST['qty']; $make = $_SESSION["make"]; $model = $_SESSION["model"]; //This script looks at validating what the customer has entered function out_of_range($value,$min=1,$max=25) {         return (strlen(trim($value))<$min || strlen(trim($value))>$max); } if(isset($_POST["submit"])) {         $error_msg = array();         if(out_of_range($_POST['title']))         {           $error_msg[] = "Please enter a valid title";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[a-zA-Z]", $_POST['title'])) $error_msg[].="Please enter a valid title<br>";         }         if(out_of_range($_POST['first_name']))         {           $error_msg[] = "Please enter a valid first name";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[a-zA-Z]", $_POST['first_name'])) $error_msg[].="Please enter a valid first name<br>";         }         if(out_of_range($_POST['last_name']))         {           $error_msg[] = "Please enter a valid last name";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[a-zA-Z]", $_POST['last_name'])) $error_msg[].="Please enter a valid last name<br>";         }         if(out_of_range($_POST['house_num']))         {           $error_msg[] = "Please enter a valid house number";         }         if(out_of_range($_POST['street']))         {           $error_msg[] = "Please enter a valid street";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[a-zA-Z]", $_POST['street'])) $error_msg[].="Please enter a valid street<br>";         }         if(out_of_range($_POST['town']))         {           $error_msg[] ="Please enter a valid town";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[a-zA-Z]", $_POST['town'])) $error_msg[].="Please enter a valid town<br>";         }         if(out_of_range($_POST['postcode']))         {           $error_msg[] = "Please enter a valid postcode";         } else {                 // check if email is in a valid format (LN NLL or LLN NLL)                 if(!ereg("^[a-zA-Z]{1,2}[0-9][0-9A-Za-z]{0,1} {0,1}[0-9][A-Za-z]{2}$", $_POST['postcode'])) $error_msg[].="Please enter a valid postcode<br>";         }         if(out_of_range($_POST['email']))         {           $error_msg[] = "Please enter a valid email address";         } else {                 // check if email is in a valid format using a regular expression                 if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $_POST['email'])) $error_msg[].="Please enter a valid email address<br>";         }         if(out_of_range($_POST['phone']))         {           $error_msg[] = "Please enter a valid phone number";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[0-9]", $_POST['phone'])) $error_msg[].="Please enter a valid phone number<br>";         }         if(out_of_range($_POST['qty']))         {           $error_msg[] = "Please enter a valid quantity";         } else {           if($_POST['qty'] > $origstocknumber)           $error_msg[] = "Please enter a valid quantity";                 //} else {                 // check if textbox is using numerical values only                 //if(!ereg("[0-9]", $_POST['qty'])) $error_msg[].="Please enter a valid quantity*<br>";         }         if(out_of_range($_POST['provider']))         {           $error_msg[] = "Please enter a valid provider";         }         if(out_of_range($_POST['card_num']))         {           $error_msg[] = "Please enter a valid card number";         //} else {                 // check if email is in a valid format using a regular expression         //        if(!ereg("^(\d{4}[- ]){3}\d{4}|\d{16}$", $_POST['card_num'])) $error_msg[].="Please enter a card number*<br>";         }         if(out_of_range($_POST['type']))         {           $error_msg[] = "Please enter a valid type of card";         }         if(out_of_range($_POST['expires']))         {           $error_msg[] = "Please enter a valid expiry date";         } else {                 // check if textbox is using numerical values only                 if(!ereg("[0-9]", $_POST['expires'])) $error_msg[].="Please enter a valid expirey date<br>";         }         if(count($error_msg)<=0)         {         //Database entry for the customer order and customer details.         $title = mysql_real_escape_string($_POST["title"]);         $fname = mysql_real_escape_string($_POST["first_name"]);         $lname = mysql_real_escape_string($_POST["last_name"]);         $housenum = mysql_real_escape_string($_POST["house_num"]);         $street = mysql_real_escape_string($_POST["street"]);         $town = mysql_real_escape_string($_POST["town"]);         $postcode = mysql_real_escape_string($_POST["postcode"]);         $email = mysql_real_escape_string($_POST["email"]);         $phone = mysql_real_escape_string($_POST["phone"]);         $qty = mysql_real_escape_string($_POST["qty"]);         $provider = mysql_real_escape_string($_POST["provider"]);         $card_num = mysql_real_escape_string($_POST["card_num"]);         $type = mysql_real_escape_string($_POST["type"]);         $expires = mysql_real_escape_string($_POST["expires"]);         $connection = mysql_connect("***", "***", "***");         mysql_select_db("***", $connection)         or die("Unable to select database");         $query = "INSERT INTO customer VALUES ('','$title','$fname','$lname','$housenum','$street','$town','$postcode', '$email', '$phone', '$qty', '$make', '$model','$provider','$card_num','$type','$expires')";         mysql_query($query);         echo mysql_error().         mysql_close($connection);         Print "Thank you for your order";         //}         //Update totals         $connection = mysql_connect("***", "***", "***");         mysql_select_db("***", $connection)         or die("Unable to select database");         $result = mysql_query("UPDATE mobile SET stock='$stocknumber' WHERE model='$model'")         or die(mysql_error());         mysql_query($query);         echo mysql_error().         mysql_close($connection);                 //Show any error messages for the user to see in red text }         else {                 echo "<span style='font-weight: bold; color: red;'>Error(s):</span><br /><ul><li>";                 echo join('</li><li>',$error_msg);                 echo "</ul>";         //Shows data within variables if needed during testing         //foreach($_POST as $key => $value) echo "$key => $value <br>";         } } ?> [/code]
  5. >:( Arggggh I'm still getting nowhere with this, the PHP looks fine could it be something to do with the HTML form? [code=php:0] <form method="POST" action="order.php"> Title<br> <input type="text" name="title" size="20" value="<? echo $title; ?>"><p><p> First name<br> <input type="text" name="first_name" size="20" value=""><p> Last name<br> <input type="text" name="last_name" size="20" value=""><p> House Number<br> <input type="text" name="house_num" size="20" value=""><p> Street<br> <input type="text" name="street" size="20" value=""><p> Town<br> <input type="text" name="town" size="20" value=""><p> Postcode<br> <input type="text" name="postcode" size="20" value=""><p> e-mail<br> <input type="text" name="email" size="20" value=""><p> Phone Number<br> <input type="text" name="phone" size="20" value=""><p> Qty<br> <input type="text" name="qty" size="20" value=""><p> <img SRC="images/payment.png" ALT="Logo" ><p> Card number<br> <input type="text" name="card_num" size="20" value=""><p> Type<br> <select name="type"> <option>Delta</option> <option>Mastercard</option> <option>Maestro</option> <option>Visa</option> <option>Visa Electron</option> </select><p> expires<br> <input type="text" name="expires" size="20" value=""><p> <? //Create the drop down menu from the database $database ="****"; mysql_connect("****","****","****")   or die("Unable to connect to server"); mysql_select_db($database) or die ("Unable to connect to database"); $query1 = "SELECT DISTINCT name FROM sims"; $result1 = mysql_query($query1) or die ("couldnt execute query 1."); echo "Select Simcard <br> <select name='provider'>\n"; while ($row = mysql_fetch_array($result1)) { echo "<option value=\"{$row[name]}\">$row[name]</option>\n"; } echo "</select>\n"; echo  "<br>"; ?> <input type="submit" value="Buy" name="submit"> </form> <? } ?> [/code]
  6. I'm trying to get this regular expression to work, so it validates input in the correct manner such as 35p or 99p. But at the moment it's just throwing the error message at me even though it's the correct input for that field. [code=php:0]if(!ereg("^\d\d?p$", $_POST['peak'])) $error_msg[].=[/code]
  7. Thanks guys, I was hoping to try to keep the same format as I started out with so I could have a go at using regular expressions to validate if an e-mail address is in the correct format etc... Whats really got me is that the coding I originally posted works fine on another page, but refuses to work on this one. ???
  8. I'm currently trying to get some validation to work sucessfully, but it is not working >:( I don't get any error messages either, just a blank screen when I submit the data to be inserted into the database, reguardless if the IF statements have been met or not. <? if(isset($_POST["submit"])){ $error_msg=''; if(trim($_POST["name"])=='' || strlen(trim($_POST["name"])) < 6 || strlen(trim($_POST["name"])) > 15) {                 $error_msg.="Please enter a name between 6 to 15 characters long<br>";         }        if(isset($_POST["submit"])){         if(trim($_POST["peak"])=='' || strlen(trim($_POST["peak"])) < 6 || strlen(trim($_POST["peak"])) > 15) {                 $error_msg.="Please enter a peak between 6 to 15 characters long<br>";         }         if(trim($_POST["offpeak"])=='' || strlen(trim($_POST["offpeak"])) < 6 || strlen(trim($_POST["offpeak"])) > 15) {                 $error_msg.="Please enter a off peak between 6 to 15 characters long<br>";         }         if(trim($_POST["peaknet"])=='' || strlen(trim($_POST["peaknet"])) < 6 || strlen(trim($_POST["peaknet"])) > 15) {                 $error_msg.="Please enter a peaknet between 6 to 15 characters long<br>";         }         if(trim($_POST["offpeaknet"])=='' || strlen(trim($_POST["offpeaknet"])) < 6 || strlen(trim($_POST["offpeaknet"])) > 15) {                 $error_msg.="Please enter a offpeaknet between 6 to 15 characters long<br>";         }         if(trim($_POST["txt"])=='' || strlen(trim($_POST["txt"])) < 6 || strlen(trim($_POST["txt"])) > 15) {                 $error_msg.="Please enter a txt between 6 to 15 characters long<br>";         }         if(trim($_POST["picture"])=='' || strlen(trim($_POST["picture"])) < 6 || strlen(trim($_POST["picture"])) > 15) {                 $error_msg.="Please enter a picture between 6 to 15 characters long<br>";         }         // display error message if any, if not, proceed to other processing         if($error_msg==''){         $name = $_POST["name"];         $peak = $_POST["peak"];         $offpeak = $_POST["offpeak"];         $peaknet = $_POST["peaknet"];         $offpeaknet = $_POST["offpeaknet"];         $txt = $_POST["txt"];         $picture = $_POST["picture"];         $connection = mysql_connect("", "", "");         mysql_select_db("neil", $connection)         or die("Unable to select database");         $query = "INSERT INTO sims VALUES ('','$name','$peak','$peaknet','$offpeaknet','$offpeak','$txt','$picture')";         mysql_query($query);         echo mysql_error().         mysql_close($connection);         Print "New sim sucessfully created";         } } else {               echo "<font color=red face='Verdana'>$error_msg</font>";         } } ?>
  9. The variables are coming from a HTML form on another page. But I can't see anything on there to make it insert twice either. ???
  10. I'm trying to get an insert to sucessfully work with this code, it does insert the data but it does it twice. I've been looking at the code for ages but I can't see the woods for the tree's. :( Has anyone got any idea's as to why it's playing silly beggers? if(isset($_POST["submit"])){         $connection = mysql_connect("", "", "");         mysql_select_db("car_rental", $connection)         or die("Unable to select database");         $query = "INSERT INTO customer VALUES ('','$title','$fname','$lname','$housenum','$street','$town','$postcode', '$email', '$phonenum', '$make', '$model','$warrenty','$card_num','$type','$expires')";         mysql_query($query);         echo mysql_error().         mysql_close($connection);         Print "Thank you for your order";         } ?>
×
×
  • 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.