Forum Moderators: coopster
Parse error: parse error, unexpected T_VARIABLE in /home/example/public_html/test3/verwerken.php on line 38
Does anyone know how to solve this?
Thank you very much in advance,
Stefan.
[edited by: jatar_k at 5:31 pm (utc) on April 22, 2005]
[edit reason] no urls thanks [/edit]
edited by: jatar_k at 5:31 pm (utc) on April 22, 2005
no urls thanks
mail("$email", "Bestelling GSM-Deurbel", "Geachte $name,\nBedankt voor uw bestelling. Als de betaling is
ontvangen, wordt het pakketje binnen 7 werkdagen bij u thuis bezorgt.\n\nU kunt het bedrag (€80,-)
overmaken op onze girorekening 4338942 of via paypal naar bestellen@example.nl.\n\nUw gegevens (ter
bevestiging):\n$naam\n$straat\n$postcode\n$plaats\n$telefoonnummer\n$email\nAls deze gegevens niet
kloppen, laat het ons dan z.s.m. weten (bestellen@example.nl).");
mail("sdegraaf@example.com", "Bestelling GSM-Deurbel", "Nieuwe bestelling voor de GSM-Deurbel. Gegevens
van de klant:\n\n$naam\n$straat\n$postcode\n$plaats\n$telefoonnummer\n$email");
$ip = getenv ( 'REMOTE_ADDR' );
$tijd = date ( 'D M j' );
$host = "localhost";
$gebruiker = "narutouz_goten";
$wachtwoord = "XHoIS";
$db = "narutouz_ict";
$dbtable = "bestellen";
mysql_connect($host,$gebruiker,$wachtwoord) or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
$toevoegen = 'INSERT INTO $dbtable values('$naam','$straat','$postcode','$plaats','$telefoonnummer','$email','$ip','$tijd';
mysql_query($toevoegen) or die(mysql_error());
?>
[edited by: jatar_k at 6:37 pm (utc) on April 22, 2005]
[edit reason] generalized email addresses [/edit]
problem is the above has mismatched quotes and, as cazgh mentioned, a missing ).
try this way
$toevoegen = "INSERT INTO $dbtable values('$naam','$straat','$postcode','$plaats','$telefoonnummer','$email','$ip','$tijd')";
when the parser was encountering the second single quote in that string it was ending that string assignment so it had no idea what to do with the rest of the line.
Uw gegevens:TestTeststreet144817BVTesttown5282978me@me.comAls deze gegevens niet kloppen, laat het ons dan z.s.m. weten (bestellen@example.nl).
I also get a new error message:
Column count doesn't match value count at row 1
Do you know how to solve this?
[edited by: jatar_k at 5:25 pm (utc) on April 28, 2005]
[edit reason] generalized url [/edit]
it means you aren't passing the proper number of values for your insert. You have 2 options
[dev.mysql.com...]
1. when you build your insert statement you can include a column list like so
$toevoegen = "INSERT INTO $dbtable (col_name1, col_name2, col_name3, ....) values('$value1', '$value2', '$value3', .....)";
2. you need to include every column in the table when passing an insert with out a column list
1: The information I print to the browser with the PRINT function is still put after each other (it doesn't put the submitted info of each field on a new line). How can I do this? I thought with \n but it doesn't work.
2: Also, I need some way to show the administrator all the info which is submitted on a page (older submissions at the bottom and newer at the top). How can I do this and how can I let the admin change the submitted info without using PHPMyAdmin?
I don't quite track on question number two ...? I don't use phpMyAdmin, but it seems as though you are asking how to display entries in the database in date-entered order?
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/narutouz/public_html/ict/aanpassen.php on line 27
My PHP code which should be able to do what I said above:
<?
mysql_connect("localhost","user","pass");
mysql_select_db("narutouz_ict"); if(!isset($cmd))
{
$result = mysql_query("select * from bestellen order by ID");
while($r=mysql_fetch_array($result))
{
$titel=$r["Naam"];
$id=$r["ID"];
echo "<a href='aanpassen.php?cmd=edit&id=$id'>$titel - Aanpassen</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" ¦¦ $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["ID"];
$sql = "SELECT * FROM bestellen WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
Can you tell me what the problem is? Thanks in advance.
[edited by: coopster at 2:04 am (utc) on April 28, 2005]
[edited by: jatar_k at 5:24 pm (utc) on April 28, 2005]
[edit reason] snipped irrelevant code and user/pass [/edit]
$id = $_GET["ID"];
$sql = "SELECT * FROM bestellen WHERE id=$id";
exit("\$sql is: $sql");
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
$sql is: SELECT * FROM bestellen WHERE ID=
But shouldn't it display the id-number behind ID=? This is my table:
CREATE TABLE `bestellen` (
`ID` int(11) NOT NULL auto_increment,
`Naam` varchar(50) default NULL,
`Straat` varchar(50) default NULL,
`Postcode` varchar(50) default NULL,
`Plaats` varchar(50) default NULL,
`Telefoonnummer` varchar(50) default NULL,
`Email` varchar(50) default NULL,
`Betaald` varchar(50) default NULL,
`ip_ad` varchar(25) default NULL,
`log_date` datetime default NULL,
PRIMARY KEY (`ID`)
) TYPE=MyISAM AUTO_INCREMENT=8 ; I still can't figure out what would be wrong. I also tried using $sql = "SELECT * FROM bestellen WHERE ID=$id"; instead of id=$id"; which also didn't work.
I changed
$sql = "SELECT * FROM bestellen WHERE ID=$id";
To
$sql = "SELECT * FROM bestellen WHERE ID='$id'";
Is this allowed? Or doesn't it show anything because it doesn't recognise the command? Thanks.
PS: Is this correct by the way (maybe I've made a mistake somewhere so that it doesn't show the info from the database in the fields): <input type="TEXT" name="betaald" value="<?php echo $myrow["Betaald"]?>" size=30>
[edited by: dbzfyam at 4:05 pm (utc) on April 28, 2005]
if (!isset($_POST["submit"]))
meaning you only want to select the id when they haven't submitted the form?
I am not sure but it seems that it should be
if(isset($_POST["submit"]))
if that test is backwards then it might be executing that code when the id isn't there yet instead of when it is. The GET id obviously isn't there so I am guessing the logic is wring somewhere.
1. no cmd sent
2. cmd sent but no submit
3. cmd sent and submit sent
I see cmd can be passed either by get or post so we will account for that.
if there are any other cases then my code won't be right ;)
so , we can try setting up a little testing to see what is blowing out. We'll test the 2 vars we care about and set them up for later use first, I like yes and no because it reads well, though you could use 1 and 0 but whatever.
$cmd = 'no';
$submit = 'no';
if (isset($_GET['cmd'])) {
$cmd = $_GET['cmd'];
} else if (isset($_POST['cmd'])) {
$cmd = $_POST['cmd'];
}
if (isset($_POST['submit'])) $submit = 'yes';
alright so now we have our values set up and we aren't using straight post or get values either which I don't like doing. Now we need to set up our three combinations of these values. We try to find the uniqueness in each so we don't have to test everything every time and I also try to put the most common first but I will just go with your order
if ($cmd == 'no') {
echo '<p>cmd is no';
} else if ($submit == 'no' && $cmd == 'edit') {
echo '<p>cmd is set but submit is not there';
} else {
echo '<p>cmd is set and submit exists';
} there are a couple of other ways to do this as well, testing for submit and then dropping into a switch on cmd but I figure I will just set up the 3 known cases for now. The final else to trap anything that doesn't pass any previous test. Obviously this is a simple test that just echos what was found but I usually start with something like this to make sure that my logic works before I add in a ton of other code and then smash my head against the keyboard for hours because of a simple logic problem. :)
If we add in the connect code above that block with some added 'or die's, that should be removed once the script is completed, and drop in the selects that you have in your original. This is my normal next step when creating a script to make sure
a) that my logic still works
b) that my selects are being created properly
we should probably get the id now as well
mysql_connect("localhost","goten","HXoSI") or die ('connect: ' . mysql_error());
mysql_select_db("narutouz_ict") or die ('selectdb: ' . mysql_error());
$cmd = 'no';
$submit = 'no';
$id = -1;
if (isset($_GET['cmd'])) {
$cmd = $_GET['cmd'];
} else if (isset($_POST['cmd'])) {
$cmd = $_POST['cmd'];
}
if (isset($_POST['submit'])) $submit = 'yes';
if (isset($_GET['ID']) $id = $_GET['ID'];
if ($cmd == 'no') {
$sql = "select * from bestellen order by ID";
echo '<p>cmd is no';
echo '<br>',$sql;
} else if ($submit == 'no' && $cmd == 'edit') {
$sql = "SELECT * FROM bestellen WHERE id=" . $id;
echo '<p>cmd is set but submit is not there';
echo '<br>',$sql;
} else {
echo '<p>cmd is set and submit exists';
} from there, if all of that works, then it is only a matter of putting your fetch_arrays back in
>> I tried you code to see if it works and it does see the correct command and/or submit
perfect, so we got the logic to work. The next step is to remove all of the echo junk I threw in there and put back all of your sql queries
some other parts could probably be optimized but that should maybe be another lesson ;)
I will just plug it back together and we will see if it works, maybe it will, maybe it won't, I added those 'or die's to your queries as well in case something else goes wrong
<?
// db connect
mysql_connect("localhost","user","pass");
mysql_select_db("narutouz_ict");
// check and initialize
$cmd = 'no';
$submit = 'no';
$id = -1;
if (isset($_GET['cmd'])) {
$cmd = $_GET['cmd'];
} else if (isset($_POST['cmd'])) {
$cmd = $_POST['cmd'];
}
if (isset($_POST['submit'])) $submit = 'yes';
if (isset($_GET['ID']) $id = $_GET['ID'];
// done checking everything now let's do some querying
if ($cmd == 'no') {
$sql = "select * from bestellen order by ID";
$result = mysql_query($sql) or die ('cmd=no died: ' . mysql_error());
while($r=mysql_fetch_array($result)) {
$titel=$r["Naam"];
$id=$r["ID"];
echo "<a href='aanpassen.php?cmd=edit&id=$id'>$titel - Aanpassen</a>";
echo "<br>";
}
//echo '<p>cmd is no';
//echo '<br>',$sql;
} else if ($submit == 'no' && $cmd == 'edit') {
$sql = "SELECT * FROM bestellen WHERE id=" . $id;
$result = mysql_query($sql) or die ('cmd=edit died: ' . mysql_error());
$myrow = mysql_fetch_array($result);
//echo '<p>cmd is set but submit is not there';
//echo '<br>',$sql;
}
?>
I also removed the else on there because I didn't know of any code to go in there, try that
<?
mysql_connect("localhost","username","password");
mysql_select_db("database");
if(!isset($cmd))
{
$result = mysql_query("select * from bestellen order by ID");
while($r=mysql_fetch_array($result))
{
$titel=$r["Naam"];
$id=$r["ID"];
echo "<a href='aanpassen.php?cmd=edit&id=$id'>$titel - Aanpassen</a>";
echo "<br>";
}
}
?>
<?
if($_GET["cmd"]=="edit" ¦¦ $_POST["cmd"]=="edit")
{
if (!isset($_POST["submit"]))
{
$id = $_GET["ID"];
$sql = "SELECT * FROM bestellen WHERE id=$id";
$result = mysql_query($sql);
$myrow = mysql_fetch_array($result);
?>
with your code. It does display the rows from the table again, but it should only display the fields when the links are clicked (to edit them). And when I try to click on a link, it does go to the right URL, but the fields are empty (am I using the right code: <input type="TEXT" name="betaald" value="<?php echo $myrow["Betaald"]?>" size=30> to display the contents of the row?).