It’s meant for designers not developers.
The code it uses is highly bloated and out dated.
It’s expensive for what it is and does.
can anyone tell me why i get a 404 error when i run these 2 portions of script:
<form id="shoppingCart" method="POST" class="form-inline" name="basket_form" action="Connections/testit0.php">
<div class="content">
<div class="navbar">
<div class="navbar-inner">
<ul class="nav custom_nav">
<li class="pull-left">
<div>
<a href="http://exxxxd.co" class="btn btn-info">
<i class="icon-hand-left icon-white"></i>
Continue Shopping
</a>
</div>
and:
[php]<?php
/*** mysql hostname ***/
$hostname = ‘localhost’;
/*** mysql username ***/
$username = ‘xxxx’;
/*** mysql password ***/
$password = ‘xxxx’;
try {
$dbh = new PDO(“mysql:host=$hostname;dbname=mysql”, $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo ‘Connected to database
’;
catch(PDOException $e) {
echo “An Error Occurred. The Error Is Being Processed!”; //user friendly message
some_logging_function($ex->getMessage());
}
?>
[/php]
shouldn’t the values i enter into the shopping cart be passed on to the php script above then inserted into the db fields? is this the flow?
404 means page not found. It says that. It means you do not have a file in the Connections/ directory named testit0.php from the location the script is running.
i looked in the connections folder and i received a error log. this is what it read,
“[12-Dec-2015 06:56:25 UTC] PHP Parse error: syntax error, unexpected ‘catch’ (T_CATCH) in /home/ewff/public_html/Connections/testit0.php on line 31”
please someone explain. is this the reason i’m not getting the connection?
I’m pretty sure I pointed that out in another post. Your try catch is missing needed brackets. Which is the reason for the error.
Slade, you have your TRY-CATCH set up wrong. It should be loosely like this:
try {
…some code…
} catch(…some exception…) {
…some code to handle the exception…
}
As you see, in your connection code you last posted is missing the bracket before CATCH !
Hope that helps…
if it makes a difference i do have a laptop that does not have dreamweaver on it but what would i use for editing? should i migrate all his to another machine that does not have dreamweaver on it?
i added the bracket and i still get the 404 error. i’ll keep working at it.
Well, Slade, I use Dreamweaver for quick jobs and have no problems. You must not take everything so
strictly. Many people have their favorite editors. A lot of people use only Notepad++ which is free. I use that
to make small one-line changes. But, yes, Dreamweaver is more for designing, but, again I use it often.
Now, back to your 404 error. That is saying that you are not finding your page. Therefore, you are either
going to the wrong URL address in your browser to test your page, or the file is not where you think it is.
The TRY-CATCH still needs the missing bracket.
I never use Dreamweaver to test a site. I go to the site thru the browser. Then, I re-test with other ones.
Testing is normally done under IE, Chrome and Firefox. ( And, sometimes Safari on an iPad or other… )
So, in DW, you save your code somewhere. If you hover over the name of the file, it tells you where it is
stored. Then, go to that file and open it in a browser. I think you said you have a local server and a
hosted one somewhere. If the file works on one and not the other, then use Astonecipher’s code to have
two different connections. Where it test which you are running the code from and then takes the correct
connection code.
During this time, if you get a 404, either the file does not exist or it is being re-directed to another page
that does not exist. If it is a login page that redirects to a home page, maybe the home page is missing.
Also, place these at the top of your PHP page so that they display more error messages…
[php]
error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
[/php]
How have you debugged this code so far? Have you tried the old faithful DIE() function to track where it
is dying? TO do that, you just insert this line a few lines down the page.
[php]
die(“The page got here…”);
[/php]
This will KILL your page and display this message. If you see it, move it a few lines further down. Once
you do not see it, but instead get the 404 message, you know about where your code is dying. Then, you
can fix the lines in error.
Not sure if this helps, but, connection code is not this complicated. Hope you can track down the bad code!
Good luck!
well it looks like this is where i am stuck now:
<form id="shoppingCart" method="POST" class="form-inline" name="basket_form" action="Connections/order.php">
this is how i see it: the user inputs data into the form, the values go to the php script
“order” in the Connections folder. from there those values are passed to the fields of the db. after inputing data into the fields of this form i get no results posted to the db when i look in the my phpadmin control panel.
i can connect to the database and i can see the table i set up via the dreamweaver mysql panel but i see none of the values passed to the database. what gives?
Well…
the user inputs data into the form, the values go to the php script "order" in the Connections folder. from there those values are passed to the fields of the db. after inputing data into the fields of this form i get no results posted to the db when i look in the my phpadmin control panel.Let's debug it one by one... 1 - user inputs data 2 - vales to to order.php 3 - db is updated 4 - no new data in db
So, step one is your form. Assuming that it is all set and good to go, we can skip #1
2 - To debug that one is very simple. In the order.php file that is in the Connections folder, just start it off
with a display of the posted values to make sure it is getting passed onto that page. To do that just print
the POST array, like this: (Place this at the top of the order.php file’s page.)
[php]
[/php]
What this will do for you is cause the system to stop when the order.php file is executed and it will display
ALL of the values that were passed to it. If this is empty, then the data is not being sent to the order.php
file. If it has data in it, then you can read the values and make sure it is passing all of the data you need.
If that step is good, then move on to #3…
3 - Updating the database is easy to check also. You create a QUERY from the posted data, I am assuming
this is inside the order.php file. So, you grab all of the data from the posted form. You place them into a
bunch of variables. You validate the variables to make sure they are safe. Then, you build a query that is
supposed to update the database. SO, loosely, you have something like…
$value=$_POST[“something”]; $query=“UPDATE something…”; mysqli_query($conn, $query)
Now just place this command between the $query= and the mysqli_query():
[php]
die($query); // Or whatever your query string is…
[/php]
This will kill your page and show you the actual live query you are attempting to run against your server.
You can read it and see what is wrong with it…
So, basically, Slade, you need to step thru your four part process and see where it is failing. One step at a
time. Debugging is the most annoying of processes. But, if you think it out, it is only four steps in your site.
Good luck, let us know how it goes…
The issue I see, and I may very well be wrong, is this Connections/order.php.
If you are running this on a Linux server, Connections/ is not the same as connections/.
The path to get to the file may be incorrect, a common beginner issue.
Try going to the page directly, www.yourdomain.com/whatever_directory_the_orderform_is_in/Connections/order.php
Either you will get something that say you are on the right page, or a 404 page.
After ensuring you ARE being directed to the proper page, you can really commence debugging.
seriously working on it. what i have now is when i preview the order.php in the browser i get a blank screen staring back at me and it doesn’t allow me to view the page source when rt mouse click but what is it does do is duplicate the page. i get no 404 or 500 error message. is this a good sign?
i still cannot track down the error. where can i find a error log for this? here is how the order.php looks now:
[php]
Untitled Document <?php print_r($_POST); die("Got Here...Connections-order.php"); error_reporting(E_ALL); ini_set('display_errors', 1); /*** mysql hostname ***/ $hostname = 'xxxx.co'; /*** mysql username ***/ $username = 'xxxx'; /*** mysql password ***/ $password = 'xxxx'; try { $dbh = new PDO("mysql:host=$hostname;dbname=mysql" $user, $password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $db->setAttribute(PDO::ERRMODE_EXCEPTION); /*** echo a message saying we have connected ***/ echo 'Connected to database'; }catch(PDOException $e) { echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message some_logging_function($ex->getMessage()); } ?>
[/php]
nothing printed when i put it through preview in browser in dreamweaver where it updates the testing server. i also put the url in the address bar and got the same blank screen and behavior as i mentioned above. i know this is a really thick question but where do i see where the errors are i have made in the script?
also there is a image attached showing the db structure. i feel like i’m getting closer.
Well, you should put this part of your code at the TOP of your page first.
Also, if you have two scripts, one working and one not. Compare both to each other and find out why one
works and the other doesn’t. Just place the DIE(“got…here…”); near the top of both and run them. Then,
move them both down a few lines and eventually, you will see where it is dying.
At top of page…
[php]
error_reporting(E_ALL);
ini_set(‘display_errors’, 1);
print_r($_POST);
die(“Got Here…Connections-order.php”);
[/php]
If that page is reached, you should get something displayed. If not, then it is the calling page that is not
sending the code to this page…
what is the calling page, the form itself?
i added the code to the top of the php page, thusly:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
print_r($_POST);
die("Got Here...Connections-order.php");
/*** mysql hostname ***/
$hostname = 'exxf.co';
/*** mysql username ***/
$username = 'xxxx';
/*** mysql password ***/
$password = 'xxxx';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=mysql" $user, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';
}catch(PDOException $e) {
echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message
some_logging_function($ex->getMessage());
}
?>
i still need to know where i can find error logs…
i have several other domains so i’m going to test the script with a fresh site to see if i can get it right there.
thanks, guys.
So, Slade??? You put HTML above the code we showed you? That is NOT at the top…
Anyway, it should still show you what your $_POST array includes. Then, you can look thru it and figure
out what is being posted to the page. In that way, you know what is being sent to your other code and
you can debug where it is dying…
Did that make sense?
yes, it makes tons of sense. but it’s not happening. i moved the code to the top of the page and i’m getting the same result. where should i look for an error code? i type the url in the browser and get the same result as before. here is the url:
http://eyewasframed.co/Connections/order.php
i am attempting to setup a connection on another site and i will update you on my results…
you’re great ErnieAlex. thanks.
here is the script as ran through dreamweaver when testing connection with another site. i get this error message when inputting the url in the address bar:
"Parse error: syntax error, unexpected ‘$user’ (T_VARIABLE) in /homepages/19/d296853194/htdocs/SolutionM3/Untitled-2.php on line 41
"
here is the code:
<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);
print_r($_POST);
die("Got Here...Connections-order.php");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<?php
/*** mysql hostname ***/
$hostname = 'xxxx.com';
/*** mysql username ***/
$username = 'xxxx';
/*** mysql password ***/
$password = 'xxxx';
try {
$dbh = new PDO("mysql:host=$hostname;dbname=mysql" $user, $password); /****this is line 41***/
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
$db->setAttribute(PDO::ERRMODE_EXCEPTION);
/*** echo a message saying we have connected ***/
echo 'Connected to database<br />';
}catch(PDOException $e) {
echo "An Error Occurred. The Error Is Being Processed!"; //user friendly message
some_logging_function($ex->getMessage());
}
?>
<body>
<?php
// define variables and set to empty values
$item = $temple = $quantity = $price = $promotional = "";
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$item = ordertest01($_POST["item"]);
$temple = ordertest01($_POST["temple"]);
$quantity = ordertest01($_POST["quantity"]);
$price = ordertest01($_POST["price"]);
$promotional = ordertest01($_POST["promotional"]);
}
function ordertest01($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$item = htmlspecialchars($_POST['Item']);
$temple = htmlspecialchars($_POST['Temple']);
$quantity = htmlspecialchars($_POST['Quantity']);
$price = htmlspecialchars($_POST['Price']);
$promotional = htmlspecialchars( $_POST['Promotional']);
$stmt->bindParam(':item', $item);
$stmt->bindParam(':temple', $temple);
$stmt->bindParam(':quantity', $quantity);
$stmt->bindParam(':price', $price);
$stmt->bindParam(':promotional', $promotional);
$result = $db->exec("INSERT INTO order0001(Item, Temple, Quantity, Price, Promotional) VAULES (':item', ':temple',
':quantity', ':price', ':promotional')";
header( "Location: http://www..com/.....html" )
/*** close the database connection ***/
$dbh = null;
?>
</body>
</html>
i take it that i should get error messages like this for the other site? i did not attempt to pass any values with this site, just checked the connection. i wonder why i don’t get this same response on the site i’m working on.
You are using $user in your connection but the variable is $username
i made the change and still the same error message