Jump to content

Retrieving Variable Problem - Script Posted


triphis

Recommended Posts

Okay, I have a MySQL table, used to keep track of items I have in a collection. When I add a new item to my collection, I go to the \"add.php\" page:

 

[php:1:3d60dc8dc8]<?php

$q=\"SELECT * FROM r99 WHERE have=0 ORDER BY name ASC\";

$result = mysql_query($q,$db);

 

while ($row = mysql_fetch_array($result)) {

$name = $row[\"name\"];

?>

 

<form action=\"form.php?name=<?=$name?>\" method=\"post\">

<table width=300 border=0>

<tr>

<td width=\"150\"><font face=\"verdana\" size=\"1\"><?=$name?></td>

<td><input type=\"text\" name=\"paid\" size=15></td>

<td>

<input type=\"submit\" name=\"submit\" value=\"Go!\">

</td>

</tr></table><br></form>

 

<?php

}

?>

[/php:1:3d60dc8dc8]

 

This is sent to the form.php page like this: form.php?name=$name

 

[php:1:3d60dc8dc8]<?php

 

$connection = mysql_connect(\"$hostname\" , \"$user\" , \"$pass\");

$db = mysql_select_db($dbase , $connection);

 

$q=\"UPDATE r99 SET have=\'1\' WHERE name=\'$name\'\";

$result= mysql_query($q, $connection) or die

(\"Could not execute query : $q.\" . mysql_error());

mysql_free_result()

 

$q=\"UPDATE r99 SET paid=\'$paid\' WHERE name=\'$name\'\";

$result= mysql_query($q, $connection) or die

(\"Could not execute query : $q.\" . mysql_error());

mysql_free_result()

 

?>[/php:1:3d60dc8dc8]

 

If you notice, the add php calls up items with HAVE=0 meaning I do not have it. Once it goes through the form page, it is set to 1 (so it won\'t appear on the add.php page again), and the price is added (which was formerly 0)

 

I get this error : Parse error: parse error in /data/members/free/tripod/uk/t/r/i/triphis/htdocs/form.php on line 17 --- which refers to [php:1:3d60dc8dc8]$q=\"UPDATE r99 SET paid=\'$paid\' WHERE name=\'$name\'\";[/php:1:3d60dc8dc8]

 

Where have I gone wrong? Thanx

Link to comment
https://forums.phpfreaks.com/topic/1092-retrieving-variable-problem-script-posted/
Share on other sites

Try this

 

 

<?php 



$connection = mysql_connect("$hostname" , "$user" , "$pass"); 



$db = mysql_select_db($dbase , $connection); 



$q="UPDATE r99 SET have=\'1\' WHERE name=\'$name\'"; 

$result= mysql_query($q, $connection) or die 

("Could not execute query : $q." . mysql_error()); 

mysql_free_result(); 



$q="UPDATE r99 SET paid=\'$paid\' WHERE name=\'$name\'"; 

$result= mysql_query($q, $connection) or die 

("Could not execute query : $q." . mysql_error()); 

mysql_free_result(); 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.