Jump to content

Parse error: parse error, expecting `'&'' or `T_VARIABLE'


justineaguas

Recommended Posts

Hello all,

 

I get an error called: Parse error: parse error, expecting `'&'' or `T_VARIABLE'

 

I just studied PHP 5 hours ago. Now I have connected to database with mySQL and all. I am trying to enter a value into the table named 'table1'. I want to insert a text into the database. The text will come from a textarea named "fname". I created a function and this is the codes.

 

Here is the function:

 

function insertValues(`regName`) //error in this line

{

mysql_query("INSERT INTO `table1` (id, fname)

VALUES ('1', `".regName."`)");

}

 

Here is the code of the form:

 

<form action="" method="post" onclick="<?php insertValues(this); ?>>

<td>

<input name="regName" type="text" />

</td>

<td>

<input name="submit" type="submit" value="Register!" />

</td>

</form>

 

 

I'm just a newb. Thanks to those who will help.

Link to comment
Share on other sites

1. Please insert your code in


tags for better readability.

2.

function insertValues($regName) //error in this line
{
mysql_query("INSERT INTO `table1` (id, fname)
VALUES ('1', '$regName')");
}

 

3. I expect you'll have also problems here. What 'this' is supposed to be?

<?php insertValues(this); ?>

 

 

Link to comment
Share on other sites

PHP is parsed serverside (before the content is outputted to the browser) and can't be triggered by client side events like javascript. For this you would need to look into AJAX; although that would probably be far too advanced for you at the moment.

 

I think what your trying to do is this:

 

<?php
// Connect to mysql or include file where connection is established...

function insertValues($regName)
{
mysql_query("INSERT INTO `table1` (id, fname)
VALUES (1, '" . $regName . "')");
}

if ( isset($_POST['submit']) )
   insertValues( mysql_real_escape_string($_POST['regName']) );

?>
<form action="" method="post">
<td>
<input name="regName" type="text" />
</td>
<td>
<input name="submit" type="submit" value="Register!" />
</td>
</form>

Link to comment
Share on other sites

Thanks to the both of you. There is no error now! :) However, the value is still not being inserted into the database.

 

@Mchl

I tried to replaced 'this' with 'regName'.

 

@Andy-H

I tried your code. There were no error but still the values were not inserted.

 

Thanks really. Sorry I'm just new to PHP.

 

 

Link to comment
Share on other sites

@Mchl

I tried to replaced 'this' with 'regName'.

 

That will still not work for the reasons outlined by Andy-H.

 

@Andy-H

I tried your code. There were no error but still the values were not inserted.

 

Did you connect to the database first? In any case, add some debugging to your query:

 

mysql_query("INSERT INTO `table1` (id, fname) VALUES (1, '" . $regName . "')") or trigger_error(mysql_error(),E_USER_ERROR);

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.