Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old December 22nd, 2005, 04:55 PM
steve02a@gmail.com
Guest
 
Posts: n/a
Default Scripting error

I have a simple html form built that a user puts name, company,
address..blah..blah, you know - and it dumps it all in a db I created
in MySQL.

Below is my php script:

<?php

if (strlen($name) > 2) {

$dbh=mysql_connect ("localhost", "reseller", "PASSWORD HERE") or die
('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("autonomi_reseller ");

$date = time();

$insertq = "INSERT INTO apply SET first_name = '$first_name', last_name
= '$last_name', email = '$email', company = '$company', address1 =
'$address1', address2 = '$address2', city = '$city', state_province =
'$state_province', zip_or_postalcode = '$zip_or_postalcode', phone =
'$phone'";
mysql_query($insertq) or die (mysql_error());

echo '<html><head><title>Redirect</title><script language="javascript">
<!--

location.redirect("http://url.com here");

-->
</script>
';
}

?>
--------------------------------------------------------------------

Whne I execute the script after I filled in all the info on the webpage
form, I get this error:

Parse error: parse error, unexpected $ in
/home/autonomi/public_html/php/app.php on line 23

What am I missing in my php script? It's driving me nuts trying to
figure it out. Thanks in advance.

  #2  
Old December 22nd, 2005, 07:15 PM
kevincw01
Guest
 
Posts: n/a
Default Re: Scripting error

what's with the '; after </script>?

  #3  
Old December 22nd, 2005, 07:25 PM
NC
Guest
 
Posts: n/a
Default Re: Scripting error


steve02a@gmail.com wrote:[color=blue]
> I have a simple html form built that a user puts name, company,
> address..blah..blah, you know - and it dumps it all in a db I created
> in MySQL.
>
> Below is my php script:
>
> <?php
>
> if (strlen($name) > 2) {
>
> $dbh=mysql_connect ("localhost", "reseller", "PASSWORD HERE") or die
> ('I cannot connect to the database because: ' . mysql_error());
> mysql_select_db ("autonomi_reseller ");
>
> $date = time();
>
> $insertq = "INSERT INTO apply SET first_name = '$first_name', last_name
> = '$last_name', email = '$email', company = '$company', address1 =
> '$address1', address2 = '$address2', city = '$city', state_province =
> '$state_province', zip_or_postalcode = '$zip_or_postalcode', phone =
> '$phone'";
> mysql_query($insertq) or die (mysql_error());
>
> echo '<html><head><title>Redirect</title><script language="javascript">
> <!--
>
> location.redirect("http://url.com here");
>
> -->
> </script>
> ';
> }
>
> ?>
> --------------------------------------------------------------------
>
> Whne I execute the script after I filled in all the info on the webpage
> form, I get this error:
>
> Parse error: parse error, unexpected $ in
> /home/autonomi/public_html/php/app.php on line 23[/color]

It would be nice if you marked which line is line 23 in your script...

Cheers,
NC

  #4  
Old December 22nd, 2005, 07:55 PM
Michel
Guest
 
Posts: n/a
Default Re: Scripting error


"kevincw01" <kevincw01@gmail.com> wrote in message
news:1135278401.853970.231870@g44g2000cwa.googlegr oups.com...[color=blue]
> what's with the '; after </script>?
>[/color]

it closes the string to be echoed



  #5  
Old December 22nd, 2005, 08:45 PM
kevincw01
Guest
 
Posts: n/a
Default Re: Scripting error

ahh yes, thx. well i echo NC's request. Which is line 23?

  #6  
Old December 23rd, 2005, 12:05 PM
David Haynes
Guest
 
Posts: n/a
Default Re: Scripting error

steve02a@gmail.com wrote:[color=blue]
> I have a simple html form built that a user puts name, company,
> address..blah..blah, you know - and it dumps it all in a db I created
> in MySQL.
>
> Below is my php script:
>
> <?php
>
> if (strlen($name) > 2) {
>
> $dbh=mysql_connect ("localhost", "reseller", "PASSWORD HERE") or die
> ('I cannot connect to the database because: ' . mysql_error());
> mysql_select_db ("autonomi_reseller ");
>
> $date = time();
>
> $insertq = "INSERT INTO apply SET first_name = '$first_name', last_name
> = '$last_name', email = '$email', company = '$company', address1 =
> '$address1', address2 = '$address2', city = '$city', state_province =
> '$state_province', zip_or_postalcode = '$zip_or_postalcode', phone =
> '$phone'";
> mysql_query($insertq) or die (mysql_error());
>
> echo '<html><head><title>Redirect</title><script language="javascript">
> <!--
>
> location.redirect("http://url.com here");
>
> -->
> </script>
> ';
> }
>
> ?>
> --------------------------------------------------------------------
>
> Whne I execute the script after I filled in all the info on the webpage
> form, I get this error:
>
> Parse error: parse error, unexpected $ in
> /home/autonomi/public_html/php/app.php on line 23
>
> What am I missing in my php script? It's driving me nuts trying to
> figure it out. Thanks in advance.
>[/color]

I ran the code you posted through a couple of PHP IDEs I have and the
code is syntactically correct. I am wondering why you are doing all that
messy stuff with javascript just to get the redirect when there is a PHP
function for it. See my reworked example below:

<pre>
<?php
if (strlen($name) > 2) {
$dbh = mysql_connect("localhost", "reseller", "PASSWORD HERE")
or die('I cannot connect to the database because: '
.mysql_error());

mysql_select_db("autonomi_reseller", $dbh);

$date = time(); // not sure why this is done

$insertq = "insert into apply( "
."first_name, "
."last_name, "
."email, "
."company, "
."address1, "
."address2, "
."city, "
."state_province, "
."zip_or_postalcode, "
."phone "
.") values ( "
."'$first_name', "
."'$last_name', "
."'$email' "
."'$company', "
."'$address1', "
."'$address2', "
."'$city', "
."'$state_province', "
."'$zip_or_postalcode', "
."'$phone' "
.") ";

mysql_query($insertq, $dbh)
or die(mysql_error());

header('http://url.com here');
}
?>
</pre>

I find setting out the insert the way I have makes it much easier to see
what is meant by the insert. You could do the same with the 'set column
= $column' form if you prefer it.

Even though the specification of the database connection is optional, I
like to put it in anyway because I am very paranoid when I code.

Hope this helps.
-david-

 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles