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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Updating variables

Status
Not open for further replies.

sjaakdelul

IS-IT--Management
Sep 19, 2002
43
NL
I am using php4.2.2 and the newest version of mysql.

Database:

CREATE TABLE cijferlijst (
Kwartaal int(1) default NULL,
vak varchar(5) default NULL,
cijfer1 varchar(4) default NULL,
cijfer2 varchar(4) default '-',
cijfer3 varchar(4) default '-',
cijfer4 varchar(4) default '-',
Studiepunten char(2) default '-',
Oordeel varchar(100) default 'Nog niet afgesloten'
)


I've one form:

<form name=&quot;form&quot; method=&quot;post&quot; action=&quot;update2.php&quot;>
<table width=&quot;500&quot; border=&quot;0&quot; cellpadding=&quot;5&quot; cellspacing=&quot;0&quot;>
<?php
// MySQL data
$host = &quot;localhost&quot;;
$username = &quot;&quot;;
$password = &quot;&quot;;
$database = &quot;hrocijfers&quot;;

// Make connection to MySQL server
mysql_connect (&quot;$host&quot;,&quot;$username&quot;, &quot;$password&quot;);
mysql_select_db(&quot;$database&quot;);

// Execute query
$query = &quot;SELECT * FROM `cijferlijst`&quot;;
$results = mysql_query($query);

// Create dropdown box
?>
<tr><td>Vak afkortingen:</td>
<td><div align=&quot;left&quot;><? echo &quot;<select name=vak>&quot;;
// List vakken into the box
while ($results_array = mysql_fetch_array($results)) {
$name = $results_array['vak'];
echo &quot;<option value='&quot; . $name . &quot;'>&quot; . $name . &quot;</option>&quot;;
}
echo &quot;</select>&quot;;
?></div></td>
</tr>
<tr><td>Afkorting vak:</td>
<td><div align=&quot;left&quot;>
<input type=&quot;text&quot; name=&quot;vakkeuze&quot; value=&quot;<?=$_POST['vakkeuze']?>&quot;>
</div></td></tr>
<tr><td>Behaalde cijfer:</td>
<td><div align=&quot;left&quot;>
<input type=&quot;text&quot; name=&quot;cijferinvoer&quot; value=&quot;<?=$_POST['cijferinvoer']?>&quot;>
</div></td></tr>
<tr><td>Hoeveelste cijfer:</td>
<td><div align=&quot;left&quot;>
<input type=&quot;text&quot; name=&quot;cijfer&quot; value=&quot;<?=$_POST['cijfer']?>&quot;>
</div></td></tr>
</table>
<input type=&quot;hidden&quot; name=&quot;required&quot; value=&quot;cijferinvoer&quot;>
<input type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;>
</form>


Update2.php

<?php
if ( $_POST[vakkeuze]>A ) { $vakkeuze1=$_POST[vakkeuze];
echo &quot;$vakkeuze1<br>&quot;;
} else {
echo &quot;Fill in a good name!!!<br>&quot;;
}
// MySQL data
$host = &quot;localhost&quot;;
$username = &quot;upclan&quot;;
$password = &quot;jXZDSuXw&quot;;
$database = &quot;clanupclan&quot;;

// Make connection to MySQL server
mysql_connect (&quot;$host&quot;,&quot;$username&quot;, &quot;$password&quot;);
mysql_select_db(&quot;$database&quot;);

//Execute query
$query = &quot;SELECT * FROM `cijferlijst` WHERE vak='$vakkeuze1'&quot;;
$results = mysql_query($query);

// Checkout the entered vak
$num_rows = mysql_num_rows($results);
if ( $num_rows>0 ) {
echo &quot;password oke<br>&quot;;
}
else {
echo &quot;Voer de juiste vak afkorting in.<br>&quot;;
}

if ( $_POST[cijferinvoer]>0 ) { $cijferinvoer1=$_POST[cijferinvoer];
echo &quot;$cijferinvoer1<br>&quot;;
} else {
echo &quot;voer een cijfer in dat groter is dan nul<br>&quot;;
}

if ( $_POST[cijfer]>0 ) { $cijfer1=$_POST[cijfer];
echo &quot;$cijfer1<br>&quot;;
} else {
echo &quot;voer een cijfer in dat groter is dan nul<br>&quot;;
}

// Execute query
$query = 'UPDATE cijferlijst set $cijfer1=$cijferinvoer where vak=$vakkeuze1';
$results = mysql_query($query);
echo &quot;Ok&quot;;
?>



