/    Sign up×
Community /Pin to ProfileBookmark

Error from .php FORM’s

This may be rookieish, but I am a php rookie, waiting to get some books, but I have an error I would like to pose to all.

I have a test .php form (test_form.php) that calls test_sql_isrt.php and I get an error as shown below. However, if I execute this script by embedding test_sql_isrt into the file, rather than executing with the FORM submit button, a record gets added.

Also, I try executing a button to just do a select form and I get a different message, which leads me to believe it has something to do with the form.

//////

Error:

Warning: mysql_result(): supplied argument is not a valid MySQL result resource in /home/ebllorg/public_html/newsite/test_sql_isrt.php on line 4
fname joevalue 1… bad query.

//////////////
File: test_form.php
.
.
<form action=”test_sql_isrt.php” method=”POST”>
Enter your name: <input type=”text” name=”fname” />
Enter your id: <input type=”text” name=”age” />
Enter your age: <input type=”text” name=”age” />
<input type=”submit” value=”Add”/>
</form>
.
.

file: test_sql_isrt.php

<?
$query1 = “SELECT MAX(playerid) FROM Registration”;
$result1 = mysql_query($query1);
$value = mysql_result($result1, 0);
$value = $value+1;

$fname = $_POST[“fname”];
echo “fname “;
echo $fname;
echo “value “;
echo $value;
echo “… “;

$sql = “INSERT INTO `Registration` ( `playerid` , `fname` , `lname` , `address` , `dob` , `city` , `state` , `zip` )
VALUES ($value, ‘Geogre’, ‘Costanza’, ‘12345 grapple drive’, ‘1999-05-04’, ‘Anytown’, ‘ia’, ‘12345’)”;

if (! $result = mysql_query($sql))
{
die(“bad query.”);
}

?>

///////////////////

Thanks in advance.

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@grailquester5Apr 26.2005 — The first thing I notice is "mysql_result()".

I've never seen that function. I think what you're looking for reads more like this:

[code=php]
$query1 = "SELECT MAX(playerid) FROM Registration";
$result1 = mysql_query($query1);
$value = mysql_fetch_array($result1, MYSQL_NUM);
$value = $value[0];
$value = $value+1;
[/code]


Also on your second query, when referring to a MySQL table you don't use any 's or "s. So it would just be
[CODE]
INSERT INTO Registration VALUES (....
[/CODE]
Copy linkTweet thisAlerts:
@dpkyteauthorApr 27.2005 — I changed my .php to use this and get the below message:


Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/ebllorg/public_html/newsite/test_sql_isrt.php on line 4

fname asdfasd, value 1...

bad query.

///////////////

Also,

If I change my form to execute a select statement, I get the below:

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ebllorg/public_html/newsite/test_sql_select.php on line 5

Warning: Invalid argument supplied for foreach() in /home/ebllorg/public_html/newsite/test_sql_select.php on line 8


Warning: mysql_data_seek(): supplied argument is not a valid MySQL result resource in /home/ebllorg/public_html/newsite/test_sql_select.php on line 13

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ebllorg/public_html/newsite/test_sql_select.php on line 14

///////////

So, it seems to me something is not being set-up properly. I can change test_form.php (see below) and execute the logic and it does insert the record, should my form somehow be set up to execute the .php differently?




<?php

include("test_sql_isrt.php"); // this actually inserts a row... w

?>

Insert

<form action="test_sql_isrt.php" method="POST">

Enter your name: <input type="text" name="fname" />

Enter your id: <input type="text" name="age" />

Enter your age: <input type="text" name="age" />

<input type="submit" value="Add"/>

</form>

.

.

.


thanks.
Copy linkTweet thisAlerts:
@grailquester5Apr 27.2005 — Well, the "is not a valid MYSQL result resource" error usually tells you that the query wasn't executed properly. Do you have access to a terminal to login to MySQL with (or something like PHPMyAdmin)? If so, try executing the exact query from the command line. If the query returns the result you expect, we'll go on from there, but I'm betting it will return an error for some reason. Double-check the column name and table name, and if you can send along your database structure schema.
Copy linkTweet thisAlerts:
@NogDogApr 27.2005 — After your mysql_query() statement, do something like this to see if you can get MySQL to give you more info on what's wrong:
[code=php]
if(! $result)
{
echo mysql_errno($link) . ": " . mysql_error($link). "n";
}
# replace $link with whatever variable you use to store the result from
# your mysql_connect() call.
[/code]
Copy linkTweet thisAlerts:
@dpkyteauthorApr 27.2005 — Well, after you mentioned the Connect, I removed the include from the form and added the logic that was in the connect into my test_sql_isrt.php file. That seemed to work.

Thanks to all for your help. And, thanks again Nogdog !!!
×

Success!

Help @dpkyte spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...