topshelfbleu
-
Posts
21 -
Joined
-
Last visited
Never
Posts posted by topshelfbleu
-
-
Hi
I have a table that looks like
userid qnum1 qnum2 qnum 3
1 a b c
2 d a f
I want to create a new table using this data but organised in a different format i.e.
Answers
"userid","columnamefrom table1", "answer"
So this would look like
Answers
1;1;a
1;2;b
1;3;c
2;1;d
2;2;a
2;3;f
Is concatenate the way to go here?
-
Hi
I've got a qry that selects 100 questions one at a time from tblquestions.
When the users have answered q100 I want them to be able to come out of the post-process-post loop that has taken them through the survey.
My idea is that I could put an IF requirement in before the qry runs each time it selects the next question
i.e.
if $nextq <101 $result = mysql_query("SELECT oid,psc9 FROM tblquestions WHERE oid = $nextq"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; }; else echo "thanks you've finished now";
Two Questions:
- Is this the way I should be going about this problem?
- Have I got the syntax right?
Many thanks!
Nick
- Is this the way I should be going about this problem?
-
Hi-
Thanks that appears to have worked - but could you spend a second explaining why? I'm not sure what that middle comma is doing?
Really grateful thank you.
Nick
-
Hi
I am attempting to request a single row from a table that has 20 fields.
I want to turn each field into it's own variable (you'll see oc1, oc2 etc in the code) and then echo the variable just to check it has worked.
When I run the qry below - it picks up the first one correctly but then places the same value in all the other fields. (The $question var should be a long text string but is echoing the first variable instead.
There's clearly something wrong with the way I have constructed this - but I don't know at which point it has gone wrong.
Can anyone help?
$result = mysql_query("SELECT oid,qid,question,posneg,oc1,oc2,oc3,oc4,oc5,oc6,oc7,psc1,psc2,psc3,psc4,psc5,psc6,psc7,psc8,psc9 FROM tblquestions WHERE oid = '1'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $oid=mysql_result($result,"oid"); $qid=mysql_result($result,"qid"); $question=mysql_result($result,"question"); $posneg=mysql_result($result,"posneg"); $oc1=mysql_result($result,"oc1"); $oc2=mysql_result($result,"oc2"); $oc3=mysql_result($result,"oc3"); $oc4=mysql_result($result,"oc4"); $oc5=mysql_result($result,"oc5"); $oc6=mysql_result($result,"oc6"); $oc7=mysql_result($result,"oc7"); $psc1=mysql_result($result,"psc1"); $psc2=mysql_result($result,"psc2"); $psc3=mysql_result($result,"psc3"); $psc4=mysql_result($result,"psc4"); $psc5=mysql_result($result,"psc5"); $psc6=mysql_result($result,"psc6"); $psc7=mysql_result($result,"psc7"); $psc8=mysql_result($result,"psc8"); $psc9=mysql_result($result,"psc9"); ?> <?php echo $oid; // Question Number?> <?php echo $qid; // Question Number?> <?php echo $question; // Question Number?> <?php echo $posneg; // Question Number?> <?php echo $oc1; // Question Number?> <?php echo $oc2; // Question Number?> <?php echo $oc3; // Question Number?> <?php echo $oc4; // Question Number?> <?php echo $oc5; // Question Number?> <?php echo $oc6; // Question Number?> <?php echo $oc7; // Question Number?> <?php echo $psc1; // Question Number?> <?php echo $psc2; // Question Number?> <?php echo $psc3; // Question Number?> <?php echo $psc4; // Question Number?> <?php echo $psc5; // Question Number?> <?php echo $psc6; // Question Number?> <?php echo $psc7; // Question Number?> <?php echo $psc8; // Question Number?> <?php echo $psc9; // Question Number?>
-
Hi -
I know this is a #101 question but here goes!
I simply want to select a single row from a table and use the columns fields as variables that can then be posted in a form.
$result = mysql_query("SELECT * from tblquestions WHERE qid='1'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); $oid=$result['oid']; $qid=$result['qid']; $question=$result['question'];
The code above isn't working - as when I try to echo each variable
<?php echo $question;?>
nothing is being shown on screen.
I'm obviously barking up the wrong tree in the way I'm trying to create the variable - but don't really have any idea where to look next.
-
No- I just didnt for one second I guess it right!
Thx
-
I want to do this
$var1=$var2*$Var3*$Var4
in a spreadsheet it would be something like =sum((var2*var3)*var4))
what is the correct way to write this?!
Ta
-
I am retrieving a single row from a table and I want to use one of the fields in a post form which will be sent to process.php
I have successfully use echo to place some results where I want them – but I want to use some of the row results as hidden fields.
The code I am using to retrieve from the table is
$result = mysql_query("SELECT qid,question,oc1 FROM tblquestions WHERE qid = '1'");
The oc1 field is the one I want to post by way of a hidden field so that it can be passed to the process.php.
I have tried
[/echo $row[2]; // oc1 $oc1 = $row[2];php] And then in the form: [code=php:0]<input type="hidden" name="oc1" id="oc1" value= <?php echo $oc1?> />
I think I just read that this can't actually be done- but I'm new to all this, so am not sure whether I've understood how I should be doing it instead.
Any help REALLY gratefully received!
-
Have I done this incorrectly? Am trying to use a variable and then post it in a hidden field.
Could this be why it has gone screwy?
<input type="hidden" name="oc1" id= <?php "echo $row[2];" ?> [code=php:0]
-
I'd echod the initial values in the posting form tho. So I do know they are correct.
-
I have a form that is posting a value from a radio button as well as 16 Hidden values.
The form action goes to file2- which is successfully conecting and processing but instead of inserting the correct values I'm just seeing a row of zeros.
I don't know where to start looking!
This is the code from the posting form :
---
<?php // query.php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $result = mysql_query("SELECT qid,question,oc1,oc2,oc3,oc4,oc5,oc6,oc7,psc1,psc2,psc3,psc4,psc5,psc6,psc7,psc8,psc9 FROM tblquestions WHERE qid = '1'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); echo $row[0]; // Question Number echo $row[1]; // Question echo $row[2]; // oc1 echo $row[3]; // oc2 echo $row[4]; // oc3 echo $row[5]; // oc4 echo $row[6]; // oc5 echo $row[7]; // oc6 echo $row[8]; // oc7 echo $row[9]; // pcs1 echo $row[10]; // pcs2 echo $row[11]; // pcs3 echo $row[12]; // pcs4 echo $row[13]; // pcs5 echo $row[14]; // pcs6 echo $row[15]; // pcs7 echo $row[16]; // pcs8 echo $row[17]; // pcs9 ?> <p>Hello </p> <?php echo $row[0]; // Question Number ?> <form id="form1" name="form1" method="post" action="./uinputprocess.php"> <table width="800" border="0"> <tr> <td colspan="6"><p>Question <?php echo $row[0]; // Question Number ?> </p> <?php echo $row[1]; // Question ?> .</td> </tr> <tr> <td width="126"><p align="center"> </p> <p align="center">Strongly Disagree </p></td> <td width="65"><p align="center"> </p> <p align="center">Disagree </p></td> <td width="145"><p align="center"> </p> <p align="center">Unsure but Doubtful </p></td> <td width="152"><p align="center"> </p> <p align="center">Unsure but Probable </p></td> <td width="67"><p align="center"> </p> <p align="center">Agree </p></td> <td width="219"><p align="center"> </p> <p align="center">Strongly Agree </p></td> </tr> <tr> <td><div align="center"> <input type= "radio" name= "ans" value = "1" /> </div></td> <td><div align="center"> <input type= "radio" name= "ans" value = "2" /> </div></td> <td><div align="center"> <input type= "radio" name= "ans" value = "3" /> </div></td> <td><div align="center"> <input type= "radio" name= "ans" value = "4" /> </div></td> <td><div align="center"> <input type= "radio" name= "ans" value = "5" /> </div></td> <td><div align="center"> <input type= "radio" name= "ans" value = "6" /> </div></td> </tr> <tr> <td colspan="6"> </td> </tr> <tr> <td colspan="6"><p>Hidden Fields Here > <input type="hidden" name="oc1" id= <?php "echo $row[2];" ?> /> <input type="hidden" name="oc2" id= <?php "echo $row[3];" ?> /> <input type="hidden" name="oc3" id= <?php "echo $row[4];" ?> /> <input type="hidden" name="oc4" id= <?php "echo $row[5];" ?> /> <input type="hidden" name="oc5" id= <?php "echo $row[6];" ?> /> <input type="hidden" name="oc6" id= <?php "echo $row[7];" ?> /> <input type="hidden" name="oc7" id= <?php "echo $row[8];" ?> /> <input type="hidden" name="psc1" id= <?php "echo $row[9];" ?> /> <input type="hidden" name="psc2" id= <?php "echo $row[10];" ?> /> <input type="hidden" name="psc3" id= <?php "echo $row[11];" ?> /> <input type="hidden" name="psc4" id= <?php "echo $row[12];" ?> /> <input type="hidden" name="psc5" id= <?php "echo $row[13];" ?> /> <input type="hidden" name="psc6" id= <?php "echo $row[14];" ?> /> <input type="hidden" name="psc7" id= <?php "echo $row[15];" ?> /> <input type="hidden" name="psc8" id= <?php "echo $row[16];" ?> /> <input type="hidden" name="psc9" id= <?php "echo $row[17];" ?> /> </p> <p>Pin <label for="textfield"></label> <input name="textfield" type="password" id="textfield" size="20" maxlength="5" /> </p></td> </tr> <tr> <td colspan="6"><p> <input type="submit" name="button" id="button" value="Submit" /> </p> <p> </p></td> </tr> </table> </form>
And this is the code from the processing file
<?php // query.php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $pin =$_POST['pin']; $qid =$_POST['qid']; $oc1 =$_POST['oc1']; $oc2 =$_POST['oc2']; $oc3 =$_POST['oc3']; $oc4 =$_POST['oc4']; $oc5 =$_POST['oc5']; $oc6 =$_POST['oc6']; $oc7 =$_POST['oc7']; $psc1 =$_POST['psc1']; $psc2 =$_POST['psc2']; $psc3 =$_POST['psc3']; $psc4 =$_POST['psc4']; $psc4 =$_POST['psc5']; $psc6 =$_POST['psc6']; $psc7 =$_POST['psc7']; $psc8 =$_POST['psc8']; $psc9 =$_POST['psc9']; $ans =$_POST['ans']; $enter_sql= "INSERT INTO tblresults (pin,qid,oc1,oc2,oc3,oc4,oc5,oc6,oc7,psc1,psc2,psc3,psc4,psc5,psc6,psc7,psc8,psc9) VALUES ('$pin','$qid','$oc1','$oc2','$oc3','$oc4','$oc5','$oc6','$oc7','$psc1','$psc2','$psc3','$psc4','$psc5','$psc6','$psc7','$psc8','$psc9')"; $enter_query =mysql_query($enter_sql) or die (mysql_error()); ?> <body> <p>Thank you - You have successfully entered your answer</p>
-
Having trouble with this-
Basically have created an excel csv and converted into notepad.
Clicking Import in phpmyadmin - choosing CSV with Load Data and changed the ; to a comma.
Clicking go I'm getting the following error :
SQL query:
LOAD DATA INFILE '/tmp/phpXqCUTK' INTO TABLE `tblquestions` FIELDS TERMINATED BY ';' ENCLOSED BY '"' ESCAPED BY '\\' LINES TERMINATED BY '\r\n'
MySQL said: Documentation
#1045 - Access denied for user 'myusername'@'%' (using password: YES)
-
This doesn't make any sense to me as phpmyadmin is doing everything else okay (with user password settings).
Am I being totally stupid here?
-
That is what I meant, and having tried it - it works.
Very grateful.
Nick
-
Hi
I've got a form that users enter an identification pin in for their first question as well as clicking a radio button(Q1.php) . They click submit and the answers are put through a couple of multiplication function and then placed in a table (alongside the pin) via Q2.php.
On the Q2 page I want to place the 2nd question that the user needs to answer.
Rather than making them retype the pin I was hoping to process it as a hidden field - being picked up from their Q1.php entry.
This 'hidden pin echo ' process will continue throughout Q2- Q10 pages.
However - I can't seem to include any php in the page after the Q1 form has been processed. Have I got my php tags messed up?
<?php $con = mysql_connect("localhost","ca","d"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("candango", $con); $q1 =$_POST['q1']; $pin =$_POST['pin']; $ans1 = $q1 * 3; $ans2 = $q1 * 5; $ans3 = $q1 * 2; $enter_sql= "INSERT INTO aapcm2 (pin,ans1, ans2, ans3) VALUES ('$pin','$ans1','$ans2','$ans3')"; $enter_query =mysql_query($enter_sql) or die (mysql_error()); ?> <body> <p>Thank you - You have successfully entered your answers.</p><form action="q2.php" method="post"> <p>What do you think the answer to this one is? <input type="radio" name="q2" id="q2" value="-3"> <label for="q2"></label> <input name="Hidden" type="hidden" id="Hidden" value="$pin" /></p> <p> <input type="submit" name="button" id="button" value="Submit"> </p> </form> <p></p> </body>
-
Hi
The page I'm working on will receive a value from a radio button ( '$q1' and then I need to apply 3 seperate multiplications to it. The 3 values will then be placed into a table.
How do I turn the values into named variables which then can get placed into the dbase using the insert into dbasename and values
So far I've done this
<?php
$con = mysql_connect("blah","blah","blah");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("candango", $con);
$q1 =$_POST['q1'];
$multiplication = '$q1'*3;
$multiplication = '$q1'*5;
$multiplication = '$q1'*10;
$enter_sql= "INSERT INTO answers (answer from 1, answer from 2, answer 3)
$enter_query =mysql_query($enter_sql) or die (mysql_error());
?>
[/code]
Any guidance - greatly accepted!
Thanks
Nick
-
My query is a fixtures list for my local sports team- There seems little point including fixtures from the past as they are in a results query anyway.
I'm ordering by date (see below) but how can I remove the ones already past?
$query = "SELECT * FROM fix10 ORDER BY Date";
TIA Nick
-
I want to pull some records plus unique key from one mysql table and then use them as questions in a form/questionnaire.
The post form will have six radio buttons to the right of the fields pulled with the key posted but hidden and will wirte to another table.
I guess this is a templating question- as I've successfully retrieved the table 1 records via a query - I just can't seem to use them in the form. Below is the code I'm using to view table "PCM1"
<?php // query.php require_once 'login.php'; $db_server = mysql_connect($db_hostname, $db_username, $db_password); if (!$db_server) die("Unable to connect to MySQL: " . mysql_error()); mysql_select_db($db_database) or die("Unable to select database: " . mysql_error()); $query = "SELECT * FROM pcm1"; $result = mysql_query($query); if (!$result) die ("Database access failed: " . mysql_error()); $rows = mysql_num_rows($result); for ($j = 0 ; $j < $rows ; ++$j) { echo 'RID: ' . mysql_result($result,$j,'mcde') ; echo 'Statement: ' . mysql_result($result,$j,'oppclub') . '<br />'; ; }
-
Yep - I do see the difference.... and thanks for pointing out that particular issue.
However...
I'm embarrassed to say I don't know what PFMaBiSmAd's s quote
"debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your master php.ini so that php will help you" actually means.
-
thanks all- but still nothing appearing.
(I have corrected the straight bracket). I've been typing into dw rather than use a debugging tool. Am just having a look now at netbeans
the post form is http://www.candango.co.uk/php/insert_records.php
code for entry_page.php is
<?php $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("aaworldcup", $con); $Name =$_POST['Name']; $email =$_POST['email']; $m1hscore =$_POST['m1hscore']; $m1ascore =$_POST['m1ascore']; $enter_sql= "INSERT INTO aaworldcup (Name,email,m1hscore,m1ascore) VALUES ('$Name','$email','$m1hscore','$m1ascore')"; $enter_query =mysql_query($enter)sql) or die (mysql_error()); ?> <body> hello</body>
-
I've been looking at this for over an hour- I've even opened a book.
I'm totally new to it and trying to write a form which allow friends to post predictions for each world cup match.
Is there anything that stands out to you here. Once clicking submit - the retrieving page isn't showing anything and obv not submitting to the dbase.
<?php $con = mysql_connect("localhost","user","pass"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("aaworldcup", $con); $Name =$_POST['Name']; $email =$_POST['email'}; $m1hscore =$_POST['m1hscore']; $m1ascore =$_POST['m1ascore']; $enter_sql= "INSERT INTO aaworldcup (Name,email,m1hscore,m1ascore) VALUES ('$Name','$email','$m1hscore','$m1ascore')"; $enter_query =mysql_query($enter)sql) or die (mysql_error()); ?>
copying a table with a new column
in MySQL Help
Posted
Hi
I have an answers table of 15 rows each with 100 fields (100) that I need to multiply by a factor of either +1 or -1 and then save the new version to a new table
What is the best way to go about this?
Any help really gratefully accepted.