Jump to content


Photo

Retrieving Variable Problem - Script Posted


  • Please log in to reply
2 replies to this topic

#1 triphis

triphis
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 01 October 2003 - 10:13 PM

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
Xac Attack

#2 shivabharat

shivabharat
  • Members
  • PipPipPip
  • Advanced Member
  • 371 posts
  • LocationChennai, India

Posted 02 October 2003 - 05:28 AM

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();

Knowledge --- Reading Enriches Mind But Sharing Enhances It.[br][br]Note: Before you request help enusre that you have had a look at the tutorials @phpfreaks

#3 triphis

triphis
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 02 October 2003 - 09:56 PM

that worked! thank you :)
Xac Attack




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users