ajicles Posted June 24, 2010 Share Posted June 24, 2010 I have made a PHP Script that allows a user to enter data into a Database and the database recalls the information in a table. I have a problem with Notice: Undefined offset: 9 in E:\wamp\www\video.php on line 61 which calls the data from a row and column. <?php $ID = @$_GET['id'] ; $db_host = 'localhost'; $db_user = 'root'; $db_pwd = ''; $database = 'youtube'; $table = 'submitvid'; if (!mysql_connect($db_host, $db_user, $db_pwd)) die("Can't connect to database"); if (!mysql_select_db($database)) die("Can't select database"); $result = mysql_query("SELECT id,link FROM submitvid WHERE id = '$ID'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); ?> </center> <table width="755" height="477" border="1"> <tr> <td width="132">Link to file:</td> <td width="607"><?php echo $row[1]; ?></td> </tr> <tr> <td>Title of Video:</td> <td><?php echo $row[2]; ?></td> </tr> <tr> <td>Video Description:</td> <td><?php echo $row[3]; ?></td> </tr> <tr> <td>Video Tags:</td> <td><?php echo $row[4]; ?></td> </tr> <tr> <td>Match Type:</td> <td><?php echo $row[5]; ?></td> </tr> <tr> <td>Match Score:</td> <td><?php echo $row[6]; ?></td> </tr> <tr> <td>Match Map:</td> <td><?php echo $row[7]; ?></td> </tr> <tr> <td>Youtube Account:</td> <td><?php echo $row[8]; ?></td> </tr> <tr> <td>Email Address:</td> <td><?php echo $row[9]; ?></td> </tr> </table> </center> The row is clarified from the URL so in the case the error came up is at row 1. It will show the data from row 1 column 1 and column 2 but wont work with row 1 columns 3-9 for some reason? Could someone help me. Thanks ~ AJ [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/205777-notice-undefined-offset-9-in-ewampwwwvideophp-on-line-61/ Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 It would be much easier for you to use mysql_fetch_assoc. Then you can refer to the field names by name in the array. Ken Link to comment https://forums.phpfreaks.com/topic/205777-notice-undefined-offset-9-in-ewampwwwvideophp-on-line-61/#findComment-1076819 Share on other sites More sharing options...
ajicles Posted June 24, 2010 Author Share Posted June 24, 2010 It would be much easier for you to use mysql_fetch_assoc. Then you can refer to the field names by name in the array. Ken Thank you very much Link to comment https://forums.phpfreaks.com/topic/205777-notice-undefined-offset-9-in-ewampwwwvideophp-on-line-61/#findComment-1076821 Share on other sites More sharing options...
ajicles Posted June 24, 2010 Author Share Posted June 24, 2010 Ken could you help me fill out this code? <?php $conn = mysql_connect("localhost", "root", ""); if (!$conn) { echo "Unable to connect to DB: " . mysql_error(); exit; } if (!mysql_select_db("youtube")) { echo "Unable to select mydbname: " . mysql_error(); exit; } $sql = "SELECT id as userid, fullname, userstatus FROM sometable WHERE userstatus = 1"; $result = mysql_query($sql); if (!$result) { echo "Could not successfully run query ($sql) from DB: " . mysql_error(); exit; } if (mysql_num_rows($result) == 0) { echo "No rows found, nothing to print so am exiting"; exit; } // While a row of data exists, put that row in $row as an associative array // Note: If you're expecting just one row, no need to use a loop // Note: If you put extract($row); inside the following loop, you'll // then create $userid, $fullname, and $userstatus while ($row = mysql_fetch_assoc($result)) { echo $row["userid"]; echo $row["fullname"]; echo $row["userstatus"]; } mysql_free_result($result); ?> After selecting the database I get confused The three columns that I need to be read are: id link title_video Link to comment https://forums.phpfreaks.com/topic/205777-notice-undefined-offset-9-in-ewampwwwvideophp-on-line-61/#findComment-1076829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.