Jump to content

[SOLVED] One final plea..


fwapah

Recommended Posts

OK despite everyone's help, I have taken this from a two tables with a password login system to an email check and a simple form with one table. And it's STILL not working.

 

I'm fairly new to this kind of coding and my code is admittedly sloppy at times, so thanks for the help and extreme patience!!

 

Here's the gist:

Someone logs in with their email address and is taken to a page that shows two grants they need to review and any progress on it (scores.php). They click on "update" for the grant and it takes them to update.php. They update the grant and comments and then hit "submit' and it's supposed to update the info for each slot and take them to a page that says it was successful and where they can review.

 

What is really does is 1) not show the grant number (I'm having issues with passing on info, even with session save) and 2) not displaying that page at all. Here is my code, thanks in advance for your insight!

 

scores.php (working- email ("remail" passed thru post from login page):

<?php

session_start();

$remail=$_POST["remail"];

db connect info

$_SESSION['remail']='$remail';

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name") or die(mysql_error());

// Retrieve data from database
$sql="SELECT * FROM $tbl_name where remail='$remail'";
$result=mysql_query($sql);
?>
<table width="400" border="1" cellspacing="0" cellpadding="3">
<tr>
<td colspan="4"><strong>Grants for your review </strong> </td>
</tr>

<tr>
<td align="center"><strong>Grant #</strong></td>
<td align="center"><strong>Score</strong></td>
<td align="center"><strong>Comments</strong></td>
<td align="center"><strong>Update</strong></td>
</tr>
<?php
while($rows=mysql_fetch_assoc($result)){
?>
<tr>
<td><? echo $rows['gnum']; ?></td>
<td><? echo $rows['gscore']; ?></td>
<td><? echo $rows['gcomm']; ?></td>
<td align="center"><a href="update.php?gnum=<? echo $rows['gnum']; ?>&rid=<? echo $rows['rid']; ?>">update</a></td>
</tr>

<?php
}
?>
</table>
</td>
</tr>
</table>
<?php
mysql_close();
?>

 

 

update.php?g=x?rid=y (working)

<?php

db connect info

session_start();

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$gnum=$_GET['gnum'];
$rid=$_GET['rid'];


$_SESSION['gnum']='$gnum';
$_SESSION['rid']='$rid';

// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE rid='$rid' AND gnum='$gnum'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="800" border="0" cellspacing="1" cellpadding="0">
<form name="form1" method="post" action="update_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<strong>Grant #<? $_POST['gnum']; ?></strong> </td>
</tr>
<tr>
<td align="center" width="10%"> </td>
<td align="center" width="90%"> </td>
</tr>
<tr>

<td align="center" width="10%"><strong>Score</strong></td>
<td align="center" width="90%"><strong>Comments</strong></td>
</tr>
<tr>
<td align="center" width="10%"><input name="gscore" type="text" id="gscore" value="<? echo $rows['gscore']; ?>"></td>
<td align="center" width="90%"><input name="gcomm" type="text" id="gcomm" size="25" value="<? echo $rows['gcomm']; ?>"> </td>
</tr>
<tr>
<td> </td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection
mysql_close();

?>

 

 

update_ac.php, the troublemaker.. i got it to work once but then i added more variables I think and now it's dead:

<?php

session_start();

db connect info

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$gnum=$_POST['gnum'];
$rid=$_POST['rid'];

// update data in mysql database
$sql="UPDATE $tbl_name SET gscore='$gscore', gcomm='$gcomm' WHERE rid='$rid' AND gnum='$gnum'";
$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='scores.php?g=<? echo $rows['$gnum']; ?>&rid=<? echo $rows['$rid']; ?>'>View result</a>";
}

else {
echo "ERROR";
}

?>

 

 

 

Link to comment
Share on other sites

Problem one may lie in the fact that you are using <? as an opening tag instead of <?php. Some browsers parse <? as XML rather than PHP. Change that and it may fix your problem.

 

Problem two looks to me like it lies here:

 


In this page (the third page), these $_POST variables don't exist, as they have not been submitted through any form in the previous page. It looks like you have set them into session variables though, so they should be accessible if you change your code to:

[code]$gnum=$_SESSION['gnum'];
$rid=$_SESSION['rid'];

 

Finally, if you want to tighten your code up a bit, you don't even need to assign the session variables to $gnum and $rid, you can just use $_SESSION['gnum'] and $_SESSION['rid'] directly in your code.[/code]

Link to comment
Share on other sites

One of your main errors is most likely here:

 

<strong>Grant #<? $_POST['gnum']; ?></strong> </td>

 

You are only opening the PHP tag using the short method, you aren't actually printing the results.

Although short hand methods of programming aren't usually reccomended, it shouldn't make too much difference.

 

Methods:

<? echo $_POST['gnum']; ?> // Short hand opening statement

<?=$_POST['gnum'];?> // Short hand opening and echo'ing the results

<?php echo $_POST['gnum']; ?> // Long hand opening and echo'ing the results, reccomended

Link to comment
Share on other sites

Man, it's so embarrassing to miss the most basic things.. thanks to everyone who has helped me through this painful process. Definitely signing up for a php class before my next project.

 

Everything is working like a charm, except it's not writing to my database! I'm sure it's an error in my code, so please please please, a final look before i'm out of your hair for a while  :)

 

