/    Sign up×
Community /Pin to ProfileBookmark

Hi all, I need to replace much of my fossilized code. can someone suggest correct pdo code for the below?

[code=php]<?php
include(“getnumbers.php”);
error_reporting(0);
mysql_connect(‘localhost’,’root’,”);
mysql_select_db(‘homedb’) or die(“Unable to select database”);
$query=” SELECT * FROM oocust WHERE id = ‘$id'”;
$result=mysql_query($query);
$num=mysql_numrows($result);[/code]

to post a comment
PHP

11 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmFeb 19.2014 — I could, but if you need help with the connect and the select in addition to just plain querying, I suggest you read up on PDO first.

The manual has some good stuff on this.
Copy linkTweet thisAlerts:
@NogDogFeb 19.2014 — You'll also want to decide if you are going to use OOP or procedural style coding. (All the cool developers use the OOP form, of course.)

Here's a brief example of the basics you'd need to execute a query (using a prepared statement): http://www.phpeveryday.com/articles/PDO-Prepared-Statement-P550.html (although I'd personally name the PDO object [B]$pdo[/B] instead of [B]$conn[/B], just to add readability).
Copy linkTweet thisAlerts:
@12StringsauthorFeb 26.2014 — Thanks NogDog & ginerjm. Would u please lok at this code. I'm past the error messages now but get a blank page ?

<?php

include ('getnumbers.php');

if(isset($_GET['acctno'])){

$acctno = trim($_
GET['acctno']);

$R = "R";

try{
$sql = "SELECT
acctno,pd,payrec,orderno,
bname,bstreet,bcity,bstate,bzip,
sname,sstreet,scity,sstate,szip,
terms,duedate
FROM oocust
WHERE acctno = :acctno AND payrec = :R AND pd = ''";
$query = $PDO->prepare($sql);
$query->bindParam (":acctno", $acctno);
$query->bindParam(":R", $R);
$query->execute();
while($row = $query->fetch(PDO::FETCH_ASSOC)){
$acctno = $row['acctno'];
$pd = $row['pd'];
$payrec = $row['payrec'];
$orderno = $row['orderno'];
$bname = $row['bname'];
$bstreet = $row['bstreet'];
$bcity = $row['bcity'];
$bstate = $row['bstate'];
$bzip = $row['bzip'];
$sname = $row['sname'];
$sstreet = $row['sstreet'];
$scity = $row['scity'];
$sstate = $row['sstate'];
$szip = $row['szip'];
$terms = $row['terms'];
$duedate = $row['duedate'];

// the below code is for the date
$format = "D M d Y g:ia";
$date = date($format, time());
// the above code is for the date

$tax = $payable * $taxrate;
$amtdue = $payable + $tax + $shipamt;
$currdate = date('Y-m-d');
$date1 = $duedate;
$date2 = $currdate;
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));

// echo "Difference is $months months, $days days.";

$dayslate = $months *30;

$dayslate = $dayslate + $days;

$query = "

INSERT INTO oocust (acctno,status,pd,payrec,orderno,bname,bstreet,bcity,bstate,bzip,bemail,

phone,contact,sname,sstreet,scity,sstate,szip,semail,terms,fob,shipdate,shipamt,

dateord,datecomp,duedate,qty,descr,payable,tax,paidamt,datepaid,dayslate,checkno,

amtdue,prevbal,balance)

VALUES ('$acctno',$status','$pd','$payrec','$orderno','$bname','$bstreet','$bcity',

'$bstate','$bzip','$bemail','$phone','$contact','$sname','$sstreet','$sscity','$sstate',

'$szip','$semail','$terms','$fob','$shipdate','$shipamt','$dateord','$datecomp',

'$duedate','$qty','$descr','$payable','$tax','$paidamt','$datepaid','$dayslate',

'$checkno,'$amtdue','$prevbal,','$balance')";

}

}catch (PDOException $e){
echo "Database error: ".$e->getMessage();
}

}

?>

</form></center></body></html>
Copy linkTweet thisAlerts:
@ginerjmFeb 26.2014 — Can we see the new code now?
Copy linkTweet thisAlerts:
@ginerjmFeb 26.2014 — Ok - the first time I came to see your message, the code was not yet there.

