Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP beginner Pls. Help?

Status
Not open for further replies.

joelxez

Programmer
Apr 18, 2002
67
PH
Dear Experts,

I'm having an error, what's wrong with my code.

Notice: Undefined variable: ID in C:\Inetpub\ on line 15

Notice: Undefined variable: Name in C:\Inetpub\ on line 15

Notice: Undefined variable: Address in C:\Inetpub\ on line 15
could not complete your query



Heres my add.php below
------------------------------------------------------------
<?php

$host = &quot;localhost&quot;;
$user = &quot;joel&quot;;
$pass = &quot;&quot;;
$database = &quot;personal&quot;;
$table = &quot;tblpersonal&quot;;

echo &quot;<B>This is a list of items I have in my table named $table</B> <hr>&quot;;

// Connecting to the Database
$connection = @mysql_connect($host, $user, $pass) or die(&quot;could not connect to server&quot;);

@mysql_select_db($database, $connection);

$query = &quot;INSERT INTO $table('ID','Name','Address')VALUES('$ID','$Name','$Address')&quot;;

// Query the Database
$result = @mysql_query($query) or die(&quot;could not complete your query&quot;);

?>

------------------------------------------------------------
and here's my add.htm



<html>

<head>

<title>Add</title>
</head>

<body>

<form method=&quot;POST&quot; action =&quot;add.php&quot;>
<input type=&quot;text&quot; name=&quot;ID&quot; size=&quot;20&quot;></p>
<p><input type=&quot;text&quot; name=&quot;Name&quot; size=&quot;20&quot;></p>
<p><input type=&quot;text&quot; name=&quot;Address&quot; size=&quot;20&quot;></p>
<p><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></p>
</form>

</body>

</html>

------------------------------------------------------------
 
Hi Joelexz!

I'm not an expert, but flattery gets you a long way.

I can't see exactly what's going wrong in your code. However, a few suggestions:

a) Get rid of the '@' signs in front of everything. You are hiding perhaps useful information. There are better ways to hide error messages.

b) Do a print of the $query string to see what is ACTUALLY being passed to the query. In fact do a print of any and every line you suspect is causing the problem. I'd like to see a &quot;print $_POST&quot; to be sure things are arriving OK.

c) Tell us exactly what is 'line 15' since I can't work it out from your post.

My suspicion is the single quotes around the fields.

Hope something here helps.


Hugh Prior
Author of the world's best ;) and most local search engine.
 
At a guess this is line 15
$query = &quot;INSERT INTO $table('ID','Name','Address')VALUES('$ID','$Name','$Address')&quot;;

Which needs some spaces:
$query = &quot;INSERT INTO $table ('ID','Name','Address') VALUES('$ID','$Name','$Address')&quot;;

and possibly change $table to '$table' - this largely depends on your version of PHP if its greater than 4.1.0 you may need to use $_POST
instead. If this is the case you will also need to change ('$ID','$Name','$Address')&quot;; to ('$_POST[ID]','$_POST[Name]','$_POST[Address]')&quot;; ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Well, want my advise, go to php.ini, and in the error_reporting, just put there E_ALL & ~E_NOTICE
otherwise you will get a lot of notices ...

Anikin
Hugo Alexandre Dias
Web-Programmer
anikin_jedi@hotmail.com
 
Hi KarVer

I used this code

$query = &quot;INSERT INTO $_POST
('ID','Name','Address')VALUES('$_POST[ID]','$_POST[Name]','$_POST[Address]')&quot;;

I got an error again...

Notice: Undefined index: table in C:\Inetpub\ on line 15
could not complete your query

Joel
 
You define $table in your script, not via the query string. Change the $_POST
back to $table. //Daniel
 
well spotted dan. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
$_POST, lets give you a clue:

<form method=&quot;POST&quot; action =&quot;add.php&quot;>
<input type=&quot;text&quot; name=&quot;ID&quot; size=&quot;20&quot;></p>
<p><input type=&quot;text&quot; name=&quot;Name&quot; size=&quot;20&quot;></p>
<p><input type=&quot;text&quot; name=&quot;Address&quot; size=&quot;20&quot;></p>
<p><input type=&quot;submit&quot; value=&quot;Submit&quot; name=&quot;B1&quot;><input type=&quot;reset&quot; value=&quot;Reset&quot; name=&quot;B2&quot;></p>
</form>

if you submit that form to a php page (add.php) to get at the variables you have sent in the form you used $_POST['ID'] or $_POST['Name'] etc.

Local variables in PHP don't need to be called with a $_POST prefix because, simply, they aren't. --BB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top