Jump to content

Recommended Posts

hey guys, i am new to this forum so i apologize if this is not the correct section.

I am trying to display records from a table but when the records are displayed the first record is not being displayed and it starts from the second.

 

I should tell you that the records i try to display are data that are just inserted in the table so its kind of ("insert this" reload page "display this".

 

Its a bit urgent so i would really appreciate a fast response ,

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/128955-php-mysql-records-display-problem/
Share on other sites

This is the code for the insertion of the records:

 

session_start();
//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(host, usrnm);
if(!$link) {
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db('db');
if(!$db) {
	die("Unable to select database");
}




	$event = $_POST["event"];
	$bet = $_POST["bet"];
	$winnings = $_POST["winings"];	
	$member_id = $_SESSION['SESS_AGENT_ID'];
	$agent_id = $_SESSION['SESS_MEMBER_ID'];	
	$session_id = session_id();


//Check for duplicate login ID
if($event != '') 
{
	$qry = "SELECT * FROM `coupons` WHERE `event` = '$event' && `session_id` = '$session_id'";
	$result = @mysql_query($qry);
	if($result) 
	{
		if(mysql_num_rows($result) > 0) 
		{
			$errmsg_arr[] = 'You already placed this bet';
			$errflag = true;
			?>
			<script>
			alert('You already placed this bet');
			window.location = "game-show.php"
			</script>
			<?php

		}
		mysql_free_result($result);
	}
	else 
	{
		die("Query failed");
	}
}

	   	
//Create INSERT query
$qry = "INSERT INTO `coupons`(event, bet, winings, member_id, agent_id, session_id) VALUES('$event','$bet','$winnings','$member_id','$agent_id','$session_id')";
$result = mysql_query($qry);

if($result) 
{
?>
			<script>
			alert('Bet placed succesfully');
			window.location = "game-show.php"

			</script>
			<?php
	//header("location:game-show.php");
}
else 
{
	die("Query Failed");
}

This is the code i use to display the records:

//Array to store validation errors
$errmsg_arr = array();

//Validation error flag
$errflag = false;

//Connect to mysql server
$link = mysql_connect(host, usrnm);
if(!$link) 
{
	die('Failed to connect to server: ' . mysql_error());
}

//Select database
$db = mysql_select_db('db');
if(!$db) 
{
	die("Unable to select database");
}


echo "<td><input type='text' name='bets' value='1' onchange='window.reload(true)' /></td>";
$total =1;
$bets = $_POST['bets'];
$result = mysql_query("SELECT * FROM `coupons` WHERE `session_id` = '$session_id'");

if ($result >= 1)
{
	$row = mysql_fetch_array($result);

           while($row = mysql_fetch_array($result))
	{		 
	echo "<tr>
	<td>$row[event]</td>
	<td>$row[bet]</td>
	<td>$row[winings]</td>
	</tr>";
	$total *= $row[winings]; 
	}
	echo"<td></td><td><b>Total</b></td><td>$total</td></tr>";


}
else 
{
echo "Query Failed";
}
?>

 

Edit - [ code ] tags added. Please use them when posting code

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.