Here's my current update.php:

<?php
session_start();

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

// get value of id that sent from address bar
$gnum=$_GET['gnum'];

$_SESSION['rid']=$_GET['rid'];
$rid=$_SESSION['rid'];

// Retrieve data from database
$sql="SELECT * FROM $tbl_name WHERE rid='$rid' AND gnum='$gnum'";
$result=mysql_query($sql);

$rows=mysql_fetch_array($result);
?>
<table width="800" border="0" cellspacing="1" cellpadding="0">
<form name="form2" method="post" action="update_ac.php">
<table width="100%" border="0" cellspacing="1" cellpadding="0">
<tr>
<strong>Grant #<?php echo $gnum; ?></strong> </td>
</tr>
<tr>
<td align="center" width="10%"> </td>
<td align="center" width="90%"> </td>
</tr>
<tr>

<td align="center" width="10%"><strong>Score</strong></td>
<td align="center" width="90%"><strong>Comments</strong></td>
</tr>
<tr>
<td align="center" width="10%"><input name="gscore" type="text" id="gscore" value="<?php echo $rows['gscore']; ?>"></td>
<td align="center" width="90%"><input name="gcomm" type="text" id="gcomm" size="25" value="<?php echo $rows['gcomm']; ?>" </td>
</tr><td><input name="rid" type="hidden" id="rid" value="<?php echo $rid; ?>"></td><td><input name="gnum" type="hidden" id="gnum" value="<?php echo $gnum; ?>"></td>
<tr>
<td> </td>
<td align="center"><input type="submit" name="Submit" value="Submit"></td>
<td> </td>
</tr>
</table>
</td>
</form>
</tr>
</table>

<?

// close connection
mysql_close();

?>

 

and my update_ac.php:

<?php

session_start();

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

$gnum=$_POST['gnum'];
$rid=$_POST['rid'];
$_SESSION['rid']=$rid;

// update data in mysql database
$sql="UPDATE $tbl_name SET gscore='$gscore', gcomm='$gcomm' WHERE rid='$rid' AND gnum='$gnum'";
$result=mysql_query($sql);

// if successfully updated.
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='scores.php?rid=$rid'>Back to Score Review</a>";
}

else {
echo "ERROR";
}

?>

<a href="logout.php">Logout to End Session</a>

 

Yelp! I am repeating code a lot because some of the variables aren't carrying over when it goes back to previous sheets.

 

Thanks thank thanks for your help.

Link to comment
Share on other sites

Add this in the middle to view the query.

You may have errors suppressed in your php.ini, may want to check and enable E_ALL

 

$sql="UPDATE $tbl_name SET gscore='$gscore', gcomm='$gcomm' WHERE rid='$rid' AND gnum='$gnum'";

echo $sql;  //add this

$result=mysql_query($sql);

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.