473,394 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Php MySQL_query and echo conflict

SHOverine
Hello All. I have a problem with a form that I am trying to create. What happens is: I have a person enter a UserName and select some values using radio buttons. They submit the form, and the next page is intended to echo their information back. I was able to get the first page to write values to the database, but when I add the second page, the values do not write to the database and I get an error.

Here is a pared-down version of the code, with comments:

<!-- FIRST PAGE -->
<html>
<head>
<?php
include("db.php"); //CONNECTS TO DATABASE
?>
</head>
<body>
<form name="form1" method="post" action="myinformation.php">

<p>Name: <input name="UserName" type = "text"></p>

<?php
$_SESSION['$UserName'] = $UserName;
?>

<p><input name="v1" value="Value1" type="hidden">
<input name="Input1" onclick="g1.value = v1.value" type="radio">Value1</p>

<!-- IF SELECTED, THIS PUTS THE VALUE ASSOCIATED WITH THE RADIO BUTTON "V1" INTO THE TEXT BOX "G1", WHICH I WANT TO PUT IN THE MYSQL DATABASE -->

</form>

<?php dbConnect('my_database');

if (isset($_POST['submitok'])) {
$Submit_sql = "INSERT INTO Info (UserName, G1)
VALUES ('$UserName', '$g1')

mysql_query($Submit_sql) or die(mysql_error());
} ?>
</body>
</html>

<!-- IF I HAVE NOTHING IN THE NEXT PAGE, myinformation.php, THE VALUES WILL WRITE TO THE DATABASE. HOWEVER, I WANT TO ECHO BACK THE VALUES FOR THE USER SO THEY CAN PRINT THEM. -->

<!--SECOND PAGE -->

<html>
<head>
<?php
include("db.php"); //CONNECTS TO DATABASE
?>
</head>
<body>
<h1><?php echo $UserName;
$_SESSION['$UserName'] = $UserName;?>'s Information</h1>

<p>
<?php
dbConnect('my_database');
$sql_g1 = "SELECT G1 FROM Info WHERE UserName = '$UserName'";
$result_g1 = mysql_query($sql_g1);
$g1 = mysql_result($result_g1, 0);
echo $g1;
?>
</p>
</body>
</html>

<!-- THE INFORMATION DOES NOT WRITE TO THE DATABASE WHEN I HAVE THIS IN MY SECOND PAGE AND I GET THE ERROR "Warning: mysql_result(): Unable to jump to row 0 on MySQL result index 5 in /home/theweekl/public_html/NCAA2007/myinformation.php on line xxx", BECAUSE THE DATA IS NOT THERE -->

Any help is greatly appreciated!

Cheers,
Seth
Mar 9 '07 #1
5 2631
ronverdonk
4,258 Expert 4TB
We can only help you when you adhere to the Posting Guidelines, shown at the top of this forum! Especially the part about enclosing code within code or php tags! The code posted is absolutely unreadable in this format.

You have posted code before so you know that.

moderator
Mar 9 '07 #2
Sorry about the ill-formatted post.

Hello All. I have a problem with a form that I am trying to create. What happens is: I have a person enter a UserName and select some values using radio buttons. They submit the form, and the next page is intended to echo their information back. I was able to get the first page to write values to the database, but when I add the second page, the values do not write to the database and I get an mysql_result() error.

Here is the code:

First page:
[php]form name="form1" method="post" action="myinformation.php">

<p>Name: <input name="UserName" type = "text"></p>

$_SESSION['$UserName'] = $UserName;

<p><input name="v1" value="Value1" type="hidden">
<input name="Input1" onclick="g1.value = v1.value" type="radio">Value1</p>

</form>

dbConnect('my_database');

if (isset($_POST['submitok'])) {
$Submit_sql = "INSERT INTO Info (UserName, G1)
VALUES ('$UserName', '$g1')

mysql_query($Submit_sql) or die(mysql_error());
}[/php]
Second page (myinformation.php):
[php]
<h1> echo $UserName;
$_SESSION['$UserName'] = $UserName;'s Information</h1>