BTW - CAN YOU FOLLOW THE RULES AND USE THE CODE/PHP TAGS TO HELP MAKE YOUR FORMATTED CODE LOOK MORE PRESENTABLE?

So now that I can read your code in my own editor, tell me what error to look for other than the query you never execute.

BTW - if you turn on error checking you may see some errors that are the cause of a blank page.
Copy linkTweet thisAlerts:
@ginerjmFeb 26.2014 — ACTUALLY - your script is probably working perfectly! You don't output anything from the script as it sits right now, so success at least means you won't see anything.
Copy linkTweet thisAlerts:
@12StringsauthorMar 03.2014 — hi guys, take a break from the tough stuff.

I could use some help here. I don't understand this one. Below is the 'fetch_taxrate'

code.

[code=php]<?php
$taxrate=$_POST['search_term'];
$stat = mysql_connect('localhost','root','');
$stat = mysql_select_db('homedb');
$query = "SELECT taxrate FROM numbers Where taxrate='$taxrate'";
$stat = @mysql_fetch_assoc(mysql_query($query));
echo $stat["taxrate"];
?> [/code]


Below is the 'numbers' sql

id receiptno orderno taxrate bank

1 154 150 0.575 999.99
[/QUOTE]

Here is the message:
Warning: require(includes/fetch_taxrate.php): failed to open stream:

No such file or directory in C:xampphtdocsinvoiceinvoiceinsert.php on line 101

Fatal error: require(): Failed opening required 'includes/fetch_taxrate.php'

(include_path='.;C:xamppphpPEAR') in C:xampphtdocsinvoiceinvoiceinsert.php

on line 101
[/QUOTE]

[code=php] </script>
</head>
<body bgcolor="#ccffff"><center>

<input type="text" name="Date[]" size="25" onFocus="this.value=''" value="Date - <?php echo $date;?>

<input type="text" name="acctno[]" size="25" STYLE="color: #000000; background-color: #72A4D2;" onFocus="this.value=''" value="Acct#<?php echo $acctno;?><br>

