Forum Moderators: coopster
Would this mean that when the person sends this to their address bar, a variable show_num would be created with the value of 1 automatically and I could just use $show_num anywhere on the php coding and it would equal one when they load the page that way? (Lol I ask alot but I really thank you guys for your help since I am a beginner :P)
Would this mean that when the person sends this to their address bar, a variable show_num would be created with the value of 1
Yes, but only if you have
register_globals turned On in your php.ini file (which is how many example scripts will do it, but it is a bad idea because they can be a security hole). instead you can access it through the $_GET pre-defined variable like this..
<?php
if ( isset($_GET['show_num']) ) {
print 'Show number = '.$_GET['show_num'];
}
?>
[pre]
if ( isset($_GET['show_num']) and ctype_digit($_GET['show_num']) )
$showid = $_GET['show_num'];
else
$showid = -1;
[/pre] I've added an extra little check in there to make sure that the show_num is a number. Otherwise naughty little users might break your code by entering and address like show.php?show_num=foobar.
Rule 1 of writing interactive php scripts: Always check that inputs from the users are what you expect them to be. Assume users hate you and that they will always look for a way to break your scripts :)
$sql = 'SELECT * FROM `Show_Data` WHERE 1 AND `show_num` = $show_num LIMIT 0, 30';
Is there a way to make the show_name for entry 1= $show_name? What i'm trying to do is select all the data (one entry) where show_num is equal to one number (is unique and incrementing). Then once its all selected make it into variables so I can display it on the page.
[pre]
$connection = mysql_connect(DB_SERVER, DB_USER, DB_PASSWORD )
or die( "Unable to connect to database: ".mysql_error() );
mysql_selectdb( DB_NAME )
or die( "Unable to select database: ".mysql_error() );
$sql = 'select name, description from show_data where show_num = '.$showid;
$result = mysql_query( $sql, $connection )
or die( "Invalid SQL: ".mysql_error() );
if ( $row = mysql_fetch_assoc($result) ) {
print '<h1>'.$row['name'].'</h1>';
print '<div id="showdesc">;
print $row['description'];
print '</div>';
}
else
print 'Show '.$showid.' not found.';
[/pre] Note that DB_SERVER, DB_USER, DB_PASSWORD and DB_DATABASE should be defined in another PHP file which is not under your document root, and then use the
include statement to read it in this script. That way if php fails for some reason, and the server starts dishing out your scripts in plain text, the users won't get to find out your password.
'select name, description, field3 from...
..lists what fields you want to select from the table.
And then once you have done the
$row = mysql_fetch_assoc then the contents of these fields are all available in the $row array... $row['name']
$row['description']
$row['field3']
...
okay?