There are 5 steps.
1) Set $vakkeuze1
2) Set $cijferinvoer1
3) Set $cijfer1
4) Check vak
5) Update the table cijferlijst.

The steps 1,2 and 3 are going very well...but the steps 4 and 5 aren't good.


Step 4:
I've filled out the form:

Afkorting vak:Bekn1
Cijfer:8
Hoeveelste cijfer:1


The result from update2.php is:

Bekn1
Voer de juiste vak afkorting in.
8
1
Ok

So, the cause of the problem start at &quot;// Checkout the entered vak&quot; ...

But what's wrong?


Step5:
I think the code to update the table cijferlijst is good ... anyone who can see any wrong code?


Who can help me?
 
use ' instaed of ` .
(`) is know to cause the odd problem with php, then try it again and see how you get on. ______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
Hmmz...disapointed, it didn't work

I create another file to test the update line. This works and I copy and past it into update2.php:

<?php
if ( $_POST[vakkeuze]>A ) { $vakkeuze1=$_POST[vakkeuze];
echo &quot;$vakkeuze1<br>&quot;;
} else {
echo &quot;Voer de juiste vakafkorting in!!!<br>&quot;;
}
// MySQL data
$host = &quot;localhost&quot;;
$username = &quot;&quot;;
$password = &quot;&quot;;
$database = &quot;hrocijfers&quot;;

// Make connection to MySQL server
mysql_connect (&quot;$host&quot;,&quot;$username&quot;, &quot;$password&quot;);
mysql_select_db(&quot;$database&quot;);

//Execute query
$sql = &quot;SELECT * FROM 'cijferlijst' WHERE vak='$vakkeuze1'&quot;;
$result = mysql_query($sql);

// Checkout the entered vak
$num_rows = mysql_num_rows($result);
if ( $num_rows>0 ) {
echo &quot;password oke<br>&quot;;
}
else {
echo &quot;Voer de juiste vak afkorting in.<br>&quot;;
}

if ( $_POST[cijferinvoer]>0 ) { $cijferinvoer1=$_POST[cijferinvoer];
echo &quot;$cijferinvoer1<br>&quot;;
} else {
echo &quot;voer een cijfer in dat groter is dan nul<br>&quot;;
}

if ( $_POST[cijfer]>0 ) { $cijfer1=$_POST[cijfer];
echo &quot;$cijfer1<br>&quot;;
} else {
echo &quot;voer een cijfer in dat groter is dan nul<br>&quot;;
}
//Execute query
$query = 'UPDATE cijferlijst set cijfer1=9 where vak=\'Proj1\'';
$results = mysql_query($query);

echo &quot;Your availability is updated... <br><br>&quot;;
echo &quot;<a href=availability2.php>Click here to view the status of other members</a>&quot;;
?>


The update linew is correctly now

//Execute query
$query = 'UPDATE cijferlijst set cijfer1=9 where vak=\'Proj1\'';
$results = mysql_query($query);


-But how can I put the variables into the line?

$query = 'UPDATE cijferlijst set cijfer1='$cijferinvoer' where vak=\'Proj1\'';


this one didn't work...

-What can be wrong at the select line?

Thx
 
Ok, now I've this select line:


//Execute query
$sql = 'SELECT * FROM `cijferlijst` WHERE 1 AND `vak` = \'Proj1\' LIMIT 0, 30';
$result = mysql_query($sql);


Phpmyadmin advise me to use a variable in the line like this:

$sql = 'SELECT * FROM `cijferlijst` WHERE 1 AND `vak` = \'$vakkeuze1\' LIMIT 0, 30';

But the line is defect when I used it...

Anyone who knows more about this problem?
 
Try:

$sql = &quot;SELECT * FROM cijferlijst WHERE 1 AND vak = ' . $vakkeuze1 . ' LIMIT 0, 30';

______________________________________________________________________
TANSTAAFL!
 
It didn't worked ... I've tried 10 other variants, but use a variable in the update or select line still didn't worked ...

Anyone knows more about this problem?
 
if(!empty($vakkeuze)){

$sql = &quot;SELECT * FROM cijferlijst WHERE vak = '$vakkeuze1' LIMIT 0, 30';

}else{
echo &quot;vakkeuze1 is empty&quot;;
}

______________________________________________________________________
There's no present like the time, they say. - Henry's Cat.
 
This is the goodone:

//Execute query
$result = mysql_query(&quot;
SELECT * from cijferlijst
WHERE 1
AND vak = '&quot;. $vakkeuze1 . &quot;'
&quot;);

Thx 4 all
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top