<!--Copies "Bill To" info to "Ship To" info.-->
<form name='form' action="" method="post">
<?php
require "includes/fetch_taxrate.php";
if(isset($_GET['acctno']))
try
{

$sql = "SELECT
acctno,status,pd,payrec,orderno,bname,bstreet,bcity,bstate,bzip,
phone,contact,sname,sstreet,scity,sstate,szip,terms,fob,shipdate,
shipamt,dateord,datecomp,duedate,qty,descr,payable,tax,paidamt,
datepaid,dayslate,checkno,amtdue,prevbal,balance
FROM oocust WHERE payrec = 'R' && pd = ''";

$query = $PDO->prepare($sql);
$query->execute();
while($row = $query->fetch(PDO::FETCH_ASSOC))
{

$acctno=$_POST['acctno'];
$status=$_POST['status'];
$pd=$_POST['pd'];
$payrec=$_POST['payrec'];
$orderno=$_POST['orderno'];
$bname=$_POST['bname'];
$bstreet=$_POST['bstreet'];
$bcity=$_POST['bcity'];
$bstate=$_POST['bstate'];
$bzip=$_POST['bzip'];
$bemail=$_POST['bemail'];
$phone=$_POST['phone'];
$contact=$_POST['contact'];
$sname=$_POST['sname'];
$sstreet=$_POST['sstreet'];
$scity=$_POST['scity'];
$sstate=$_POST['sstate'];
$szip=$_POST['szip'];
$semail=$_POST['semail'];
$terms=$_POST['terms'];
$fob=$_POST['fob'];
$shipdate=$_POST['shipdate'];
$shipamt=$_POST['shipamt'];
$dateord=$_POST['dateord'];
$datecomp=$_POST['datecomp'];
$duedate=$_POST['duedate'];
$qty=$POST['qty'];
$descr=$_POST['descr'];
$payable=$_POST['payable'];
$tax=$_POST['tax'];
$paidamt=$_POST['paidamt'];
$datepaid=$_POST['datepaid'];
$dayslate=$_POST['dayslate'];
$checkno=$_POST['checkno'];
$amtdue=$_POST['amtdue'];
$prevbal=$_POST['prevbal'];
$balance=$_POST['balance'];
$currdate = date('Y-m-d');
$date1 = $duedate;
$date2 = $currdate;
$diff = abs(strtotime($date2) - strtotime($date1));
$years = floor($diff / (365*60*60*24));
$months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
$days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
// echo "Difference is $months months, $days days
$dayslate = $months *30; // ?
$dayslate = $dayslate + $days; // ?
$sql2 = "
INSERT INTO oocust (acctno,status,pd,payrec,orderno,bname,bstreet,bcity,bstate,bzip,
phone,contact,sname,sstreet,scity,sstate,szip,terms,fob,shipdate,shipamt,
dateord,datecomp,duedate,qty,descr,payable,tax,paidamt,datepaid,dayslate,checkno,
amtdue,prevbal,balance)
VALUES ('$acctno',$status','$pd','$payrec','$orderno','$bname','$bstreet','$bcity',
'$bstate','$bzip','$phone','$contact','$sname','$sstreet','$sscity','$sstate',
'$szip','$terms','$fob','$shipdate','$shipamt','$dateord','$datecomp',
'$duedate','$qty','$descr','$payable','$tax','$paidamt','$datepaid','$dayslate',
'$checkno,'$amtdue','$prevbal,','$balance')";
?>[/code]

[code=html]function copyAddress() {
document.Form.sname.value=document.Form.bname.value
document.Form.sstreet.value=document.Form.bstreet.value
document.Form.scity.value=document.Form.bcity.value
document.Form.sstate.value=document.Form.bstate.value
document.Form.szip.value=document.Form.bzip.value
document.Form.semail.value=document.Form.bemail.value
}
</script>
<!-- Start of Bill To table -->
<TABLE><tr>

<td>
<input type="text" readonly name="BillTo[]" size="25" value="Bill To" STYLE="color: #000000; background-color: #72A4D2;" onFocus="this.value=''"><br>
<input type="text" name="bName[]" size="25" onFocus="this.value='' value="Name - <?php echo $bname;?><br>

<input type="text" name="bStreet[]" size="25" onFocus="this.value='' value="Street - <?php echo $bstreet;?><br>
<input type="text" name="bCity[]" size="25" onFocus="this.value='' value="City - <?php echo $bcity;?><br>

<input type="text" name="bState[]" size="25" onFocus="this.value='' value="State - <?php echo $bstate;?><br>

<input type="text" name="bZip[]" size="25" onFocus="this.value='' value="Zip - <?php echo $bzip;?><br>

<input type="text" name="bemail[]" size="25" onFocus="this.value='' value="Email - <?php echo $bemail;?><br>
</td>
<!--End of Bill To table -->
<!-- Start of Ship To table -->
<td>

<input type="text" readonly name="ShipTo[]" size="25" value="Ship To" STYLE="color: #000000; background-color: #72A4D2;" onFocus="this.value=''"><br>

<input type="text" name="sName[]" size="25" onFocus="this.value='' value="Name - <?php echo $sname;?><br>
<input type="text" name="sStreet[]" size="25" onFocus="this.value='' value="Street - <?php echo $sstreet;?><br>
<input type="text" name="sCity[]" size="25" onFocus="this.value='' value="City - <?php echo $scity;?><br>

<input type="text" name="sState[]" size="25" onFocus="this.value='' value="State - <?php echo $sstate;?><br>

<input type="text" name="sZip[]" size="25" onFocus="this.value='' value="Zip - <?php echo $szip;?><br>
<input type="text" name="sEmail[]" size="25" onFocus="this.value='' value="Email - <?php echo $semail;?><br>

</td> </td>

<!--End of Ship To table -->
<tr><td>
<INPUT onclick=copyAddress() type="button" size=35 value="Click if Ship To Address is Same as Bill To">
</td>
</TR></TBODY></TABLE><br>
<hr align=center width=48%>
<table border=0 cellpadding=10 cellspacing=10>

<tr>
<th>Taxable?</th>
<th>Recurring?</th>
<th>Paid?</th>
<th>Account type</th>
<th>Terms:</th>
<th>FOB:</th>

<tr>
<hr align=center width=48%>
<td>
<SELECT name=taxable>
<OPTION value="">
<OPTION class=highlight value="N" selected>No
<OPTION class=highlight value="Y">Yes
</OPTION></SELECT>

<SELECT name=recur>
<OPTION value="">
<OPTION class=highlight value="Y" selected>Yes
<OPTION class=highlight value="N">No
</OPTION></SELECT>

<SELECT name=pd>
<OPTION value="">
<OPTION class=highlight value="p" selected>Yes
<OPTION class=highlight value=" "> No
</OPTION></SELECT>

<SELECT name=payrec>
<OPTION value="">
<OPTION class=highlight value=R selected>receivable
<OPTION class=highlight value=P>payable
</OPTION></SELECT>

<SELECT name=terms>
<OPTION value="">
<OPTION class=highlight value=net_10 selected>Net 10
<OPTION class=highlight value=1_10_30>1 10 Net 30
<OPTION class=highlight value=2_10_30>2 10 Net 30
<OPTION class=highlight value=cash>Cash

</OPTION></SELECT>
<SELECT name=fob>
<OPTION value="">
<OPTION class=highlight value=Destination selected>Destination
<OPTION class=highlight value=Origin>Origin

</OPTION></SELECT></td></tr></table><br>
<hr align=center width=48%>
DATES <font color="blue">(yyyy-mm-dd)</font><br>
<input type="text" name="shipdate[]" size="25" onFocus="this.value=''" value="Ship Date - <?php echo $shipdate;?>
<input type="text" name="dateord[]" size="25" onFocus="this.value=''" value="Date Ordered - <?php echo $dateord;?>
<input type="text" name="datecomp[]" size="25" onFocus="this.value=''" value="Date Completed - <?php echo $datecomp;?>
<input type="text" name="datepaid[]" size="25" onFocus="this.value=''" value="Date Paid - <?php echo $datepaid;?>
<input type="text" name="DueDate[]" size="25" onFocus="this.value=''" value="Due Date - <?php echo $duedate;?>
<hr align=center width=48%>
<input type="text" name="Orderno[]" size="10" onFocus="this.value=''" value="Order# - <?php echo $orderno;?>
<input type="text" name="qty[]" size="5" onFocus="this.value=''" value="qty - <?php echo $qty;?>
<input type="text" name="payable[]" size="7" onFocus="this.value=''" value="Charges - <?php echo $payable;?>
<input type="text" name="tax[]" size="6" onFocus="this.value=''" value="Tax - <?php echo $tax;?><br>
<hr align=center width=48%>
<input type="text" name="paidamt[]" size=7 onFocus="this.value=''" value="Amt Paid# - <?php echo $paidamt;?>
<input type="text" name="checkno[]" size=15 onFocus="this.value=''" value="Check# - <?php echo $checkno;?>

<input type="text" name="shipamt[]" size=7 onFocus="this.value=''" value="Ship Amt - <?php echo $shipamt;?><br>
<INPUT type="submit" name="submit" value="submit data">
</tr></table> [/code]

[code=php]<?php
$query2 = $PDO->prepare($sql2);
$query2->execute();
}

}
catch (PDOException $e)
{

echo "Database error: ".$e->getMessage();

}

?>[/code]

[code=html]</form></center></body></html>
[/code]
Copy linkTweet thisAlerts:
@ginerjmMar 03.2014 — Your code is a confusing mass of pieces that we cannot make much sense of.

As for the error you showed us, you obviously have a problem locating a file that you are trying to include in your script. Fix it.
Copy linkTweet thisAlerts:
@12StringsauthorMar 03.2014 — Thanks for the response ginerjim. Yeah I wouldn't expect anyone to follow that load of code, especially from me LOL. All I

need is someone smarter than me to explain how my statment "require "includes/fetch_taxrate.php"; " failed.
Copy linkTweet thisAlerts:
@ginerjmMar 03.2014 — Can't tell you why you are getting the message other than it is telling you exactly what it sees as wrong. On a specific line no. in a specific script you have a statement that can not find the path/filename that you asked for. Check your server folders for the filename and then change that path/filename in that require line to point correctly.
Copy linkTweet thisAlerts:
@saddamh146Mar 03.2014 — Thanks
×

Success!

Help @12Strings spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.3,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...