<p>
dbConnect('my_database');
$sql_g1 = "SELECT G1 FROM Info WHERE UserName = '$UserName'";
$result_g1 = mysql_query($sql_g1);
$g1 = mysql_result($result_g1, 0);
echo $g1;

</p>
[/php]
Mar 11 '07 #3
ronverdonk
4,258 Expert 4TB
When you pass (POST) your data using submit to the second page, you must extract the POSTed values from the $_POST array. I cannot see any extraction in the second page.

Also the following statement is unclear to me:
Expand|Select|Wrap|Line Numbers
  1. <input name="Input1" onclick="g1.value = v1.value" type="radio">Value1</p>
What is the 'onclick' doing there? And what are the g1 and v1 values? Did you assign a Javascript DOM variable to these?

Ronald :cool:
Mar 11 '07 #4
Ronald,

As always, thanks for the response. I was making things more complicated than they need be. For one, I needed to have my submit statement on the second page and only echo back the variable - instead of submitting, and then recalling the values to the "my information page". The code is as simple as

[PHP]
dbConnect('my_database');
echo $g1;
[/PHP]

As for the onclick stuff - g1 is the text box where the selected value goes (either v1 or v2, which are the values of the radio button "Input1"). If you want to know more, pm or email me.

Problem has been solved. Thanks again.

Cheers,
Seth

When you pass (POST) your data using submit to the second page, you must extract the POSTed values from the $_POST array. I cannot see any extraction in the second page.

Also the following statement is unclear to me:
Expand|Select|Wrap|Line Numbers
  1. <input name="Input1" onclick="g1.value = v1.value" type="radio">Value1</p>
What is the 'onclick' doing there? And what are the g1 and v1 values? Did you assign a Javascript DOM variable to these?

Ronald :cool:
Mar 12 '07 #5
ronverdonk
4,258 Expert 4TB
I am glad you solved your problem. See you next time.

Ronald :cool:
Mar 12 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Bruce A. Julseth | last post by:
I know the following $sql will fail since there is no Customer='Smith'. I want to determine how to test a failure of mysql_query. I thought mysql_query returned false if a query failed. The test...
0
by: Bill | last post by:
I have the following line in a php script $queryDeletePosition = mysql_query("DELETE FROM `Position` WHERE `stockID` = '$existStockID' AND `userID`='$userID' AND `groupID`='$groupID' LIMIT 1 ",...
7
by: John Moore | last post by:
Hi I posted three days ago about a function I wrote which kept refusing to run a mysql_query. Well I did away with the function, and hard coded the variables into the query itself. Here's...
5
by: Chameleon | last post by:
I have a SQL Script with about 5000 SQL Commands. How can I send it to SQL Server at once? I see mysql_query() fails on first semicolon (;) who delimits the SQL Commands. Another...
2
by: techjohnny | last post by:
Error: Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/jplane/certcent/phpweb/quiz/index.php on line 20 Warning: mysql_num_rows(): supplied argument is...
1
by: thad.irvin | last post by:
Hey all; I'm one of those newbies to the PHP realm of programming and I've run into a stumper. What I'm trying to do is pull data (any data at this point) from a mysql database. I've checked...
14
lotus18
by: lotus18 | last post by:
Hello World I have a problem in detecting the conflict schedule (Day and Time). Day 1. M 2. T 3. W 4. TH 5. F
14
lotus18
by: lotus18 | last post by:
Hello all I have these records on my Day Table for my complete database table please click here 1. M 2. T 3. W 4. TH 5. F 6. S
5
by: lisles | last post by:
i have a page funtion.php which hs the function to connect to the db /* Mysql Connection */ function connect(){ global $db_server,$db_user,$db_pass,$db;//Global Values from the config.php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.