Jump to content
xisto Community

alex1985

Members
  • Content Count

    398
  • Joined

  • Last visited

Posts posted by alex1985


  1. Help me out!!! I was trying to correct the mistake all the day, today. I can't still fix it. I'm using the tutorial in the textbook, like step-by-step guide how you make certain things. I'm putting the the experts from the textbook which makes the entire page. Probabli, there are some mistakes or I put them in the wrong order. So, I asking you to take a glance at it, and help me to create one. I will as well to make it tomorrow. Trying is one of the way of learning some certain aspects. Please, let me know as soon as possible. Thanks for you cooperation.

    There are experts:

    1)

    <?phpelse: // Allow the user to enter a new joke$authors = @mysql_query('SELECT id, name FROM author');if (!$authors) {exit('<p>Unable to obtain author list from the database.</p>');}$cats = @mysql_query('SELECT id, name FROM category');if (!$cats) {exit('<p>Unable to obtain category list from the ' .'database.</p>');}?>

    2)

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"><p>Enter the new joke:<br /><textarea name="joketext" rows="5" cols="45"></textarea></p>

    3)

    <p>Author:<select name="aid" size="1"><option selected value="">Select One</option><option value="">---------</option><?phpwhile ($author = mysql_fetch_array($authors)) {$aid = $author['id'];$aname = htmlspecialchars($author['name']);echo "<option value='$aid'>$aname</option>\n";}?></select></p>

    4)

    <p>Place in categories:<br /><?phpwhile ($cat = mysql_fetch_array($cats)) {$cid = $cat['id'];$cname = htmlspecialchars($cat['name']);echo "<label><input type='checkbox' name='cats[]' " ."value='$cid' />$cname</label><br />\n";}?></p>

    5)

    <input type="submit" value="SUBMIT" /></form><?php endif; ?>

    6)

    <?php$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');if (!$dbcnx) {exit('<p>Unable to connect to the ' .'database server at this time.</p>');}if (!@mysql_select_db('ijdb')) {exit('<p>Unable to locate the joke ' .'database at this time.</p>');}if (isset($_POST['joketext'])):// A new joke has been entered// using the form.$aid = $_POST['aid'];$joketext = $_POST['joketext'];if ($aid == '') {exit('<p>You must choose an author for this joke. Click ' .'"Back" and try again.</p>');}$sql = "INSERT INTO joke SETjoketext='$joketext',jokedate=CURDATE(),authorid='$aid'";if (@mysql_query($sql)) {echo '<p>New joke added</p>';} else {exit('<p>Error adding new joke: ' . mysql_error() . '</p>');}$jid = mysql_insert_id();

    7)

    if (isset($_POST['cats'])) {$cats = $_POST['cats'];} else {$cats = array();}

    8)

    $i = 0; // First indexwhile ($i < count($cats)) { // While we're not at the end// process $cats[$i]++$i; // Increment to the next index}

    9)

    $i = 0; // First indexwhile (isset($cats[$i])) { // While we're not at the end// process $cats[$i]++$i; // Increment to the next index}

    10)

    for ($i = 0; isset($cats[$i]); ++$i) {// process $cats[$i]}

    11)

    foreach ($cats as $catID) {// Process $catID}

    12)

    $numCats = 0;foreach ($cats as $catID) {$sql = "INSERT IGNORE INTO jokecategorySET jokeid=$jid, categoryid=$catID";$ok = @mysql_query($sql);if ($ok) {$numCats = $numCats + 1;} else {echo "<p>Error inserting joke into category $catID: " .mysql_error() . '</p>';}}?><p>Joke was added to <?php echo $numCats; ?> categories.</p><p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add anotherjoke</a></p><p><a href="jokes.php">Return to joke search</a></p>

    Finished. That the experts are given from the textbook. When I type all of it, it does not work on the server?! So, I think there is a mistake or I'm puttinng in the wrong way in the PHP file. Thanks.

  2. Hi, do you know what is the mistake in the following PHP code:

    It does give me the following message:

    Parse error: syntax error, unexpected $end in /home/alex1985/public_html/mulhim/library_project/test_dir/newjoke.php on line 68

    <?php$dbcnx = @mysql_connect('localhost', 'root', 'mypasswd');if (!$dbcnx) {exit('<p>Unable to connect to the ' .'database server at this time.</p>');}if (!@mysql_select_db('ijdb')) {exit('<p>Unable to locate the joke ' .'database at this time.</p>');}if (isset($_POST['joketext'])):// A new joke has been entered// using the form.$aid = $_POST['aid'];$joketext = $_POST['joketext'];if ($aid == '') {exit('<p>You must choose an author for this joke. Click ' .'"Back" and try again.</p>');}$sql = "INSERT INTO joke SETjoketext='$joketext',jokedate=CURDATE(),authorid='$aid'";if (@mysql_query($sql)) {echo '<p>New joke added</p>';} else {exit('<p>Error adding new joke: ' . mysql_error() . '</p>');}$jid = mysql_insert_id();if (isset($_POST['cats'])) {$cats = $_POST['cats'];} else {$cats = array();}$i = 0; // First indexwhile ($i < count($cats)) { // While we're not at the end// process $cats[$i]++$i; // Increment to the next index}$i = 0; // First indexwhile (isset($cats[$i])) { // While we're not at the end// process $cats[$i]++$i; // Increment to the next index}for ($i = 0; isset($cats[$i]); ++$i) {// process $cats[$i]}foreach ($cats as $catID) {// Process $catID}$numCats = 0;foreach ($cats as $catID) {$sql = "INSERT IGNORE INTO jokecategorySET jokeid=$jid, categoryid=$catID";$ok = @mysql_query($sql);if ($ok) {$numCats = $numCats + 1;} else {echo "<p>Error inserting joke into category $catID: " .mysql_error() . '</p>';}}?><p>Joke was added to <?php echo $numCats; ?> categories.</p><p><a href="<?php echo $_SERVER['PHP_SELF']; ?>">Add anotherjoke</a></p><p><a href="jokes.php">Return to joke search</a></p><?php


  3. I found one tutorial how to make a complete login system which suggest to use the following SQL syntax to encrypt the password:

    INSERT INTO login (username,password,email,activated) value ('admin',sha1(concat('yourpasswordhere','0dAfghRqSTgx')),'youremailhere','1');

    Is it appropriate or not?!

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | 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.