Jump to content

markschum

Members
  • Posts

    12
  • Joined

  • Last visited

Everything posted by markschum

  1. oops , sorry , I think I have it. been looking at this for too long
  2. I had this unning on my local apache server but when I uploaded it to the hosting site it fails with the error shown. Warning: PDOStatement::execute() [pdostatement.execute]: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in /home/thusuo5/public_html/interestingthings.biz/index.php on line 77 The try except The error isnt being trapped so the warning appears on the web page with the order processed message. I have counted everything, see no spelling or punctuation errors. the website is interestingthings.biz hosted by innovision. I am trying to do this for a family member and as a learning exercise. Thanks for any help. try { $dbh = new PDO('mysql:host=localhost;dbname=orders', 'user', 'password'); /*** INSERT data ***/ /*** set up the query ***/ $qry = "INSERT INTO new(type,style,material,ring,finish,font,text,name,address, email, orderdate,ip) VALUES (:ftype,:fstyle,:fmaterial,:fring,:ffinish,:ffont,:ftext,:fname, :faddress, :fcity, fzipcode, :femail, :orderdate,:ip )"; $query = $dbh -> prepare($qry); /*** run the insert ***/ $result = $query->execute(array( ":ftype" => $ftype, ":fstyle" => $fstyle, ":fmaterial" => $fmaterial, ":fring" => $fring, ":ffinish" => $ffinish, ":ffont" => $ffont, ":ftext" => $ftext, ":fname" => $fname, ":faddress" => $faddress, ":fcity" => $fcity, ":fzipcode" => $fzipcode, ":femail" => $femail, ":orderdate" => $fdate, ":ip" => $ip )); /*** close the database connection ***/ $dbh = null; /* order placed */ $errmessage = 'your order has been placed , thanks '; // fatal error trap } catch(PDOException $e) { echo "Sorry there has been an error -". $e->getMessage() . '<br><br>'; echo "Please press the BACK button on your browser and try again "; } } Thanks again for any help.
  3. well that's embarrasing , I thought I had tried that , well, live and learn. it's working. thanks
  4. Hello all, I created a database for a website using PHPAdmin and I now am trying to make some php files to create the database and tables as a backup to allow anyone to recreate the site. I have the create database code working. The Create table using pdo fails with a message saying I have an sql error. PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 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 ')' at line 18 in C:\wamp\www\create_table.php on line 33 This is my code , cobbled together from various examples. I dont see the error and have tried combinations of quotes around the table name and the field names. I had also removed the NOT NULL from the rn field. None of it worked. There was a charset and collation line at the end that I have removed. The auto increment field was added to make deletions easier by avoiding using every field in the delete where statement. Any comments appreciated. Is there a good tutorial on using pdo, I find the php manual very difficult to follow for determining what I need to do overall. <?php // create database table // database trial table new $dns = 'mysql:host=localhost;dbname=trialdb'; $user = 'root'; $pass = ''; $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $db = new PDO($dns, $user, $pass, $opt); $sql = "CREATE TABLE IF NOT EXISTS new ( rn int(6) NOT NULL AUTO_INCREMENT PRIMARY KEY, type varchar(10) NOT NULL, material varchar(10) NOT NULL, ring varchar(10) NOT NULL, finish varchar(10) NOT NULL, font varchar(20) NOT NULL, text varchar(20) NOT NULL, name varchar(20) NOT NULL, address varchar(40) NOT NULL, city varchar(20) NOT NULL, zipcode varchar(10) NOT NULL, email varchar(40) NOT NULL, style varchar(10) NOT NULL, orderdate varchar(10) NOT NULL, ip varchar(20) NOT NULL, )" ; $sq = $db->query($sql); if ($sq) { echo 'created'; } ?>
  5. ok, thanks very much. I used that and its now working. Its obvious I need a good book on mysql and php rather than trying to pick at the manuals I now need to write a bit to allow a user to add records to the product database, but I will read as you suggest before I start. thanks again.
  6. sorry Jessica , dont understand your comment.
  7. $tempdimes = ($tempquarters - $quarters)/.1; that should be a 10 surely. I dont understand your logic . amount tendered - price = change int(change) = whole dollars change - dollars = change but then your change amount is a decimal 3.76 - 3.00 = 0.76 you cant work easily on that so convert to pennies then use 25,10,5,1 as your coins Int(change/25) = quarters change - (quarters*25) = change int(change/10) = DIMES change - (dimes * 10) = change etc modulo might be easier but I dont know if there is php for that. that gives you how many dollars, quarters, dimes , nickles and pennies you give as change. I dont know if that helps. I am new to php.
  8. OK thanks I have gone with an html form posting to a php script on the server. I am putting the data into a database table until I sort out email at the server. As a temporary measure I have written a simple display page to show the enquiries. It will do for now. I do have a mysql issue though, I know its off topic for this forum but where to post ? this is the error : INSERT INTO enquiries ( id, item, email, phone, comments) VALUES ('2', 'pontoon boat 48' with 125hp twin mercury stern drive', '', '12345', '' ) Warning: mysql_query(): You have an error in your SQL syntax; and this i the code <?php // validation expected data exists if(!isset($_POST['f_email']) and (!isset($POST['f_phone']))) { echo "We're sorry, but there's errors found with the form you submitted.<br /><br />"; echo "No email address/Phone number entered<br><br>"; echo "Please go back and fix these errors.<br><br>"; die(); } if (isset($_POST['f_email'])) { $email = $_POST['f_email']; } else { $email = NULL; } if (isset($_POST['f_phone'])) { $phone = $_POST['f_phone']; } else { $phone = NULL; } if (isset($_POST['f_comments'])) { $comments = $_POST['f_comments']; } else { $comments = NULL; } $id = $_POST['f_id']; $item = $_POST['f_item']; $link = mysql_connect ("myhost","root","") or die("error:".mysql_error()); $selected = mysql_select_db("sales",$link); if ($selected) { $writetable = "INSERT INTO enquiries ( id, item, email, phone, comments)" ; $writetable .= " VALUES ('$id', '$item', '$email', '$phone', '$comments' )"; } echo $writetable; $query = mysql_query($writetable) or die(mysql_error()); ?> I have the table setup and have checked the fields are correct and will accept NULL values. any ideas ?
  9. The application is an items-for-sale list that I have done with mysql and php. If a viewer is interested in an item they need to upply contact info (email or phone) and ask any questions. These are mainly used boats. I dont want to just put up an email address or phone and say "call us" because many wont. If I use mailto I can fill in the subject and body of the mail with a basic, "yes I want this but tell me more" but it relies on a viewer having a mail app on his machine and I dont know that. I have concerns after reading about mailto: that it is not recommended and that writing to a file may introduce record locking issues for a multi-user system. Email would be a natural choice since the site owner already checks his email regularly and sales are not time critical while writing to a flat file or database can easily be diplayed to the owner via a restricted web page or even consolidated and sent through the sites own email system. . I dont know if this clarifies anything :-)
  10. I am adding a page to a website for some items for sale and need to provide a way for the viewer to enter an email address and some comments and submit that for action. I thought there was an HTML command that put the info to a flat file but I cant find anything current. Mailto: seems to have a lot of people saying dont use it . I can use PHP easily enough. Does anyone have comments in what approach to take ? Does PHP have any issues with record or file locking if I just add to a flat file ? thanks
  11. ok, thanks I will add some checking to catch those lines that may be incomplete.
  12. Hi all, I am an old guy, who used to work on IBM mainframes in Cobol and System 36 and 38 with cobol and rpg. I do some Visual basic 6, some C++ if I have too, and most recently python. A couple strokes in the past and a quintuple bypass this year have left me a bit wobbly but that will improve. I am learning some web page creation in html and php. I have Notepad++ and BlueGriffon but am not sure I like either of them. I am running Apache, PHP and MYsql on my system for a test website. Since I know that I know next to nothing about php or web coding you can say anything you like, I promise I wont be that offended ;-) Some tiips on free or cheap editors or books would be appreciated.
  13. Hi all, I am an old programmer with Cobol and RPG, some Visual Basic 6 and Python. I am starting PHP for a web site to generate parts of pages. I am running apache, php and mysql on a local machine as a test system. I am reading a file , comma delimited which contains either text , price, or a filename for a long description. <?php $fil = "./data/catalog.txt"; if (!file_exists($fil)) echo "Catalog not found - Ending <br>"; $lines = file($fil); foreach($lines as $l) { $fields = str_getcsv($l,","); echo "Item: ".$fields[0]."<br>"; echo "Price: ".$fields[1]."<br>"; if (file_exists($fields[2])) { echo $f." Decription Found<br>"; } else { echo "No Description<br>"; } } ?> I get a Notice on the lines like echo "Price; ".$Fields[1].<br>; Notice: Undefined offset: 1 in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\file_read.php on line 15 Price: Is there a better way of getting an array element or is it acceptable to just ignore the Notice. I dont mind at all if you laugh , point and make fun of this code. I am sticking bits together from the manual. regards
×
×
  • 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.